svelte-effect-runtime 1.3.2 → 1.4.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 (41) hide show
  1. package/dist/chunks/{client-DkW4e4dD.js → client-vV6UAwoP.js} +3 -3
  2. package/dist/chunks/client-vV6UAwoP.js.map +1 -0
  3. package/dist/chunks/{server-CQcF2W3T.js → server-7YVuxUNk.js} +53 -2
  4. package/dist/chunks/server-7YVuxUNk.js.map +1 -0
  5. package/dist/chunks/v3-D0c0MKPf.js +1 -0
  6. package/dist/chunks/v4-MMhHmzIG.js +1 -0
  7. package/dist/client.js +1 -1
  8. package/dist/internal/remote-client.js +3 -3
  9. package/dist/internal/remote-client.js.map +1 -1
  10. package/dist/internal/remote-shared.d.ts +134 -1
  11. package/dist/internal/remote-shared.js +64 -0
  12. package/dist/internal/remote-shared.js.map +1 -1
  13. package/dist/internal/transform.d.ts +7 -0
  14. package/dist/internal/transform.js +172 -15
  15. package/dist/internal/transform.js.map +1 -1
  16. package/dist/mod.d.ts +21 -0
  17. package/dist/mod.js +2 -2
  18. package/dist/preprocess.d.ts +5 -0
  19. package/dist/preprocess.js +6 -1
  20. package/dist/preprocess.js.map +1 -1
  21. package/dist/root-node.js +3 -3
  22. package/dist/server.d.ts +25 -0
  23. package/dist/server.js +26 -1
  24. package/dist/server.js.map +1 -1
  25. package/dist/v3/client.d.ts +24 -0
  26. package/dist/v3/mod.d.ts +24 -0
  27. package/dist/v3/server.d.ts +106 -0
  28. package/dist/v4/mod.d.ts +24 -0
  29. package/dist/v4/mod.js +2 -2
  30. package/dist/v4/preprocess.d.ts +4 -0
  31. package/dist/v4/preprocess.js +5 -1
  32. package/dist/v4/preprocess.js.map +1 -1
  33. package/dist/v4/root-node.js +2 -2
  34. package/dist/v4/server.d.ts +196 -0
  35. package/dist/v4/server.js +50 -1
  36. package/dist/v4/server.js.map +1 -1
  37. package/package.json +1 -1
  38. package/dist/chunks/client-DkW4e4dD.js.map +0 -1
  39. package/dist/chunks/server-CQcF2W3T.js.map +0 -1
  40. package/dist/chunks/v3-p8V3Drpp.js +0 -1
  41. package/dist/chunks/v4-DIhYCbb_.js +0 -1
@@ -1,53 +1,186 @@
1
+ /**
2
+ * Marker property name placed on serialized `RemoteFailure` envelopes so the
3
+ * client adapters can recognise server-produced failure payloads.
4
+ *
5
+ * @internal Internal - do not use.
6
+ */
1
7
  export declare const EFFECT_REMOTE_ERROR_MARKER = "__svelte_effect_remote__";
8
+ /**
9
+ * Well-known symbol used to attach a payload decoder to a remote function,
10
+ * enabling the client to reconstruct typed domain errors from wire data.
11
+ *
12
+ * @internal Internal - do not use.
13
+ */
2
14
  export declare const REMOTE_ERROR_DECODER: unique symbol;
15
+ /**
16
+ * A single validation problem surfaced by a remote form or schema check.
17
+ * Mirrors SvelteKit's `invalid()` issue shape.
18
+ */
3
19
  export interface FormIssue {
20
+ /** Human-readable description of the failure at {@link FormIssue.path}. */
4
21
  readonly message: string;
22
+ /** Field path (dot or array-index segments) the issue applies to. */
5
23
  readonly path: ReadonlyArray<string | number>;
6
24
  }
25
+ /**
26
+ * Typed error produced by `invalid.form(...)` / `invalid.<field>(...)` helpers
27
+ * inside a `Form` handler. Carries the collected `FormIssue`s to surface to
28
+ * the browser.
29
+ */
7
30
  export interface FormError<SchemaType = unknown> {
31
+ /** Discriminator identifying this as a form error. */
8
32
  readonly _tag: "FormError";
33
+ /** Issues produced by the handler, one per failed field. */
9
34
  readonly issues: ReadonlyArray<FormIssue>;
35
+ /**
36
+ * Phantom reference to the originating schema. Used purely for type
37
+ * inference of field helpers.
38
+ */
10
39
  readonly _schema?: SchemaType | undefined;
11
40
  }
41
+ /**
42
+ * Legacy wrapper around a typed server-side domain error value.
43
+ *
44
+ * @deprecated Tagged remote domain errors are no longer wrapped in
45
+ * `RemoteDomainError`. The user's own tagged error is now placed directly on
46
+ * the Effect error channel so `Effect.catchTag("YourTag", ...)` works without
47
+ * unwrapping. This interface is kept only for backwards compatibility with
48
+ * code that pattern-matched on `_tag === "RemoteDomainError"`.
49
+ */
12
50
  export interface RemoteDomainError<ErrorType = unknown> {
51
+ /** Discriminator identifying this variant of `RemoteFailure`. */
13
52
  readonly _tag: "RemoteDomainError";
53
+ /** The original typed error value produced on the server. */
14
54
  readonly cause: ErrorType;
55
+ /** HTTP status code associated with the failure. */
15
56
  readonly status: number;
16
57
  }
58
+ /**
59
+ * Remote failure emitted when request validation (schema or form) rejects the
60
+ * payload. Defaults to HTTP `400`, but callers may override the status code
61
+ * when constructing the value.
62
+ */
17
63
  export interface RemoteValidationError {
64
+ /** Discriminator identifying this variant of `RemoteFailure`. */
18
65
  readonly _tag: "RemoteValidationError";
66
+ /** Raw response body returned alongside the failure, when available. */
19
67
  readonly body?: unknown;
68
+ /** Validation issues, keyed by field path. */
20
69
  readonly issues: ReadonlyArray<FormIssue>;
70
+ /** HTTP status code for the validation failure, defaulting to `400`. */
21
71
  readonly status: number;
22
72
  }
73
+ /**
74
+ * Remote failure for HTTP-level errors returned by the server that do not map
75
+ * onto a typed domain error or validation failure.
76
+ */
23
77
  export interface RemoteHttpError {
78
+ /** Discriminator identifying this variant of `RemoteFailure`. */
24
79
  readonly _tag: "RemoteHttpError";
80
+ /** Parsed response body, if any. */
25
81
  readonly body?: unknown;
82
+ /** Original thrown value captured while handling the response. */
26
83
  readonly cause: unknown;
84
+ /** HTTP status code reported by the response. */
27
85
  readonly status: number;
28
86
  }
87
+ /**
88
+ * Remote failure for transport-level breakages (network errors, decoding
89
+ * failures). Does not carry an HTTP status.
90
+ */
29
91
  export interface RemoteTransportError {
92
+ /** Discriminator identifying this variant of `RemoteFailure`. */
30
93
  readonly _tag: "RemoteTransportError";
94
+ /** Raw body captured when the transport failure was detected, if any. */
31
95
  readonly body?: unknown;
96
+ /** Underlying error value - usually a `TypeError` or `DOMException`. */
32
97
  readonly cause: unknown;
33
98
  }
34
- export type RemoteFailure<ErrorType = unknown> = RemoteDomainError<ErrorType> | RemoteValidationError | RemoteHttpError | RemoteTransportError;
99
+ /**
100
+ * Error channel produced by every remote Effect wrapper. A server-side
101
+ * `Effect.fail(MyTaggedError)` surfaces on the client as the raw `ErrorType`,
102
+ * so `Effect.catchTag("MyTag", ...)` narrows directly to your error. The
103
+ * framework-level failure variants (`RemoteValidationError`,
104
+ * `RemoteHttpError`, `RemoteTransportError`) are still included for transport
105
+ * and HTTP failures that the caller didn't model explicitly.
106
+ */
107
+ export type RemoteFailure<ErrorType = unknown> = ErrorType | RemoteValidationError | RemoteHttpError | RemoteTransportError;
108
+ /**
109
+ * Wire shape of a serialised remote failure envelope that the server embeds
110
+ * in its response body.
111
+ *
112
+ * @internal Internal - do not use.
113
+ */
35
114
  export interface SerializedRemoteFailureEnvelope {
115
+ /** Marker flag; always `true`. */
36
116
  readonly [EFFECT_REMOTE_ERROR_MARKER]: true;
117
+ /** `devalue.stringify`-encoded payload for the failure value. */
37
118
  readonly encoded: string;
38
119
  }
120
+ /**
121
+ * Construct a {@link FormError} from one or more {@link FormIssue}s.
122
+ *
123
+ * @internal Internal - do not use.
124
+ */
39
125
  export declare function create_form_error<SchemaType = unknown>(...issues: Array<FormIssue>): FormError<SchemaType>;
126
+ /**
127
+ * Build a {@link RemoteDomainError} around a typed server-side error value.
128
+ *
129
+ * @deprecated Remote tagged failures are no longer wrapped - the user's
130
+ * tagged error is forwarded directly on the Effect error channel. This helper
131
+ * is retained for backwards compatibility with downstream code that still
132
+ * constructs `RemoteDomainError` values explicitly.
133
+ *
134
+ * @internal Internal - do not use.
135
+ */
40
136
  export declare function create_remote_domain_error<ErrorType = unknown>(cause: ErrorType, status: number): RemoteDomainError<ErrorType>;
137
+ /**
138
+ * Build a {@link RemoteValidationError} from a list of issues.
139
+ *
140
+ * @internal Internal - do not use.
141
+ */
41
142
  export declare function create_remote_validation_error(issues: ReadonlyArray<FormIssue>, options?: {
42
143
  body?: unknown;
43
144
  status?: number;
44
145
  }): RemoteValidationError;
146
+ /**
147
+ * Build a {@link RemoteHttpError} from an arbitrary thrown value.
148
+ *
149
+ * @internal Internal - do not use.
150
+ */
45
151
  export declare function create_remote_http_error(cause: unknown, options?: {
46
152
  body?: unknown;
47
153
  status?: number;
48
154
  }): RemoteHttpError;
155
+ /**
156
+ * Build a {@link RemoteTransportError} from an arbitrary thrown value.
157
+ *
158
+ * @internal Internal - do not use.
159
+ */
49
160
  export declare function create_remote_transport_error(cause: unknown, body?: unknown): RemoteTransportError;
161
+ /**
162
+ * Wrap a pre-encoded failure payload in the marker envelope the client
163
+ * adapters look for when decoding responses.
164
+ *
165
+ * @internal Internal - do not use.
166
+ */
50
167
  export declare function create_serialized_remote_failure_envelope(encoded: string): SerializedRemoteFailureEnvelope;
168
+ /**
169
+ * Type guard for {@link FormError} values.
170
+ *
171
+ * @internal Internal - do not use.
172
+ */
51
173
  export declare function is_form_error(value: unknown): value is FormError;
174
+ /**
175
+ * Type guard recognising the marker envelope wrapping an encoded remote
176
+ * failure payload.
177
+ *
178
+ * @internal Internal - do not use.
179
+ */
52
180
  export declare function is_serialized_remote_failure_envelope(value: unknown): value is SerializedRemoteFailureEnvelope;
181
+ /**
182
+ * Type guard for individual {@link FormIssue} values.
183
+ *
184
+ * @internal Internal - do not use.
185
+ */
53
186
  export declare function is_remote_validation_issue(value: unknown): value is FormIssue;
@@ -1,12 +1,39 @@
1
1
  //#region internal/remote-shared.ts
2
+ /**
3
+ * Marker property name placed on serialized `RemoteFailure` envelopes so the
4
+ * client adapters can recognise server-produced failure payloads.
5
+ *
6
+ * @internal Internal - do not use.
7
+ */
2
8
  const EFFECT_REMOTE_ERROR_MARKER = "__svelte_effect_remote__";
9
+ /**
10
+ * Well-known symbol used to attach a payload decoder to a remote function,
11
+ * enabling the client to reconstruct typed domain errors from wire data.
12
+ *
13
+ * @internal Internal - do not use.
14
+ */
3
15
  const REMOTE_ERROR_DECODER = Symbol.for("svelte-effect-runtime/remote-error-decoder");
16
+ /**
17
+ * Construct a {@link FormError} from one or more {@link FormIssue}s.
18
+ *
19
+ * @internal Internal - do not use.
20
+ */
4
21
  function create_form_error(...issues) {
5
22
  return {
6
23
  _tag: "FormError",
7
24
  issues
8
25
  };
9
26
  }
27
+ /**
28
+ * Build a {@link RemoteDomainError} around a typed server-side error value.
29
+ *
30
+ * @deprecated Remote tagged failures are no longer wrapped - the user's
31
+ * tagged error is forwarded directly on the Effect error channel. This helper
32
+ * is retained for backwards compatibility with downstream code that still
33
+ * constructs `RemoteDomainError` values explicitly.
34
+ *
35
+ * @internal Internal - do not use.
36
+ */
10
37
  function create_remote_domain_error(cause, status) {
11
38
  return {
12
39
  _tag: "RemoteDomainError",
@@ -14,6 +41,11 @@ function create_remote_domain_error(cause, status) {
14
41
  status
15
42
  };
16
43
  }
44
+ /**
45
+ * Build a {@link RemoteValidationError} from a list of issues.
46
+ *
47
+ * @internal Internal - do not use.
48
+ */
17
49
  function create_remote_validation_error(issues, options = {}) {
18
50
  return {
19
51
  _tag: "RemoteValidationError",
@@ -22,6 +54,11 @@ function create_remote_validation_error(issues, options = {}) {
22
54
  status: options.status ?? 400
23
55
  };
24
56
  }
57
+ /**
58
+ * Build a {@link RemoteHttpError} from an arbitrary thrown value.
59
+ *
60
+ * @internal Internal - do not use.
61
+ */
25
62
  function create_remote_http_error(cause, options = {}) {
26
63
  return {
27
64
  _tag: "RemoteHttpError",
@@ -30,6 +67,11 @@ function create_remote_http_error(cause, options = {}) {
30
67
  status: options.status ?? 500
31
68
  };
32
69
  }
70
+ /**
71
+ * Build a {@link RemoteTransportError} from an arbitrary thrown value.
72
+ *
73
+ * @internal Internal - do not use.
74
+ */
33
75
  function create_remote_transport_error(cause, body) {
34
76
  return {
35
77
  _tag: "RemoteTransportError",
@@ -37,18 +79,40 @@ function create_remote_transport_error(cause, body) {
37
79
  cause
38
80
  };
39
81
  }
82
+ /**
83
+ * Wrap a pre-encoded failure payload in the marker envelope the client
84
+ * adapters look for when decoding responses.
85
+ *
86
+ * @internal Internal - do not use.
87
+ */
40
88
  function create_serialized_remote_failure_envelope(encoded) {
41
89
  return {
42
90
  [EFFECT_REMOTE_ERROR_MARKER]: true,
43
91
  encoded
44
92
  };
45
93
  }
94
+ /**
95
+ * Type guard for {@link FormError} values.
96
+ *
97
+ * @internal Internal - do not use.
98
+ */
46
99
  function is_form_error(value) {
47
100
  return Boolean(value && typeof value === "object" && value._tag === "FormError" && Array.isArray(value.issues));
48
101
  }
102
+ /**
103
+ * Type guard recognising the marker envelope wrapping an encoded remote
104
+ * failure payload.
105
+ *
106
+ * @internal Internal - do not use.
107
+ */
49
108
  function is_serialized_remote_failure_envelope(value) {
50
109
  return Boolean(value && typeof value === "object" && "__svelte_effect_remote__" in value && value["__svelte_effect_remote__"] === true && typeof value.encoded === "string");
51
110
  }
111
+ /**
112
+ * Type guard for individual {@link FormIssue} values.
113
+ *
114
+ * @internal Internal - do not use.
115
+ */
52
116
  function is_remote_validation_issue(value) {
53
117
  return Boolean(value && typeof value === "object" && typeof value.message === "string" && Array.isArray(value.path));
54
118
  }
@@ -1 +1 @@
1
- {"version":3,"file":"remote-shared.js","names":[],"sources":["../../../modules/svelte-effect-runtime/internal/remote-shared.ts"],"sourcesContent":["export const EFFECT_REMOTE_ERROR_MARKER = \"__svelte_effect_remote__\";\nexport const REMOTE_ERROR_DECODER = Symbol.for(\n \"svelte-effect-runtime/remote-error-decoder\",\n);\n\nexport interface FormIssue {\n readonly message: string;\n readonly path: ReadonlyArray<string | number>;\n}\n\nexport interface FormError<SchemaType = unknown> {\n readonly _tag: \"FormError\";\n readonly issues: ReadonlyArray<FormIssue>;\n readonly _schema?: SchemaType | undefined;\n}\n\nexport interface RemoteDomainError<ErrorType = unknown> {\n readonly _tag: \"RemoteDomainError\";\n readonly cause: ErrorType;\n readonly status: number;\n}\n\nexport interface RemoteValidationError {\n readonly _tag: \"RemoteValidationError\";\n readonly body?: unknown;\n readonly issues: ReadonlyArray<FormIssue>;\n readonly status: number;\n}\n\nexport interface RemoteHttpError {\n readonly _tag: \"RemoteHttpError\";\n readonly body?: unknown;\n readonly cause: unknown;\n readonly status: number;\n}\n\nexport interface RemoteTransportError {\n readonly _tag: \"RemoteTransportError\";\n readonly body?: unknown;\n readonly cause: unknown;\n}\n\nexport type RemoteFailure<ErrorType = unknown> =\n | RemoteDomainError<ErrorType>\n | RemoteValidationError\n | RemoteHttpError\n | RemoteTransportError;\n\nexport interface SerializedRemoteFailureEnvelope {\n readonly [EFFECT_REMOTE_ERROR_MARKER]: true;\n readonly encoded: string;\n}\n\nexport function create_form_error<SchemaType = unknown>(\n ...issues: Array<FormIssue>\n): FormError<SchemaType> {\n return {\n _tag: \"FormError\",\n issues,\n };\n}\n\nexport function create_remote_domain_error<ErrorType = unknown>(\n cause: ErrorType,\n status: number,\n): RemoteDomainError<ErrorType> {\n return {\n _tag: \"RemoteDomainError\",\n cause,\n status,\n };\n}\n\nexport function create_remote_validation_error(\n issues: ReadonlyArray<FormIssue>,\n options: {\n body?: unknown;\n status?: number;\n } = {},\n): RemoteValidationError {\n return {\n _tag: \"RemoteValidationError\",\n body: options.body,\n issues,\n status: options.status ?? 400,\n };\n}\n\nexport function create_remote_http_error(\n cause: unknown,\n options: {\n body?: unknown;\n status?: number;\n } = {},\n): RemoteHttpError {\n return {\n _tag: \"RemoteHttpError\",\n body: options.body,\n cause,\n status: options.status ?? 500,\n };\n}\n\nexport function create_remote_transport_error(\n cause: unknown,\n body?: unknown,\n): RemoteTransportError {\n return {\n _tag: \"RemoteTransportError\",\n body,\n cause,\n };\n}\n\nexport function create_serialized_remote_failure_envelope(\n encoded: string,\n): SerializedRemoteFailureEnvelope {\n return {\n [EFFECT_REMOTE_ERROR_MARKER]: true,\n encoded,\n };\n}\n\nexport function is_form_error(value: unknown): value is FormError {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n (value as { _tag?: unknown })._tag === \"FormError\" &&\n Array.isArray((value as { issues?: unknown }).issues),\n );\n}\n\nexport function is_serialized_remote_failure_envelope(\n value: unknown,\n): value is SerializedRemoteFailureEnvelope {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n EFFECT_REMOTE_ERROR_MARKER in value &&\n (value as Record<string, unknown>)[EFFECT_REMOTE_ERROR_MARKER] === true &&\n typeof (value as { encoded?: unknown }).encoded === \"string\",\n );\n}\n\nexport function is_remote_validation_issue(\n value: unknown,\n): value is FormIssue {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { message?: unknown }).message === \"string\" &&\n Array.isArray((value as { path?: unknown }).path),\n );\n}\n"],"mappings":";AAAA,MAAa,6BAA6B;AAC1C,MAAa,uBAAuB,OAAO,IACzC,6CACD;AAkDD,SAAgB,kBACd,GAAG,QACoB;AACvB,QAAO;EACL,MAAM;EACN;EACD;;AAGH,SAAgB,2BACd,OACA,QAC8B;AAC9B,QAAO;EACL,MAAM;EACN;EACA;EACD;;AAGH,SAAgB,+BACd,QACA,UAGI,EAAE,EACiB;AACvB,QAAO;EACL,MAAM;EACN,MAAM,QAAQ;EACd;EACA,QAAQ,QAAQ,UAAU;EAC3B;;AAGH,SAAgB,yBACd,OACA,UAGI,EAAE,EACW;AACjB,QAAO;EACL,MAAM;EACN,MAAM,QAAQ;EACd;EACA,QAAQ,QAAQ,UAAU;EAC3B;;AAGH,SAAgB,8BACd,OACA,MACsB;AACtB,QAAO;EACL,MAAM;EACN;EACA;EACD;;AAGH,SAAgB,0CACd,SACiC;AACjC,QAAO;GACJ,6BAA6B;EAC9B;EACD;;AAGH,SAAgB,cAAc,OAAoC;AAChE,QAAO,QACL,SACE,OAAO,UAAU,YAChB,MAA6B,SAAS,eACvC,MAAM,QAAS,MAA+B,OAAO,CACxD;;AAGH,SAAgB,sCACd,OAC0C;AAC1C,QAAO,QACL,SACE,OAAO,UAAU,YAAA,8BACa,SAC7B,MAAA,gCAAkE,QACnE,OAAQ,MAAgC,YAAY,SACvD;;AAGH,SAAgB,2BACd,OACoB;AACpB,QAAO,QACL,SACE,OAAO,UAAU,YACjB,OAAQ,MAAgC,YAAY,YACpD,MAAM,QAAS,MAA6B,KAAK,CACpD"}
1
+ {"version":3,"file":"remote-shared.js","names":[],"sources":["../../../modules/svelte-effect-runtime/internal/remote-shared.ts"],"sourcesContent":["/**\n * Marker property name placed on serialized `RemoteFailure` envelopes so the\n * client adapters can recognise server-produced failure payloads.\n *\n * @internal Internal - do not use.\n */\nexport const EFFECT_REMOTE_ERROR_MARKER = \"__svelte_effect_remote__\";\n/**\n * Well-known symbol used to attach a payload decoder to a remote function,\n * enabling the client to reconstruct typed domain errors from wire data.\n *\n * @internal Internal - do not use.\n */\nexport const REMOTE_ERROR_DECODER = Symbol.for(\n \"svelte-effect-runtime/remote-error-decoder\",\n);\n\n/**\n * A single validation problem surfaced by a remote form or schema check.\n * Mirrors SvelteKit's `invalid()` issue shape.\n */\nexport interface FormIssue {\n /** Human-readable description of the failure at {@link FormIssue.path}. */\n readonly message: string;\n /** Field path (dot or array-index segments) the issue applies to. */\n readonly path: ReadonlyArray<string | number>;\n}\n\n/**\n * Typed error produced by `invalid.form(...)` / `invalid.<field>(...)` helpers\n * inside a `Form` handler. Carries the collected `FormIssue`s to surface to\n * the browser.\n */\nexport interface FormError<SchemaType = unknown> {\n /** Discriminator identifying this as a form error. */\n readonly _tag: \"FormError\";\n /** Issues produced by the handler, one per failed field. */\n readonly issues: ReadonlyArray<FormIssue>;\n /**\n * Phantom reference to the originating schema. Used purely for type\n * inference of field helpers.\n */\n readonly _schema?: SchemaType | undefined;\n}\n\n/**\n * Legacy wrapper around a typed server-side domain error value.\n *\n * @deprecated Tagged remote domain errors are no longer wrapped in\n * `RemoteDomainError`. The user's own tagged error is now placed directly on\n * the Effect error channel so `Effect.catchTag(\"YourTag\", ...)` works without\n * unwrapping. This interface is kept only for backwards compatibility with\n * code that pattern-matched on `_tag === \"RemoteDomainError\"`.\n */\nexport interface RemoteDomainError<ErrorType = unknown> {\n /** Discriminator identifying this variant of `RemoteFailure`. */\n readonly _tag: \"RemoteDomainError\";\n /** The original typed error value produced on the server. */\n readonly cause: ErrorType;\n /** HTTP status code associated with the failure. */\n readonly status: number;\n}\n\n/**\n * Remote failure emitted when request validation (schema or form) rejects the\n * payload. Defaults to HTTP `400`, but callers may override the status code\n * when constructing the value.\n */\nexport interface RemoteValidationError {\n /** Discriminator identifying this variant of `RemoteFailure`. */\n readonly _tag: \"RemoteValidationError\";\n /** Raw response body returned alongside the failure, when available. */\n readonly body?: unknown;\n /** Validation issues, keyed by field path. */\n readonly issues: ReadonlyArray<FormIssue>;\n /** HTTP status code for the validation failure, defaulting to `400`. */\n readonly status: number;\n}\n\n/**\n * Remote failure for HTTP-level errors returned by the server that do not map\n * onto a typed domain error or validation failure.\n */\nexport interface RemoteHttpError {\n /** Discriminator identifying this variant of `RemoteFailure`. */\n readonly _tag: \"RemoteHttpError\";\n /** Parsed response body, if any. */\n readonly body?: unknown;\n /** Original thrown value captured while handling the response. */\n readonly cause: unknown;\n /** HTTP status code reported by the response. */\n readonly status: number;\n}\n\n/**\n * Remote failure for transport-level breakages (network errors, decoding\n * failures). Does not carry an HTTP status.\n */\nexport interface RemoteTransportError {\n /** Discriminator identifying this variant of `RemoteFailure`. */\n readonly _tag: \"RemoteTransportError\";\n /** Raw body captured when the transport failure was detected, if any. */\n readonly body?: unknown;\n /** Underlying error value - usually a `TypeError` or `DOMException`. */\n readonly cause: unknown;\n}\n\n/**\n * Error channel produced by every remote Effect wrapper. A server-side\n * `Effect.fail(MyTaggedError)` surfaces on the client as the raw `ErrorType`,\n * so `Effect.catchTag(\"MyTag\", ...)` narrows directly to your error. The\n * framework-level failure variants (`RemoteValidationError`,\n * `RemoteHttpError`, `RemoteTransportError`) are still included for transport\n * and HTTP failures that the caller didn't model explicitly.\n */\nexport type RemoteFailure<ErrorType = unknown> =\n | ErrorType\n | RemoteValidationError\n | RemoteHttpError\n | RemoteTransportError;\n\n/**\n * Wire shape of a serialised remote failure envelope that the server embeds\n * in its response body.\n *\n * @internal Internal - do not use.\n */\nexport interface SerializedRemoteFailureEnvelope {\n /** Marker flag; always `true`. */\n readonly [EFFECT_REMOTE_ERROR_MARKER]: true;\n /** `devalue.stringify`-encoded payload for the failure value. */\n readonly encoded: string;\n}\n\n/**\n * Construct a {@link FormError} from one or more {@link FormIssue}s.\n *\n * @internal Internal - do not use.\n */\nexport function create_form_error<SchemaType = unknown>(\n ...issues: Array<FormIssue>\n): FormError<SchemaType> {\n return {\n _tag: \"FormError\",\n issues,\n };\n}\n\n/**\n * Build a {@link RemoteDomainError} around a typed server-side error value.\n *\n * @deprecated Remote tagged failures are no longer wrapped - the user's\n * tagged error is forwarded directly on the Effect error channel. This helper\n * is retained for backwards compatibility with downstream code that still\n * constructs `RemoteDomainError` values explicitly.\n *\n * @internal Internal - do not use.\n */\nexport function create_remote_domain_error<ErrorType = unknown>(\n cause: ErrorType,\n status: number,\n): RemoteDomainError<ErrorType> {\n return {\n _tag: \"RemoteDomainError\",\n cause,\n status,\n };\n}\n\n/**\n * Build a {@link RemoteValidationError} from a list of issues.\n *\n * @internal Internal - do not use.\n */\nexport function create_remote_validation_error(\n issues: ReadonlyArray<FormIssue>,\n options: {\n body?: unknown;\n status?: number;\n } = {},\n): RemoteValidationError {\n return {\n _tag: \"RemoteValidationError\",\n body: options.body,\n issues,\n status: options.status ?? 400,\n };\n}\n\n/**\n * Build a {@link RemoteHttpError} from an arbitrary thrown value.\n *\n * @internal Internal - do not use.\n */\nexport function create_remote_http_error(\n cause: unknown,\n options: {\n body?: unknown;\n status?: number;\n } = {},\n): RemoteHttpError {\n return {\n _tag: \"RemoteHttpError\",\n body: options.body,\n cause,\n status: options.status ?? 500,\n };\n}\n\n/**\n * Build a {@link RemoteTransportError} from an arbitrary thrown value.\n *\n * @internal Internal - do not use.\n */\nexport function create_remote_transport_error(\n cause: unknown,\n body?: unknown,\n): RemoteTransportError {\n return {\n _tag: \"RemoteTransportError\",\n body,\n cause,\n };\n}\n\n/**\n * Wrap a pre-encoded failure payload in the marker envelope the client\n * adapters look for when decoding responses.\n *\n * @internal Internal - do not use.\n */\nexport function create_serialized_remote_failure_envelope(\n encoded: string,\n): SerializedRemoteFailureEnvelope {\n return {\n [EFFECT_REMOTE_ERROR_MARKER]: true,\n encoded,\n };\n}\n\n/**\n * Type guard for {@link FormError} values.\n *\n * @internal Internal - do not use.\n */\nexport function is_form_error(value: unknown): value is FormError {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n (value as { _tag?: unknown })._tag === \"FormError\" &&\n Array.isArray((value as { issues?: unknown }).issues),\n );\n}\n\n/**\n * Type guard recognising the marker envelope wrapping an encoded remote\n * failure payload.\n *\n * @internal Internal - do not use.\n */\nexport function is_serialized_remote_failure_envelope(\n value: unknown,\n): value is SerializedRemoteFailureEnvelope {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n EFFECT_REMOTE_ERROR_MARKER in value &&\n (value as Record<string, unknown>)[EFFECT_REMOTE_ERROR_MARKER] === true &&\n typeof (value as { encoded?: unknown }).encoded === \"string\",\n );\n}\n\n/**\n * Type guard for individual {@link FormIssue} values.\n *\n * @internal Internal - do not use.\n */\nexport function is_remote_validation_issue(\n value: unknown,\n): value is FormIssue {\n return Boolean(\n value &&\n typeof value === \"object\" &&\n typeof (value as { message?: unknown }).message === \"string\" &&\n Array.isArray((value as { path?: unknown }).path),\n );\n}\n"],"mappings":";;;;;;;AAMA,MAAa,6BAA6B;;;;;;;AAO1C,MAAa,uBAAuB,OAAO,IACzC,6CACD;;;;;;AA4HD,SAAgB,kBACd,GAAG,QACoB;AACvB,QAAO;EACL,MAAM;EACN;EACD;;;;;;;;;;;;AAaH,SAAgB,2BACd,OACA,QAC8B;AAC9B,QAAO;EACL,MAAM;EACN;EACA;EACD;;;;;;;AAQH,SAAgB,+BACd,QACA,UAGI,EAAE,EACiB;AACvB,QAAO;EACL,MAAM;EACN,MAAM,QAAQ;EACd;EACA,QAAQ,QAAQ,UAAU;EAC3B;;;;;;;AAQH,SAAgB,yBACd,OACA,UAGI,EAAE,EACW;AACjB,QAAO;EACL,MAAM;EACN,MAAM,QAAQ;EACd;EACA,QAAQ,QAAQ,UAAU;EAC3B;;;;;;;AAQH,SAAgB,8BACd,OACA,MACsB;AACtB,QAAO;EACL,MAAM;EACN;EACA;EACD;;;;;;;;AASH,SAAgB,0CACd,SACiC;AACjC,QAAO;GACJ,6BAA6B;EAC9B;EACD;;;;;;;AAQH,SAAgB,cAAc,OAAoC;AAChE,QAAO,QACL,SACE,OAAO,UAAU,YAChB,MAA6B,SAAS,eACvC,MAAM,QAAS,MAA+B,OAAO,CACxD;;;;;;;;AASH,SAAgB,sCACd,OAC0C;AAC1C,QAAO,QACL,SACE,OAAO,UAAU,YAAA,8BACa,SAC7B,MAAA,gCAAkE,QACnE,OAAQ,MAAgC,YAAY,SACvD;;;;;;;AAQH,SAAgB,2BACd,OACoB;AACpB,QAAO,QACL,SACE,OAAO,UAAU,YACjB,OAAQ,MAAgC,YAAY,YACpD,MAAM,QAAS,MAA6B,KAAK,CACpD"}
@@ -6,6 +6,13 @@ interface TransformEffectScriptOptions extends EffectPreprocessOptions {
6
6
  interface TransformEffectScriptResult {
7
7
  code: string;
8
8
  map: SourceMap;
9
+ relocations: Array<TransformRelocation>;
10
+ }
11
+ interface TransformRelocation {
12
+ originalStart: number;
13
+ originalEnd: number;
14
+ generatedStart: number;
15
+ generatedEnd: number;
9
16
  }
10
17
  export declare function transformEffectScript(content: string, options: TransformEffectScriptOptions): TransformEffectScriptResult;
11
18
  export {};
@@ -35,6 +35,7 @@ function transformEffectScript(content, options) {
35
35
  const sourceFile = ts.createSourceFile(options.filename, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
36
36
  const effectStatements = [];
37
37
  const runtimeStatements = [];
38
+ const pendingRelocations = [];
38
39
  const magicString = new MagicString(content);
39
40
  const effectBoundBindings = /* @__PURE__ */ new Set();
40
41
  for (const statement of sourceFile.statements) {
@@ -44,6 +45,7 @@ function transformEffectScript(content, options) {
44
45
  if (transformed.hoistedText.length === 0) magicString.remove(statement.getFullStart(), statement.end);
45
46
  else magicString.overwrite(statement.getStart(sourceFile), statement.end, transformed.hoistedText);
46
47
  runtimeStatements.push(...transformed.effectTexts);
48
+ pendingRelocations.push(...transformed.pendingRelocations);
47
49
  for (const bindingName of transformed.loweredBindings) effectBoundBindings.add(bindingName);
48
50
  continue;
49
51
  }
@@ -54,6 +56,13 @@ function transformEffectScript(content, options) {
54
56
  node: statement,
55
57
  text: normalizeStatementText(sliceNode(content, statement))
56
58
  });
59
+ pendingRelocations.push({
60
+ originalStart: statement.getStart(sourceFile),
61
+ originalEnd: statement.end,
62
+ generatedSnippet: normalizeStatementText(sliceNode(content, statement)),
63
+ generatedInnerStart: 0,
64
+ generatedInnerEnd: normalizeStatementText(sliceNode(content, statement)).length
65
+ });
57
66
  }
58
67
  for (const statement of [...effectStatements].reverse()) magicString.remove(statement.node.getFullStart(), statement.node.end);
59
68
  const allRuntimeStatements = [...runtimeStatements, ...effectStatements.map((statement) => statement.text)];
@@ -61,13 +70,15 @@ function transformEffectScript(content, options) {
61
70
  magicString.prepend(makeInjectedImports(options));
62
71
  magicString.append(makeRuntimeBlock(allRuntimeStatements));
63
72
  }
73
+ const code = magicString.toString();
64
74
  return {
65
- code: magicString.toString(),
75
+ code,
66
76
  map: magicString.generateMap({
67
77
  hires: true,
68
78
  includeContent: true,
69
79
  source: options.filename
70
- })
80
+ }),
81
+ relocations: resolvePendingRelocations(pendingRelocations, code)
71
82
  };
72
83
  }
73
84
  function isHoistedStatement(statement) {
@@ -91,34 +102,60 @@ function transformVariableStatement(statement, content, filename, effectBoundBin
91
102
  return {
92
103
  effectTexts: [],
93
104
  hoistedText: normalizeStatementText(sliceNode(content, statement)),
94
- loweredBindings: []
105
+ loweredBindings: [],
106
+ pendingRelocations: [],
107
+ usesPendingYieldHelper: false
95
108
  };
96
109
  }
97
110
  const effectTexts = [];
98
111
  const hoistedDeclarations = [];
99
112
  const loweredBindings = [];
113
+ const pendingRelocations = [];
100
114
  for (const declaration of statement.declarationList.declarations) {
101
115
  if (declaration.initializer && containsTopLevelAwait(declaration.initializer)) {
102
116
  const statementText = normalizeStatementText(sliceNode(content, statement));
103
117
  throw new Error(`${filename}: declarations in <script effect> cannot depend on await.\nUse yield* Effect.promise(...) or yield* Effect.tryPromise(...) instead.\n\nProblematic statement:\n${statementText}`);
104
118
  }
105
119
  if (declaration.initializer && isRuneInitializer(declaration.initializer)) {
106
- hoistedDeclarations.push(`${getDeclarationKind(statement.declarationList.flags)} ${normalizeStatementText(sliceNode(content, declaration))};`);
120
+ const renderedDeclaration = `${getDeclarationKind(statement.declarationList.flags)} ${normalizeStatementText(sliceNode(content, declaration))};`;
121
+ hoistedDeclarations.push(renderedDeclaration);
122
+ pendingRelocations.push(...make_declaration_relocations(declaration, renderedDeclaration, content));
107
123
  continue;
108
124
  }
109
125
  if (shouldHoistDeclaration(statement.declarationList.flags, declaration, effectBoundBindings)) {
110
- hoistedDeclarations.push(`${getDeclarationKind(statement.declarationList.flags)} ${normalizeStatementText(sliceNode(content, declaration))};`);
126
+ const renderedDeclaration = `${getDeclarationKind(statement.declarationList.flags)} ${normalizeStatementText(sliceNode(content, declaration))};`;
127
+ hoistedDeclarations.push(renderedDeclaration);
128
+ pendingRelocations.push(...make_declaration_relocations(declaration, renderedDeclaration, content));
111
129
  continue;
112
130
  }
113
131
  const bindingNames = extractBindingNames(declaration.name);
114
- for (const bindingName of bindingNames) hoistedDeclarations.push(makeStateDeclaration(bindingName, declaration, content));
132
+ const helper = create_lowered_declaration_helper(declaration, content);
133
+ if (helper) {
134
+ hoistedDeclarations.push(helper.declarationText);
135
+ pendingRelocations.push(helper.expressionRelocation);
136
+ }
137
+ if (helper?.tempName) hoistedDeclarations.push(makeTypedStateBinding(helper.tempName, helper.stateTypeText));
138
+ for (const bindingName of bindingNames) {
139
+ const stateDeclaration = makeStateDeclaration(bindingName, declaration, content, helper?.tempName ? null : helper?.stateTypeText);
140
+ hoistedDeclarations.push(stateDeclaration.code);
141
+ pendingRelocations.push(...stateDeclaration.pendingRelocations);
142
+ }
115
143
  loweredBindings.push(...bindingNames);
116
- if (declaration.initializer) effectTexts.push(makeEffectAssignment(declaration.name, declaration.initializer, content));
144
+ if (declaration.initializer) if (helper?.tempName) {
145
+ effectTexts.push(`${helper.tempName} = ${helper.assignmentExpression};`);
146
+ effectTexts.push(makeEffectAssignment(declaration.name, helper.tempName, content));
147
+ } else {
148
+ const effectAssignment = helper ? `${bindingNames[0]} = ${helper.assignmentExpression};` : makeEffectAssignment(declaration.name, declaration.initializer, content);
149
+ effectTexts.push(effectAssignment);
150
+ if (!helper) pendingRelocations.push(makeEffectAssignmentRelocation(declaration.initializer, effectAssignment, content));
151
+ }
117
152
  }
118
153
  return {
119
154
  effectTexts,
120
155
  hoistedText: hoistedDeclarations.join("\n"),
121
- loweredBindings
156
+ loweredBindings,
157
+ pendingRelocations,
158
+ usesPendingYieldHelper: false
122
159
  };
123
160
  }
124
161
  function shouldHoistDeclaration(flags, declaration, effectBoundBindings) {
@@ -178,16 +215,45 @@ function getDeclarationKind(flags) {
178
215
  if ((flags & ts.NodeFlags.Let) !== 0) return "let";
179
216
  return "var";
180
217
  }
181
- function makeStateDeclaration(name, declaration, content) {
182
- if (ts.isIdentifier(declaration.name) && declaration.type) return `let ${name} = $state<${normalizeStatementText(sliceNode(content, declaration.type))} | undefined>(undefined);`;
183
- return `let ${name} = $state<any>(undefined);`;
218
+ function makeStateDeclaration(name, declaration, content, inferredTypeText) {
219
+ let stateTypeText = null;
220
+ if (ts.isIdentifier(declaration.name) && declaration.type) stateTypeText = normalizeStatementText(sliceNode(content, declaration.type));
221
+ else if (inferredTypeText) stateTypeText = inferredTypeText;
222
+ const code = stateTypeText ? makeTypedStateBinding(name, stateTypeText) : `let ${name} = $state<any>(undefined);`;
223
+ const nameStart = code.indexOf(name);
224
+ const pendingRelocations = [{
225
+ originalStart: find_binding_name_start(declaration.name, name),
226
+ originalEnd: find_binding_name_end(declaration.name, name),
227
+ generatedSnippet: "",
228
+ generatedInnerStart: nameStart,
229
+ generatedInnerEnd: nameStart + name.length
230
+ }];
231
+ pendingRelocations[0] = {
232
+ ...pendingRelocations[0],
233
+ generatedSnippet: code
234
+ };
235
+ return {
236
+ code,
237
+ pendingRelocations
238
+ };
184
239
  }
185
240
  function makeEffectAssignment(name, initializer, content) {
186
241
  const target = normalizeStatementText(sliceNode(content, name));
187
- const expression = normalizeStatementText(sliceNode(content, initializer));
242
+ const expression = typeof initializer === "string" ? initializer : normalizeStatementText(sliceNode(content, initializer));
188
243
  if (ts.isIdentifier(name)) return `${target} = ${expression};`;
189
244
  return `(${target} = ${expression});`;
190
245
  }
246
+ function makeEffectAssignmentRelocation(initializer, effectAssignment, content) {
247
+ const expression = normalizeStatementText(sliceNode(content, initializer));
248
+ const generatedInnerStart = effectAssignment.lastIndexOf(expression);
249
+ return {
250
+ originalStart: initializer.getStart(),
251
+ originalEnd: initializer.end,
252
+ generatedSnippet: effectAssignment,
253
+ generatedInnerStart,
254
+ generatedInnerEnd: generatedInnerStart + expression.length
255
+ };
256
+ }
191
257
  function extractBindingNames(name) {
192
258
  if (ts.isIdentifier(name)) return [name.text];
193
259
  const names = [];
@@ -210,6 +276,10 @@ function containsYieldStar(node) {
210
276
  if (ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AsteriskToken && ts.isIdentifier(node.left) && node.left.text === "yield") return true;
211
277
  return node.getChildren().some((child) => isFunctionBoundary(child) ? false : containsYieldStar(child));
212
278
  }
279
+ function getYieldOperand(node) {
280
+ if (node && ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AsteriskToken && ts.isIdentifier(node.left) && node.left.text === "yield") return node.right;
281
+ return null;
282
+ }
213
283
  function containsTopLevelAwait(node) {
214
284
  if (ts.isAwaitExpression(node)) return true;
215
285
  return node.getChildren().some((child) => isFunctionBoundary(child) ? false : containsTopLevelAwait(child));
@@ -229,12 +299,83 @@ function indentBlock(text, indent) {
229
299
  function makeInjectedImports(options) {
230
300
  const runtimeModuleId = options.runtimeModuleId ?? DEFAULT_RUNTIME_MODULE_ID;
231
301
  const effectModuleId = options.effectModuleId ?? DEFAULT_EFFECT_MODULE_ID;
232
- return [
302
+ const lines = [
233
303
  `import { onMount as __svelteEffectRuntimeOnMount } from "${options.svelteModuleId ?? DEFAULT_SVELTE_MODULE_ID}";`,
234
304
  `import { Effect as __svelteEffectRuntimeEffect } from "${effectModuleId}";`,
235
305
  `import { get_effect_runtime_or_throw as __svelteEffectRuntimeGetRuntime, run_component_effect as __svelteEffectRuntimeRunComponentEffect } from "${runtimeModuleId}";`,
236
- ""
237
- ].join("\n");
306
+ `type __svelteEffectRuntimeYielded<T> = T extends __svelteEffectRuntimeEffect.Effect<infer A, any, any> ? A : T;`
307
+ ];
308
+ lines.push("");
309
+ return lines.join("\n");
310
+ }
311
+ function makeTypedStateBinding(name, stateTypeText) {
312
+ return `let ${name}: ${stateTypeText} | undefined = $state(undefined as ${stateTypeText} | undefined);`;
313
+ }
314
+ function create_lowered_declaration_helper(declaration, content) {
315
+ if (declaration.type || !declaration.initializer) return null;
316
+ const bindingNames = extractBindingNames(declaration.name);
317
+ const suffix = declaration.getStart();
318
+ const helperName = `__svelteEffectRuntime_${bindingNames[0] ?? "binding"}_${suffix}`;
319
+ const expressionNode = getYieldOperand(declaration.initializer) ?? declaration.initializer;
320
+ const expressionText = normalizeStatementText(sliceNode(content, expressionNode));
321
+ const declarationText = `const ${helperName} = () => ${expressionText};`;
322
+ const yieldedExpression = getYieldOperand(declaration.initializer);
323
+ return {
324
+ declarationText,
325
+ stateTypeText: yieldedExpression ? `__svelteEffectRuntimeYielded<ReturnType<typeof ${helperName}>>` : `ReturnType<typeof ${helperName}>`,
326
+ assignmentExpression: yieldedExpression ? `yield* ${helperName}()` : `${helperName}()`,
327
+ tempName: ts.isIdentifier(declaration.name) ? void 0 : `__svelteEffectRuntimeTemp_${suffix}`,
328
+ expressionRelocation: {
329
+ originalStart: expressionNode.getStart(),
330
+ originalEnd: expressionNode.end,
331
+ generatedSnippet: declarationText,
332
+ generatedInnerStart: declarationText.lastIndexOf(expressionText),
333
+ generatedInnerEnd: declarationText.lastIndexOf(expressionText) + expressionText.length
334
+ }
335
+ };
336
+ }
337
+ function make_declaration_relocations(declaration, renderedDeclaration, content) {
338
+ const relocations = [];
339
+ if (ts.isIdentifier(declaration.name)) {
340
+ const nameStart = renderedDeclaration.indexOf(declaration.name.text);
341
+ relocations.push({
342
+ originalStart: declaration.name.getStart(),
343
+ originalEnd: declaration.name.end,
344
+ generatedSnippet: renderedDeclaration,
345
+ generatedInnerStart: nameStart,
346
+ generatedInnerEnd: nameStart + declaration.name.text.length
347
+ });
348
+ }
349
+ if (declaration.initializer) {
350
+ const initializerText = normalizeStatementText(sliceNode(content, declaration.initializer));
351
+ const initializerStart = renderedDeclaration.lastIndexOf(initializerText);
352
+ if (initializerStart >= 0) relocations.push({
353
+ originalStart: declaration.initializer.getStart(),
354
+ originalEnd: declaration.initializer.end,
355
+ generatedSnippet: renderedDeclaration,
356
+ generatedInnerStart: initializerStart,
357
+ generatedInnerEnd: initializerStart + initializerText.length
358
+ });
359
+ }
360
+ return relocations;
361
+ }
362
+ function find_binding_name_start(name, bindingName) {
363
+ if (ts.isIdentifier(name)) return name.text === bindingName ? name.getStart() : -1;
364
+ for (const element of name.elements) {
365
+ if (ts.isOmittedExpression(element)) continue;
366
+ const start = find_binding_name_start(element.name, bindingName);
367
+ if (start !== -1) return start;
368
+ }
369
+ return -1;
370
+ }
371
+ function find_binding_name_end(name, bindingName) {
372
+ if (ts.isIdentifier(name)) return name.text === bindingName ? name.end : -1;
373
+ for (const element of name.elements) {
374
+ if (ts.isOmittedExpression(element)) continue;
375
+ const end = find_binding_name_end(element.name, bindingName);
376
+ if (end !== -1) return end;
377
+ }
378
+ return -1;
238
379
  }
239
380
  function makeRuntimeBlock(statements) {
240
381
  return [
@@ -255,6 +396,22 @@ function makeRuntimeBlock(statements) {
255
396
  ""
256
397
  ].join("\n");
257
398
  }
399
+ function resolvePendingRelocations(pendingRelocations, code) {
400
+ const relocations = [];
401
+ let searchStart = 0;
402
+ for (const relocation of pendingRelocations) {
403
+ const generatedStart = code.indexOf(relocation.generatedSnippet, searchStart);
404
+ if (generatedStart === -1) continue;
405
+ searchStart = generatedStart + relocation.generatedSnippet.length;
406
+ relocations.push({
407
+ originalStart: relocation.originalStart,
408
+ originalEnd: relocation.originalEnd,
409
+ generatedStart: generatedStart + relocation.generatedInnerStart,
410
+ generatedEnd: generatedStart + relocation.generatedInnerEnd
411
+ });
412
+ }
413
+ return relocations;
414
+ }
258
415
  //#endregion
259
416
  export { transformEffectScript };
260
417