svelte-effect-runtime 3.4.4 → 3.4.6
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-5cizmHtc.js → client-CsVu54pU.js} +119 -56
- package/.dist/chunks/client-CsVu54pU.js.map +1 -0
- package/.dist/chunks/{descriptors-OS4VfJuW.js → descriptors-cOe9uRJz.js} +2 -2
- package/.dist/chunks/descriptors-cOe9uRJz.js.map +1 -0
- package/.dist/chunks/{dispatcher-C38yhZRs.js → dispatcher-LtvFKYUp.js} +3 -3
- package/.dist/chunks/dispatcher-LtvFKYUp.js.map +1 -0
- package/.dist/chunks/{dispatcher-DuBLHNa6.js → dispatcher-pHH4JcFR.js} +12 -11
- package/.dist/chunks/dispatcher-pHH4JcFR.js.map +1 -0
- package/.dist/chunks/{errors-0PaWf7Bq.js → errors-Dcf0MVbq.js} +3 -3
- package/.dist/chunks/errors-Dcf0MVbq.js.map +1 -0
- package/.dist/chunks/{runtime-C51Dv3K6.js → runtime-ekkMQ-wL.js} +4 -4
- package/.dist/chunks/runtime-ekkMQ-wL.js.map +1 -0
- package/.dist/chunks/{transform-Cdsx7ygD.js → transform-02e-RvXH.js} +246 -172
- package/.dist/chunks/transform-02e-RvXH.js.map +1 -0
- package/.dist/chunks/{vite-DR3-WaqQ.js → vite-Dkwdtbgj.js} +118 -34
- package/.dist/chunks/vite-Dkwdtbgj.js.map +1 -0
- package/.dist/detect.js.map +1 -1
- package/.dist/dispatcher.d.ts +1 -1
- package/.dist/dispatcher.js +1 -1
- package/.dist/errors.d.ts +1 -1
- package/.dist/internal/generators.js +2 -2
- package/.dist/internal/remote-client.js +1 -1
- package/.dist/markup/promise.js +1 -1
- package/.dist/markup/promise.js.map +1 -1
- package/.dist/markup/run.js +3 -3
- package/.dist/markup/run.js.map +1 -1
- package/.dist/markup/transform/index.d.ts +8 -0
- package/.dist/markup/transform/scan.d.ts +20 -0
- package/.dist/markup/transform/types.d.ts +136 -2
- package/.dist/markup/transform.js +1 -1
- package/.dist/markup/value.js +1 -1
- package/.dist/markup/value.js.map +1 -1
- package/.dist/mod.d.ts +1 -1
- package/.dist/mod.js +3 -3
- package/.dist/mod.js.map +1 -1
- package/.dist/remote/client/command.d.ts +1 -1
- package/.dist/remote/client/effect.d.ts +15 -1
- package/.dist/remote/client/index.d.ts +1 -1
- package/.dist/remote/client/types.d.ts +3 -1
- package/.dist/remote/client.js +1 -1
- package/.dist/remote/server.d.ts +8 -5
- package/.dist/remote/server.js +38 -15
- package/.dist/remote/server.js.map +1 -1
- package/.dist/remote/shared.d.ts +126 -0
- package/.dist/remote/shared.js +117 -5
- package/.dist/remote/shared.js.map +1 -1
- package/.dist/runtime/transform.js +2 -2
- package/.dist/runtime/transform.js.map +1 -1
- package/.dist/script-transform/types.d.ts +95 -0
- package/.dist/server/control-flow.d.ts +70 -4
- package/.dist/server/effects.d.ts +15 -1
- package/.dist/server/factories.d.ts +128 -9
- package/.dist/server/index.d.ts +2 -2
- package/.dist/server/runtime.d.ts +1 -1
- package/.dist/server/types.d.ts +128 -7
- package/.dist/server.d.ts +1 -1
- package/.dist/server.js +40 -23
- package/.dist/server.js.map +1 -1
- package/.dist/vite.js +1 -1
- package/LICENSE +29 -0
- package/package.json +21 -21
- package/.dist/chunks/client-5cizmHtc.js.map +0 -1
- package/.dist/chunks/descriptors-OS4VfJuW.js.map +0 -1
- package/.dist/chunks/dispatcher-C38yhZRs.js.map +0 -1
- package/.dist/chunks/dispatcher-DuBLHNa6.js.map +0 -1
- package/.dist/chunks/errors-0PaWf7Bq.js.map +0 -1
- package/.dist/chunks/runtime-C51Dv3K6.js.map +0 -1
- package/.dist/chunks/transform-Cdsx7ygD.js.map +0 -1
- package/.dist/chunks/vite-DR3-WaqQ.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/shared.ts"],"sourcesContent":["/**\n * Shared types, markers, and constructors used by both the client-side remote\n * adapters and the server-side handler runtime. These types define the error\n * protocol that flows across the network boundary.\n *\n * @since 2.0.0\n */\n\n/**\n * Well-known marker injected into every serialised remote-failure envelope\n * so the client can reliably distinguish runtime errors from domain values.\n *\n * @since 2.0.0\n * @internal\n */\nexport const EFFECT_REMOTE_ERROR_MARKER = \"__svelte_effect_remote__\";\n\n/**\n * Well-known symbol used to attach a payload decoder to a remote function\n * so the client's transport layer can decode domain error types.\n *\n * @since 2.0.0\n * @internal\n */\nexport const REMOTE_ERROR_DECODER = Symbol.for(\n \"svelte-effect-runtime/remote-error-decoder\",\n);\n\n/** Form validation helpers and types. */\n\n/**\n * A single field-level or form-level validation issue reported by a\n * {@link Form} handler.\n *\n * @since 2.0.0\n */\nexport interface FormIssue {\n /** Human-readable validation message. */\n message: string;\n /** Path to the offending field as an array of string-or-number keys. */\n path: (string | number)[];\n}\n\n/**\n * Error subtype thrown by {@link Form} handlers to signal validation\n * failures. The `issues` array is forwarded to SvelteKit's `invalid()`\n * helper on the server and surfaced as `FormError` on the client.\n *\n * @since 2.0.0\n */\nexport interface FormError<SchemaType = unknown> {\n readonly _tag: \"FormError\";\n readonly issues: readonly FormIssue[];\n /** Phantom type slot for the schema this error was derived from. */\n readonly _schema?: SchemaType;\n}\n\n/**\n * Creates a {@link FormError} holding the given issues.\n *\n * @since 2.0.0\n * @param issues - The validation issues to attach.\n * @returns A FormError with the `_tag` set and no schema reference.\n */\nexport function create_form_error(issues: readonly FormIssue[]): FormError {\n return { _tag: \"FormError\", issues };\n}\n\n/**\n * Type guard that narrows an unknown value to a {@link FormError}.\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a FormError.\n */\nexport function is_form_error(value: unknown): value is FormError {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<string, unknown>)._tag === \"FormError\"\n );\n}\n\n/** Remote error types shared by client and server helpers. */\n\n/**\n * Union of all wire-level error shapes that a remote function can\n * surface on its error channel.\n *\n * @example\n * ```ts\n * const result = yield* myQuery();\n * // error channel is RemoteFailure<DomainError>\n * ```\n *\n * @since 2.0.0\n */\nexport type RemoteFailure<ErrorType> =\n | ErrorType\n | RemoteValidationError\n | RemoteHttpError\n | RemoteTransportError;\n\n/**\n * Validation errors that originate from a server-side {@link Form}\n * handler calling `invalid()` (SvelteKit's `fail`).\n *\n * @since 2.0.0\n */\nexport interface RemoteValidationError {\n readonly _tag: \"RemoteValidationError\";\n readonly issues?: readonly FormIssue[];\n readonly body?: unknown;\n readonly status: number;\n}\n\n/**\n * HTTP-level errors with a status code and optional response body. Raised\n * when the server explicitly calls SvelteKit's `error(status, body)`.\n *\n * @since 2.0.0\n */\nexport interface RemoteHttpError {\n readonly _tag: \"RemoteHttpError\";\n readonly status: number;\n readonly body?: unknown;\n readonly cause?: unknown;\n}\n\n/**\n * Transport-level errors raised by the client adapter when the network\n * request fails or the response cannot be decoded.\n *\n * @since 2.0.0\n */\nexport interface RemoteTransportError {\n readonly _tag: \"RemoteTransportError\";\n readonly cause?: unknown;\n readonly body?: unknown;\n}\n\n/**\n * Wire format for an encoded remote failure. The server wraps domain\n * errors in this envelope before serialising them with devalue.\n *\n * @since 2.0.0\n * @internal\n */\nexport interface SerializedRemoteFailureEnvelope {\n readonly __svelte_effect_remote__: true;\n readonly encoded: string;\n}\n\n/** Constructors for structured remote error values. */\n\n/**\n * Creates a {@link RemoteValidationError} from a list of form issues.\n *\n * @since 2.0.0\n * @param issues - The validation issues reported by the server handler.\n * @param body - Optional response body returned alongside the error.\n * @param status - HTTP status code (defaults to 400).\n * @returns A remote-validation error shape.\n * @internal\n */\nexport function create_remote_validation_error(\n issues: readonly FormIssue[],\n body?: unknown,\n status = 400,\n): RemoteValidationError {\n\n return { _tag: \"RemoteValidationError\", issues, body, status };\n}\n\n/**\n * Creates a {@link RemoteHttpError} for a given HTTP status.\n *\n * @since 2.0.0\n * @param status - The HTTP status code.\n * @param body - Optional response body.\n * @param cause - Optional underlying cause.\n * @returns A remote HTTP error shape.\n * @internal\n */\nexport function create_remote_http_error(\n status: number,\n body?: unknown,\n cause?: unknown,\n): RemoteHttpError {\n\n return { _tag: \"RemoteHttpError\", status, body, cause };\n}\n\n/**\n * Creates a {@link RemoteTransportError} for network or decode failures.\n *\n * @since 2.0.0\n * @param cause - The underlying error that caused the transport failure.\n * @param body - Optional response body if one was received.\n * @returns A remote transport error shape.\n * @internal\n */\nexport function create_remote_transport_error(\n cause: unknown,\n body?: unknown,\n): RemoteTransportError {\n\n return { _tag: \"RemoteTransportError\", cause, body };\n}\n\n/**\n * Wraps a devalue-encoded error string inside a\n * {@link SerializedRemoteFailureEnvelope}.\n *\n * @since 2.0.0\n * @param encoded - The devalue-encoded error value.\n * @returns The wire-format envelope.\n * @internal\n */\nexport function create_serialized_remote_failure_envelope(\n encoded: string,\n): SerializedRemoteFailureEnvelope {\n\n return { __svelte_effect_remote__: true, encoded };\n}\n\n/** Type guards for structured remote error values. */\n\n/**\n * Checks whether a value is a {@link SerializedRemoteFailureEnvelope}.\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a serialised failure envelope.\n * @internal\n */\nexport function is_serialized_remote_failure_envelope(\n value: unknown,\n): value is SerializedRemoteFailureEnvelope {\n\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<string, unknown>).__svelte_effect_remote__ === true\n );\n}\n\n/**\n * Checks whether a value is a {@link RemoteValidationError}.\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote validation error.\n */\nexport function is_remote_validation_error(\n value: unknown,\n): value is RemoteValidationError {\n\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<string, unknown>)._tag === \"RemoteValidationError\"\n );\n}\n\n/**\n * Checks whether a value is a {@link RemoteHttpError}.\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote HTTP error.\n */\nexport function is_remote_http_error(\n value: unknown,\n): value is RemoteHttpError {\n\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<string, unknown>)._tag === \"RemoteHttpError\"\n );\n}\n\n/**\n * Checks whether a value is a {@link RemoteTransportError}.\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote transport error.\n */\nexport function is_remote_transport_error(\n value: unknown,\n): value is RemoteTransportError {\n\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<string, unknown>)._tag === \"RemoteTransportError\"\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,6BAA6B;;;;;;;;AAS1C,MAAa,uBAAuB,OAAO,IACzC,4CACF;;;;;;;;AAsCA,SAAgB,kBAAkB,QAAyC;CACzE,OAAO;EAAE,MAAM;EAAa;CAAO;AACrC;;;;;;;;AASA,SAAgB,cAAc,OAAoC;CAChE,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAkC,SAAS;AAEhD;;;;;;;;;;;;AAoFA,SAAgB,+BACd,QACA,MACA,SAAS,KACc;CAEvB,OAAO;EAAE,MAAM;EAAyB;EAAQ;EAAM;CAAO;AAC/D;;;;;;;;;;;AAYA,SAAgB,yBACd,QACA,MACA,OACiB;CAEjB,OAAO;EAAE,MAAM;EAAmB;EAAQ;EAAM;CAAM;AACxD;;;;;;;;;;AAWA,SAAgB,8BACd,OACA,MACsB;CAEtB,OAAO;EAAE,MAAM;EAAwB;EAAO;CAAK;AACrD;;;;;;;;;;AAWA,SAAgB,0CACd,SACiC;CAEjC,OAAO;EAAE,0BAA0B;EAAM;CAAQ;AACnD;;;;;;;;;;AAYA,SAAgB,sCACd,OAC0C;CAE1C,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAkC,6BAA6B;AAEpE;;;;;;;;AASA,SAAgB,2BACd,OACgC;CAEhC,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAkC,SAAS;AAEhD;;;;;;;;AASA,SAAgB,qBACd,OAC0B;CAE1B,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAkC,SAAS;AAEhD;;;;;;;;AASA,SAAgB,0BACd,OAC+B;CAE/B,OACE,OAAO,UAAU,YACjB,UAAU,QACT,MAAkC,SAAS;AAEhD"}
|
|
1
|
+
{"version":3,"file":"shared.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/remote/shared.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\n/**\n * Shared types, markers, and constructors used by both the client-side remote\n * adapters and the server-side handler runtime. These types define the error\n * protocol that flows across the network boundary.\n *\n * @since 2.0.0\n */\n\n/**\n * Well-known marker injected into every serialised remote-failure envelope\n * so the client can reliably distinguish runtime errors from domain values.\n *\n * @example\n * ```ts\n * if (envelope[EFFECT_REMOTE_ERROR_MARKER] === true) {\n * console.log(envelope.encoded);\n * }\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport const EFFECT_REMOTE_ERROR_MARKER = \"__svelte_effect_remote__\";\n\n/**\n * Well-known symbol used to attach a payload decoder to a remote function\n * so the client's transport layer can decode domain error types.\n *\n * @example\n * ```ts\n * Reflect.get(remote_function, REMOTE_ERROR_DECODER);\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport const REMOTE_ERROR_DECODER = Symbol.for(\"svelte-effect-runtime/remote-error-decoder\");\n\n/** Form validation helpers and types. */\n\n/**\n * A single field-level or form-level validation issue reported by a\n * {@link Form} handler.\n *\n * @example\n * ```ts\n * const issue: FormIssue = {\n * message: \"Use an email address.\",\n * path: [\"email\"],\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface FormIssue {\n\t/** Human-readable validation message. */\n\tmessage: string;\n\t/** Path to the offending field as an array of string-or-number keys. */\n\tpath: (string | number)[];\n}\n\n/**\n * Error subtype thrown by {@link Form} handlers to signal validation\n * failures. The `issues` array is forwarded to SvelteKit's `invalid()`\n * helper on the server and surfaced as `FormError` on the client.\n *\n * @example\n * ```ts\n * const error: FormError = {\n * _tag: \"FormError\",\n * issues: [{ message: \"Required.\", path: [\"email\"] }],\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface FormError<SchemaType = unknown> {\n\treadonly _tag: \"FormError\";\n\treadonly issues: readonly FormIssue[];\n\t/** Phantom type slot for the schema this error was derived from. */\n\treadonly _schema?: SchemaType;\n}\n\n/**\n * Creates a {@link FormError} holding the given issues.\n *\n * @example\n * ```ts\n * const error = create_form_error([\n * { message: \"Required.\", path: [\"email\"] },\n * ]);\n * ```\n *\n * @since 2.0.0\n * @param issues - The validation issues to attach.\n * @returns A FormError with the `_tag` set and no schema reference.\n */\nexport function create_form_error(issues: readonly FormIssue[]): FormError {\n\treturn { _tag: \"FormError\", issues };\n}\n\n/**\n * Type guard that narrows an unknown value to a {@link FormError}.\n *\n * @example\n * ```ts\n * if (is_form_error(error)) {\n * console.log(error.issues);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a FormError.\n */\nexport function is_form_error(value: unknown): value is FormError {\n\treturn is_form_error_value(value);\n}\n\n/** Remote error types shared by client and server helpers. */\n\n/**\n * Union of all wire-level error shapes that a remote function can\n * surface on its error channel.\n *\n * @example\n * ```ts\n * const result = yield* myQuery();\n * // error channel is RemoteFailure<DomainError>\n * ```\n *\n * @since 2.0.0\n */\nexport type RemoteFailure<ErrorType> =\n\t| ErrorType\n\t| RemoteValidationError\n\t| RemoteHttpError\n\t| RemoteTransportError;\n\n/**\n * Validation errors that originate from a server-side {@link Form}\n * handler calling `invalid()` (SvelteKit's `fail`).\n *\n * @example\n * ```ts\n * const error: RemoteValidationError = {\n * _tag: \"RemoteValidationError\",\n * status: 400,\n * issues: [{ message: \"Required.\", path: [\"email\"] }],\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface RemoteValidationError {\n\treadonly _tag: \"RemoteValidationError\";\n\treadonly issues?: readonly FormIssue[];\n\treadonly body?: unknown;\n\treadonly status: number;\n}\n\n/**\n * HTTP-level errors with a status code and optional response body. Raised\n * when the server explicitly calls SvelteKit's `error(status, body)`.\n *\n * @example\n * ```ts\n * const error: RemoteHttpError = {\n * _tag: \"RemoteHttpError\",\n * status: 404,\n * body: { message: \"Not found\" },\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface RemoteHttpError {\n\treadonly _tag: \"RemoteHttpError\";\n\treadonly status: number;\n\treadonly body?: unknown;\n\treadonly cause?: unknown;\n}\n\n/**\n * Transport-level errors raised by the client adapter when the network\n * request fails or the response cannot be decoded.\n *\n * @example\n * ```ts\n * const error: RemoteTransportError = {\n * _tag: \"RemoteTransportError\",\n * cause: new Error(\"Network unavailable\"),\n * };\n * ```\n *\n * @since 2.0.0\n */\nexport interface RemoteTransportError {\n\treadonly _tag: \"RemoteTransportError\";\n\treadonly cause?: unknown;\n\treadonly body?: unknown;\n}\n\n/**\n * Wire format for an encoded remote failure. The server wraps domain\n * errors in this envelope before serialising them with devalue.\n *\n * @example\n * ```ts\n * const envelope: SerializedRemoteFailureEnvelope = {\n * __svelte_effect_remote__: true,\n * encoded: \"[\\\"DomainError\\\"]\",\n * };\n * ```\n *\n * @since 2.0.0\n * @internal\n */\nexport interface SerializedRemoteFailureEnvelope {\n\treadonly __svelte_effect_remote__: true;\n\treadonly encoded: string;\n}\n\nconst FormIssuePathSegmentSchema = Schema.Union([Schema.String, Schema.Number]);\n\nconst FormIssueSchema = Schema.Struct({\n\tmessage: Schema.String,\n\tpath: Schema.Array(FormIssuePathSegmentSchema),\n});\n\nconst FormErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"FormError\"),\n\tissues: Schema.Array(FormIssueSchema),\n});\n\nconst SerializedRemoteFailureEnvelopeSchema = Schema.Struct({\n\t__svelte_effect_remote__: Schema.Literal(true),\n\tencoded: Schema.String,\n});\n\nconst RemoteValidationErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"RemoteValidationError\"),\n\tbody: Schema.optional(Schema.Unknown),\n\tissues: Schema.optional(Schema.Array(FormIssueSchema)),\n\tstatus: Schema.Number,\n});\n\nconst RemoteHttpErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"RemoteHttpError\"),\n\tbody: Schema.optional(Schema.Unknown),\n\tcause: Schema.optional(Schema.Unknown),\n\tstatus: Schema.Number,\n});\n\nconst RemoteTransportErrorSchema = Schema.Struct({\n\t_tag: Schema.Literal(\"RemoteTransportError\"),\n\tbody: Schema.optional(Schema.Unknown),\n\tcause: Schema.optional(Schema.Unknown),\n});\n\nconst is_form_error_value = Schema.is(FormErrorSchema);\nconst is_remote_http_error_value = Schema.is(RemoteHttpErrorSchema);\nconst is_remote_transport_error_value = Schema.is(RemoteTransportErrorSchema);\nconst is_remote_validation_error_value = Schema.is(RemoteValidationErrorSchema);\nconst is_serialized_remote_failure_envelope_value = Schema.is(\n\tSerializedRemoteFailureEnvelopeSchema,\n);\n\n/** Constructors for structured remote error values. */\n\n/**\n * Creates a {@link RemoteValidationError} from a list of form issues.\n *\n * @example\n * ```ts\n * const error = create_remote_validation_error([\n * { message: \"Required.\", path: [\"email\"] },\n * ]);\n * ```\n *\n * @since 2.0.0\n * @param issues - The validation issues reported by the server handler.\n * @param body - Optional response body returned alongside the error.\n * @param status - HTTP status code (defaults to 400).\n * @returns A remote-validation error shape.\n * @internal\n */\nexport function create_remote_validation_error(\n\tissues: readonly FormIssue[],\n\tbody?: unknown,\n\tstatus = 400,\n): RemoteValidationError {\n\treturn { _tag: \"RemoteValidationError\", issues, body, status };\n}\n\n/**\n * Creates a {@link RemoteHttpError} for a given HTTP status.\n *\n * @example\n * ```ts\n * const error = create_remote_http_error(404, { message: \"Not found\" });\n * ```\n *\n * @since 2.0.0\n * @param status - The HTTP status code.\n * @param body - Optional response body.\n * @param cause - Optional underlying cause.\n * @returns A remote HTTP error shape.\n * @internal\n */\nexport function create_remote_http_error(\n\tstatus: number,\n\tbody?: unknown,\n\tcause?: unknown,\n): RemoteHttpError {\n\treturn { _tag: \"RemoteHttpError\", status, body, cause };\n}\n\n/**\n * Creates a {@link RemoteTransportError} for network or decode failures.\n *\n * @example\n * ```ts\n * const error = create_remote_transport_error(new Error(\"Network unavailable\"));\n * ```\n *\n * @since 2.0.0\n * @param cause - The underlying error that caused the transport failure.\n * @param body - Optional response body if one was received.\n * @returns A remote transport error shape.\n * @internal\n */\nexport function create_remote_transport_error(\n\tcause: unknown,\n\tbody?: unknown,\n): RemoteTransportError {\n\treturn { _tag: \"RemoteTransportError\", cause, body };\n}\n\n/**\n * Wraps a devalue-encoded error string inside a\n * {@link SerializedRemoteFailureEnvelope}.\n *\n * @example\n * ```ts\n * const envelope = create_serialized_remote_failure_envelope(encoded);\n * ```\n *\n * @since 2.0.0\n * @param encoded - The devalue-encoded error value.\n * @returns The wire-format envelope.\n * @internal\n */\nexport function create_serialized_remote_failure_envelope(\n\tencoded: string,\n): SerializedRemoteFailureEnvelope {\n\treturn { __svelte_effect_remote__: true, encoded };\n}\n\n/** Type guards for structured remote error values. */\n\n/**\n * Checks whether a value is a {@link SerializedRemoteFailureEnvelope}.\n *\n * @example\n * ```ts\n * if (is_serialized_remote_failure_envelope(value)) {\n * console.log(value.encoded);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a serialised failure envelope.\n * @internal\n */\nexport function is_serialized_remote_failure_envelope(\n\tvalue: unknown,\n): value is SerializedRemoteFailureEnvelope {\n\treturn is_serialized_remote_failure_envelope_value(value);\n}\n\n/**\n * Checks whether a value is a {@link RemoteValidationError}.\n *\n * @example\n * ```ts\n * if (is_remote_validation_error(error)) {\n * console.log(error.issues);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote validation error.\n */\nexport function is_remote_validation_error(value: unknown): value is RemoteValidationError {\n\treturn is_remote_validation_error_value(value);\n}\n\n/**\n * Checks whether a value is a {@link RemoteHttpError}.\n *\n * @example\n * ```ts\n * if (is_remote_http_error(error)) {\n * console.log(error.status);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote HTTP error.\n */\nexport function is_remote_http_error(value: unknown): value is RemoteHttpError {\n\treturn is_remote_http_error_value(value);\n}\n\n/**\n * Checks whether a value is a {@link RemoteTransportError}.\n *\n * @example\n * ```ts\n * if (is_remote_transport_error(error)) {\n * console.error(error.cause);\n * }\n * ```\n *\n * @since 2.0.0\n * @param value - The value to check.\n * @returns `true` when the value is a remote transport error.\n */\nexport function is_remote_transport_error(value: unknown): value is RemoteTransportError {\n\treturn is_remote_transport_error_value(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,6BAA6B;;;;;;;;;;;;;AAc1C,MAAa,uBAAuB,OAAO,IAAI,4CAA4C;;;;;;;;;;;;;;;AA6D3F,SAAgB,kBAAkB,QAAyC;CAC1E,OAAO;EAAE,MAAM;EAAa;CAAO;AACpC;;;;;;;;;;;;;;;AAgBA,SAAgB,cAAc,OAAoC;CACjE,OAAO,oBAAoB,KAAK;AACjC;AA0GA,MAAM,6BAA6B,OAAO,MAAM,CAAC,OAAO,QAAQ,OAAO,MAAM,CAAC;AAE9E,MAAM,kBAAkB,OAAO,OAAO;CACrC,SAAS,OAAO;CAChB,MAAM,OAAO,MAAM,0BAA0B;AAC9C,CAAC;AAED,MAAM,kBAAkB,OAAO,OAAO;CACrC,MAAM,OAAO,QAAQ,WAAW;CAChC,QAAQ,OAAO,MAAM,eAAe;AACrC,CAAC;AAED,MAAM,wCAAwC,OAAO,OAAO;CAC3D,0BAA0B,OAAO,QAAQ,IAAI;CAC7C,SAAS,OAAO;AACjB,CAAC;AAED,MAAM,8BAA8B,OAAO,OAAO;CACjD,MAAM,OAAO,QAAQ,uBAAuB;CAC5C,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,QAAQ,OAAO,SAAS,OAAO,MAAM,eAAe,CAAC;CACrD,QAAQ,OAAO;AAChB,CAAC;AAED,MAAM,wBAAwB,OAAO,OAAO;CAC3C,MAAM,OAAO,QAAQ,iBAAiB;CACtC,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO,SAAS,OAAO,OAAO;CACrC,QAAQ,OAAO;AAChB,CAAC;AAED,MAAM,6BAA6B,OAAO,OAAO;CAChD,MAAM,OAAO,QAAQ,sBAAsB;CAC3C,MAAM,OAAO,SAAS,OAAO,OAAO;CACpC,OAAO,OAAO,SAAS,OAAO,OAAO;AACtC,CAAC;AAED,MAAM,sBAAsB,OAAO,GAAG,eAAe;AACrD,MAAM,6BAA6B,OAAO,GAAG,qBAAqB;AAClE,MAAM,kCAAkC,OAAO,GAAG,0BAA0B;AAC5E,MAAM,mCAAmC,OAAO,GAAG,2BAA2B;AAC9E,MAAM,8CAA8C,OAAO,GAC1D,qCACD;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,+BACf,QACA,MACA,SAAS,KACe;CACxB,OAAO;EAAE,MAAM;EAAyB;EAAQ;EAAM;CAAO;AAC9D;;;;;;;;;;;;;;;;AAiBA,SAAgB,yBACf,QACA,MACA,OACkB;CAClB,OAAO;EAAE,MAAM;EAAmB;EAAQ;EAAM;CAAM;AACvD;;;;;;;;;;;;;;;AAgBA,SAAgB,8BACf,OACA,MACuB;CACvB,OAAO;EAAE,MAAM;EAAwB;EAAO;CAAK;AACpD;;;;;;;;;;;;;;;AAgBA,SAAgB,0CACf,SACkC;CAClC,OAAO;EAAE,0BAA0B;EAAM;CAAQ;AAClD;;;;;;;;;;;;;;;;;AAmBA,SAAgB,sCACf,OAC2C;CAC3C,OAAO,4CAA4C,KAAK;AACzD;;;;;;;;;;;;;;;AAgBA,SAAgB,2BAA2B,OAAgD;CAC1F,OAAO,iCAAiC,KAAK;AAC9C;;;;;;;;;;;;;;;AAgBA,SAAgB,qBAAqB,OAA0C;CAC9E,OAAO,2BAA2B,KAAK;AACxC;;;;;;;;;;;;;;;AAgBA,SAAgB,0BAA0B,OAA+C;CACxF,OAAO,gCAAgC,KAAK;AAC7C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as PreprocessError, r as AwaitInEffectWorkError } from "../chunks/errors-
|
|
2
|
-
import { a as is_yield_star_expression, c as slice, d as collect_top_level_binding_names, f as has_local_import_binding, i as find_yield_star_node, l as slice_start, n as collect_yield_star_nodes, o as validate_rune_yield_usage, p as make_imports, r as contains_top_level_await, s as create_source_map, t as transform_markup_effect, u as collect_free_identifiers } from "../chunks/transform-
|
|
1
|
+
import { d as PreprocessError, r as AwaitInEffectWorkError } from "../chunks/errors-Dcf0MVbq.js";
|
|
2
|
+
import { a as is_yield_star_expression, c as slice, d as collect_top_level_binding_names, f as has_local_import_binding, i as find_yield_star_node, l as slice_start, n as collect_yield_star_nodes, o as validate_rune_yield_usage, p as make_imports, r as contains_top_level_await, s as create_source_map, t as transform_markup_effect, u as collect_free_identifiers } from "../chunks/transform-02e-RvXH.js";
|
|
3
3
|
import { contains_top_level_yield_star } from "../detect.js";
|
|
4
4
|
import MagicString from "magic-string";
|
|
5
5
|
import ts from "typescript";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/script-transform/runtime-block.ts","../../../modules/svelte-effect-runtime/src/script-transform/lower.ts","../../../modules/svelte-effect-runtime/src/script-transform/index.ts","../../../modules/svelte-effect-runtime/src/runtime/transform.ts"],"sourcesContent":["import type { EffectBlock, RuntimeImportBindings } from \"./types.ts\";\n\n/**\n * Builds the runtime blocks appended to lowered script effect code.\n *\n * @since 2.0.0\n * @param blocks - Effect bodies and dependency reads to emit.\n * @returns Full `$effect` blocks that fork generated `Effect.gen` programs.\n */\nexport function make_runtime_block(blocks: EffectBlock[]): string {\n const bindings: RuntimeImportBindings = {\n cancel: \"__SER___cancel\",\n dispatcher: \"get_dispatcher\",\n dispatcher_value: \"__SER___dispatcher\",\n effect: \"Effect\",\n program: \"__SER___program\",\n untrack: \"untrack\",\n };\n\n return make_runtime_block_with_bindings(blocks, bindings);\n}\n\n/**\n * Builds the runtime blocks appended to lowered script effect code with\n * explicit runtime import bindings.\n *\n * @since 2.4.2\n * @param blocks - Effect bodies and dependency reads to emit.\n * @param bindings - Runtime binding names available in the generated code.\n * @returns Full `$effect` blocks that fork generated `Effect.gen` programs.\n */\nexport function make_runtime_block_with_bindings(\n blocks: EffectBlock[],\n bindings: RuntimeImportBindings,\n): string {\n const merged_block = merge_effect_blocks(blocks);\n const dep_reads = merged_block.deps.map((dep) => ` ${dep};`);\n\n const body = merged_block.statements\n .map((statement) => ` ${statement}`)\n .join(\"\\n\");\n\n return [\n \"\",\n \"$effect(() => {\",\n ...dep_reads,\n ` const ${bindings.dispatcher_value} = ${bindings.dispatcher}();`,\n ` const ${bindings.program} = ${bindings.effect}.gen(function* () {`,\n body,\n \" });\",\n ` const ${bindings.cancel} = ${bindings.untrack}(() => ${bindings.dispatcher_value}.fork(${bindings.program}));`,\n ` import.meta.hot?.dispose(${bindings.cancel});`,\n ` return ${bindings.cancel};`,\n \"});\",\n \"\",\n ].join(\"\\n\");\n}\n\nfunction merge_effect_blocks(blocks: EffectBlock[]): EffectBlock {\n const statements = blocks.flatMap((block) => block.statements);\n const deps = blocks.flatMap((block) => block.deps);\n\n return {\n statements,\n deps: [...new Set(deps)],\n };\n}\n","import { collect_free_identifiers } from \"$/markup/transform/expressions.ts\";\nimport { contains_top_level_yield_star } from \"$/detect.ts\";\nimport {\n collect_yield_star_nodes,\n find_yield_star_node,\n is_yield_star_expression,\n} from \"./ast.ts\";\nimport { slice, slice_start } from \"./source.ts\";\nimport type {\n EffectBlock,\n LoweredExpression,\n LoweredStatement,\n ScriptLoweringContext,\n TempBinding,\n} from \"./types.ts\";\n\nimport ts from \"typescript\";\n\n/**\n * Delegates a statement to the correct lowerer based on syntax kind.\n *\n * @since 2.0.0\n * @param stmt - Statement to lower.\n * @param content - Original source text.\n * @param context - Lowering services for this transform pass.\n * @returns Lowered statement descriptor.\n */\nexport function lower_statement(\n stmt: ts.Statement,\n content: string,\n context: ScriptLoweringContext,\n): LoweredStatement {\n if (ts.isExpressionStatement(stmt)) {\n return lower_expression_statement(stmt, content, context);\n }\n\n if (ts.isVariableStatement(stmt)) {\n return lower_variable_statement(stmt, content, context);\n }\n\n const text = slice(content, stmt);\n\n return {\n temps: [],\n rewritten_text: \"\",\n effect_blocks: [make_effect_block([text], collect_deps(text))],\n range: { start: stmt.getFullStart(), end: stmt.end },\n };\n}\n\nfunction lower_variable_statement(\n stmt: ts.VariableStatement,\n content: string,\n context: ScriptLoweringContext,\n): LoweredStatement {\n const helper_declarations: string[] = [];\n const rewritten_decls: string[] = [];\n\n const decl_list = stmt.declarationList;\n const kind = (decl_list.flags & ts.NodeFlags.Let) !== 0 ? \"let\" : \"const\";\n let uses_dispatcher_promise = false;\n\n for (const decl of decl_list.declarations) {\n if (!contains_top_level_yield_star(decl)) {\n rewritten_decls.push(slice(content, decl).trim());\n continue;\n }\n\n const lowered = lower_node_yields_to_await(\n decl,\n content,\n make_binding_hint(decl.name),\n context,\n );\n\n helper_declarations.push(...lowered.helper_declarations);\n rewritten_decls.push(lowered.rewritten_text);\n uses_dispatcher_promise ||= lowered.uses_dispatcher_promise;\n }\n\n const rewritten_text = `${kind} ${rewritten_decls.join(\", \")};`;\n\n return {\n temps: [],\n type_helpers: helper_declarations,\n rewritten_text,\n effect_blocks: [],\n uses_dispatcher_promise,\n range: { start: stmt.getStart(), end: stmt.end },\n };\n}\n\nfunction lower_expression_statement(\n stmt: ts.ExpressionStatement,\n content: string,\n context: ScriptLoweringContext,\n): LoweredStatement {\n const expr = stmt.expression;\n\n if (!contains_top_level_yield_star(expr)) {\n return {\n temps: [],\n rewritten_text: slice(content, stmt).trim(),\n effect_blocks: [],\n range: { start: stmt.getStart(), end: stmt.end },\n };\n }\n\n if (is_yield_star_expression(expr)) {\n const text = slice(content, expr).trim();\n\n return {\n temps: [],\n rewritten_text: \"\",\n effect_blocks: [make_effect_block([text + \";\"], collect_deps(text))],\n range: { start: stmt.getFullStart(), end: stmt.end },\n };\n }\n\n if (ts.isBinaryExpression(expr) && is_assignment_operator(expr)) {\n const target = slice(content, expr.left).trim();\n const target_names = collect_assignment_target_names(expr.left);\n\n if (\n expr.operatorToken.kind === ts.SyntaxKind.EqualsToken &&\n is_yield_star_expression(expr.right)\n ) {\n const yield_text = extract_yield_star_full_text(expr.right, content);\n\n return {\n temps: [],\n rewritten_text: \"\",\n effect_blocks: [\n make_effect_block(\n [`${target} = ${yield_text};`],\n collect_deps(yield_text, target_names),\n ),\n ],\n range: { start: stmt.getStart(), end: stmt.end },\n };\n }\n\n const lowered = lower_expression_yields(\n expr.right,\n content,\n make_temp_hint(target),\n context,\n );\n const temp_names = lowered.temps.map((temp) => temp.name);\n const statement = `${target} ${\n slice(content, expr.operatorToken).trim()\n } ${lowered.rewritten_expr};`;\n\n return {\n temps: lowered.temps,\n type_helpers: lowered.type_helpers,\n rewritten_text: \"\",\n effect_blocks: [\n make_effect_block(\n [\n ...lowered.effect_blocks.flatMap((block) => block.statements),\n statement,\n ],\n [\n ...lowered.effect_blocks.flatMap((block) => block.deps),\n ...collect_deps(lowered.rewritten_expr, [\n ...target_names,\n ...temp_names,\n ]),\n ],\n ),\n ],\n range: { start: stmt.getStart(), end: stmt.end },\n };\n }\n\n const lowered = lower_expression_yields(\n expr,\n content,\n \"call\",\n context,\n );\n\n if (is_top_level_rune_call(expr)) {\n return {\n temps: lowered.temps,\n type_helpers: lowered.type_helpers,\n rewritten_text: lowered.rewritten_expr + \";\",\n effect_blocks: lowered.effect_blocks,\n range: { start: stmt.getStart(), end: stmt.end },\n };\n }\n\n const temp_names = lowered.temps.map((temp) => temp.name);\n\n return {\n temps: lowered.temps,\n type_helpers: lowered.type_helpers,\n rewritten_text: \"\",\n effect_blocks: [\n make_effect_block(\n [\n ...lowered.effect_blocks.flatMap((block) => block.statements),\n lowered.rewritten_expr + \";\",\n ],\n [\n ...lowered.effect_blocks.flatMap((block) => block.deps),\n ...collect_deps(lowered.rewritten_expr, temp_names),\n ],\n ),\n ],\n range: { start: stmt.getStart(), end: stmt.end },\n };\n}\n\nfunction lower_expression_yields(\n expr: ts.Expression,\n content: string,\n hint: string,\n context: ScriptLoweringContext,\n): LoweredExpression {\n const replacements: Array<{\n start: number;\n end: number;\n text: string;\n }> = [];\n\n const temps: TempBinding[] = [];\n const type_helpers: string[] = [];\n const statements: string[] = [];\n const deps: string[] = [];\n\n collect_yield_star_nodes(expr, (node) => {\n const temp_name = context.next_temp_name(hint);\n const yield_text = slice_start(content, node).trim();\n const type_helper = make_yield_type_helper(yield_text, hint, context);\n\n if (type_helper) {\n type_helpers.push(type_helper.declaration);\n temps.push({ name: temp_name, type: type_helper.type });\n } else {\n temps.push({ name: temp_name });\n }\n\n statements.push(`${temp_name} = ${yield_text};`);\n deps.push(...collect_deps(yield_text));\n replacements.push({\n start: node.getStart(),\n end: node.end,\n text: temp_name,\n });\n });\n\n if (replacements.length === 0) {\n return {\n temps,\n type_helpers,\n rewritten_expr: slice(content, expr).trim(),\n effect_blocks: [],\n };\n }\n\n replacements.sort((a, b) => b.start - a.start);\n\n let text = slice(content, expr);\n\n const offset_in_expr = expr.getFullStart();\n\n for (const replacement of replacements) {\n text = text.slice(0, replacement.start - offset_in_expr) +\n replacement.text +\n text.slice(replacement.end - offset_in_expr);\n }\n\n return {\n temps,\n type_helpers,\n rewritten_expr: text.trim(),\n effect_blocks: [make_effect_block(statements, deps)],\n };\n}\n\nfunction lower_node_yields_to_await(\n node: ts.Node,\n content: string,\n hint: string,\n context: ScriptLoweringContext,\n): {\n helper_declarations: string[];\n rewritten_text: string;\n uses_dispatcher_promise: boolean;\n} {\n const helper_declarations: string[] = [];\n const replacements: Array<{\n start: number;\n end: number;\n text: string;\n }> = [];\n\n collect_yield_star_nodes(node, (yield_node) => {\n const awaited = make_awaited_yield_expression(\n yield_node,\n content,\n hint,\n context,\n );\n\n helper_declarations.push(awaited.declaration);\n replacements.push({\n start: yield_node.getStart(),\n end: yield_node.end,\n text: awaited.expression,\n });\n });\n\n replacements.sort((a, b) => b.start - a.start);\n\n let text = slice_start(content, node);\n const offset_in_node = node.getStart();\n\n for (const replacement of replacements) {\n text = text.slice(0, replacement.start - offset_in_node) +\n replacement.text +\n text.slice(replacement.end - offset_in_node);\n }\n\n return {\n helper_declarations,\n rewritten_text: text.trim(),\n uses_dispatcher_promise: replacements.length > 0,\n };\n}\n\nfunction make_awaited_yield_expression(\n node: ts.Node,\n content: string,\n hint: string,\n context: ScriptLoweringContext,\n): { declaration: string; expression: string } {\n const yield_text = slice_start(content, node).trim();\n const helper_name = context.next_helper_name(`effect_${hint}`);\n const helper_id = make_script_effect_id(node, context);\n const deps = collect_deps(yield_text);\n const deps_text = `[${deps.join(\", \")}]`;\n\n return {\n declaration: `function* ${helper_name}() { return (${yield_text}); }`,\n expression: [\n `await ${context.dispatcher_name}().promise({`,\n `id: ${JSON.stringify(helper_id)}, `,\n `deps: ${deps_text}, `,\n `factory: () => ${helper_name}()`,\n `})`,\n ].join(\"\"),\n };\n}\n\nfunction make_yield_type_helper(\n yield_text: string,\n hint: string,\n context: ScriptLoweringContext,\n): { declaration: string; type: string } | undefined {\n if (!context.emit_types) {\n return undefined;\n }\n\n const helper_name = context.next_type_helper_name(hint);\n const effect_text = strip_yield_star(yield_text);\n\n return {\n declaration: `function ${helper_name}() { return (${effect_text}); }`,\n type:\n `${context.effect_name}.Success<ReturnType<typeof ${helper_name}>> | undefined`,\n };\n}\n\nfunction strip_yield_star(yield_text: string): string {\n return yield_text.replace(/^yield\\*\\s*/, \"\");\n}\n\nfunction make_script_effect_id(\n expr: ts.Node,\n context: ScriptLoweringContext,\n): string {\n return `${context.filename}:${expr.getStart()}:${expr.end}`;\n}\n\nfunction is_assignment_operator(expr: ts.BinaryExpression): boolean {\n return expr.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n expr.operatorToken.kind <= ts.SyntaxKind.LastAssignment;\n}\n\nfunction is_top_level_rune_call(expr: ts.Expression): boolean {\n if (!ts.isCallExpression(expr)) {\n return false;\n }\n\n const callee = expr.expression;\n\n if (ts.isIdentifier(callee)) {\n return callee.text.startsWith(\"$\");\n }\n\n return ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n callee.expression.text.startsWith(\"$\");\n}\n\nfunction make_temp_hint(target: string): string {\n const match = target.match(/[A-Za-z_$][\\w$]*$/);\n\n return match?.[0] ?? \"assignment\";\n}\n\nfunction make_binding_hint(name: ts.BindingName): string {\n if (ts.isIdentifier(name)) {\n return name.text;\n }\n\n return \"destructure\";\n}\n\nfunction extract_yield_star_full_text(\n expr: ts.Expression,\n content: string,\n): string {\n let found: string | undefined;\n\n find_yield_star_node(expr, (node) => {\n found = slice_start(content, node).trim();\n });\n\n return found ?? \"undefined\";\n}\n\nfunction make_effect_block(\n statements: string[],\n deps: string[],\n): EffectBlock {\n return {\n statements,\n deps: [...new Set(deps)],\n };\n}\n\nfunction collect_deps(\n expr_text: string,\n excluded_names: readonly string[] = [],\n): string[] {\n const excluded = new Set(excluded_names);\n\n return collect_free_identifiers(expr_text).filter(\n (identifier) =>\n !identifier.startsWith(\"__SER___\") && !excluded.has(identifier),\n );\n}\n\nfunction collect_assignment_target_names(node: ts.Node): string[] {\n if (ts.isIdentifier(node)) {\n return [node.text];\n }\n\n if (ts.isParenthesizedExpression(node)) {\n return collect_assignment_target_names(node.expression);\n }\n\n if (\n ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)\n ) {\n return collect_assignment_target_names(node.expression);\n }\n\n if (ts.isObjectLiteralExpression(node)) {\n return node.properties.flatMap((property) => {\n if (ts.isShorthandPropertyAssignment(property)) {\n return [property.name.text];\n }\n\n if (ts.isPropertyAssignment(property)) {\n return collect_assignment_target_names(property.initializer);\n }\n\n if (ts.isSpreadAssignment(property)) {\n return collect_assignment_target_names(property.expression);\n }\n\n return [];\n });\n }\n\n if (ts.isArrayLiteralExpression(node)) {\n return node.elements.flatMap((element) =>\n ts.isSpreadElement(element)\n ? collect_assignment_target_names(element.expression)\n : collect_assignment_target_names(element)\n );\n }\n\n return [];\n}\n","import { contains_top_level_yield_star } from \"$/detect.ts\";\nimport {\n collect_top_level_binding_names,\n has_local_import_binding,\n make_imports,\n} from \"./imports.ts\";\nimport { create_source_map, slice } from \"./source.ts\";\nimport { AwaitInEffectWorkError, PreprocessError } from \"$/errors.ts\";\nimport { make_runtime_block_with_bindings } from \"./runtime-block.ts\";\nimport { collect_yield_star_nodes, contains_top_level_await } from \"./ast.ts\";\nimport { lower_statement } from \"./lower.ts\";\nimport { validate_rune_yield_usage } from \"./runes.ts\";\nimport type {\n BlockRef,\n EffectBlock,\n Relocation,\n RuntimeImportBindings,\n ScriptLoweringContext,\n ScriptTransformResult,\n} from \"./types.ts\";\n\nimport MagicString from \"magic-string\";\nimport ts from \"typescript\";\n\nexport type { BlockRef, ScriptTransformResult } from \"./types.ts\";\n\ninterface ScriptTransformOptions {\n emit_types?: boolean;\n}\n\n/**\n * Transforms a `<script effect>` body by lowering top-level `yield*`\n * expressions into Svelte-compatible async rendering declarations or into\n * dependency-tracked `$effect` blocks for effectful statements.\n *\n * @example\n * ```ts\n * const result = transform_script_effect(\n * `let user = $state(yield* getUser(id));`,\n * \"App.svelte\",\n * );\n * ```\n *\n * @since 2.0.0\n * @param content - The raw `<script effect>` body content.\n * @param filename - The source filename, used in error messages.\n * @param options - Optional transform settings for generated script code.\n * @returns The transformed code and any block references.\n */\nexport function transform_script_effect(\n content: string,\n filename: string,\n options: ScriptTransformOptions = {},\n): ScriptTransformResult {\n let temp_counter = 0;\n\n const source_file = ts.createSourceFile(\n filename,\n content,\n ts.ScriptTarget.Latest,\n true,\n ts.ScriptKind.TS,\n );\n\n const magic = new MagicString(content);\n const effect_blocks: EffectBlock[] = [];\n const block_refs: BlockRef[] = [];\n const top_level_binding_names = collect_top_level_binding_names(source_file);\n const top_level_binding_names_set = new Set(top_level_binding_names);\n const name_allocator = make_name_allocator(top_level_binding_names);\n const emit_types = options.emit_types ?? true;\n\n let has_effect = false;\n let uses_dispatcher_promise = false;\n let uses_effect_types = false;\n\n /** Phase 1: detect imports already provided by the user. */\n const has_effect_import = has_local_import_binding(\n source_file,\n \"effect\",\n \"Effect\",\n );\n\n const has_dispatcher_import = has_local_import_binding(\n source_file,\n \"svelte-effect-runtime/internal/generators\",\n \"get_dispatcher\",\n );\n\n const has_untrack_import = has_local_import_binding(\n source_file,\n \"svelte\",\n \"untrack\",\n );\n\n const reserve_runtime_import = (name: string) =>\n top_level_binding_names_set.has(name)\n ? name_allocator.reserve(make_generated_name(name, \"\"))\n : name_allocator.reserve(name);\n\n const runtime_bindings: RuntimeImportBindings = {\n cancel: name_allocator.reserve(\"__SER___cancel\"),\n dispatcher: has_dispatcher_import\n ? \"get_dispatcher\"\n : reserve_runtime_import(\"get_dispatcher\"),\n dispatcher_value: name_allocator.reserve(\"__SER___dispatcher\"),\n effect: has_effect_import ? \"Effect\" : reserve_runtime_import(\"Effect\"),\n program: name_allocator.reserve(\"__SER___program\"),\n untrack: has_untrack_import ? \"untrack\" : reserve_runtime_import(\"untrack\"),\n };\n\n const context: ScriptLoweringContext = {\n filename,\n dispatcher_name: runtime_bindings.dispatcher,\n effect_name: runtime_bindings.effect,\n emit_types,\n next_helper_name(hint?: string) {\n return name_allocator.reserve(make_generated_name(hint ?? \"helper\", \"\"));\n },\n next_temp_name(hint?: string) {\n const suffix = temp_counter === 0 ? \"\" : `_${temp_counter}`;\n const name = make_generated_name(hint ?? String(temp_counter), suffix);\n\n temp_counter += 1;\n\n return name_allocator.reserve(name);\n },\n next_type_helper_name(hint?: string) {\n return name_allocator.reserve(\n make_generated_name(`type_${hint ?? \"effect\"}`, \"\"),\n );\n },\n };\n\n /** Phase 2: lower every top-level statement that contains `yield*`. */\n for (const stmt of source_file.statements) {\n validate_rune_yield_usage(stmt, content, filename);\n validate_script_yield_boundaries(stmt, content, filename);\n\n const has_top_level_yield_star = contains_top_level_yield_star(stmt);\n\n if (!has_top_level_yield_star) {\n continue;\n }\n\n has_effect = true;\n const lowered = lower_statement(stmt, content, context);\n\n if (lowered.effect_blocks.length > 0 && contains_top_level_await(stmt)) {\n const text = slice(content, stmt);\n throw new AwaitInEffectWorkError(filename, text);\n }\n\n magic.overwrite(\n lowered.range.start,\n lowered.range.end,\n lowered.rewritten_text,\n );\n\n if (lowered.temps.length > 0 || lowered.type_helpers?.length) {\n const temp_declarations = lowered.temps.map((temp) =>\n temp.type\n ? `let ${temp.name} = $state<${temp.type}>(undefined);`\n : `let ${temp.name} = $state(undefined);`\n );\n\n const prefix = [\n ...(lowered.type_helpers ?? []),\n ...temp_declarations,\n ].join(\"\\n\");\n\n magic.appendLeft(lowered.range.start, prefix + \"\\n\");\n }\n\n effect_blocks.push(...lowered.effect_blocks);\n uses_dispatcher_promise ||= lowered.uses_dispatcher_promise ?? false;\n uses_effect_types ||= lowered.temps.some((temp) =>\n temp.type?.includes(`${runtime_bindings.effect}.Success`) ?? false\n );\n }\n\n if (!has_effect) {\n block_refs.push({ id: filename, kind: \"script\" });\n\n return { code: content, blocks: block_refs };\n }\n\n /** Phase 3: inject runtime imports after the last user import. */\n const imports = make_imports(\n has_effect_import,\n has_dispatcher_import,\n has_untrack_import,\n runtime_bindings,\n {\n needs_dispatcher: effect_blocks.length > 0 || uses_dispatcher_promise,\n needs_effect: effect_blocks.length > 0 || uses_effect_types,\n needs_untrack: effect_blocks.length > 0,\n },\n );\n\n const last_import = [...source_file.statements]\n .reverse()\n .find(ts.isImportDeclaration);\n\n if (imports) {\n if (last_import) {\n magic.appendRight(last_import.end, \"\\n\" + imports);\n } else {\n magic.prepend(imports + \"\\n\");\n }\n }\n\n /** Phase 4: append the runtime program and lifecycle wiring. */\n if (effect_blocks.length > 0) {\n const runtime_block = make_runtime_block_with_bindings(\n effect_blocks,\n runtime_bindings,\n );\n\n magic.append(\"\\n\" + runtime_block);\n }\n\n block_refs.push({ id: filename, kind: \"script\" });\n\n const code = magic.toString();\n\n return {\n code,\n blocks: block_refs,\n map: create_source_map(magic, filename),\n relocations: create_script_relocations(content, code, source_file),\n };\n}\n\nfunction create_script_relocations(\n content: string,\n code: string,\n source_file: ts.SourceFile,\n): Relocation[] {\n const candidates = source_file.statements.flatMap((stmt) => {\n const relocations: RelocationCandidate[] = [];\n\n if (contains_top_level_yield_star(stmt) && ts.isVariableStatement(stmt)) {\n for (const decl of stmt.declarationList.declarations) {\n collect_binding_relocation_candidates(decl.name, relocations);\n }\n }\n\n collect_yield_star_nodes(stmt, (node) => {\n const text = content.slice(node.getStart(), node.end).trim();\n\n relocations.push({\n originalStart: node.getStart(),\n originalEnd: node.end,\n text,\n match: \"exact\",\n });\n });\n\n return relocations;\n });\n\n const used_ranges: Array<{ start: number; end: number }> = [];\n\n return candidates.flatMap((candidate) => {\n const generated_start = find_available_generated_text(\n code,\n candidate,\n used_ranges,\n );\n\n if (generated_start < 0) {\n return [];\n }\n\n const generated_end = generated_start + candidate.text.length;\n used_ranges.push({ start: generated_start, end: generated_end });\n\n return [{\n originalStart: candidate.originalStart,\n originalEnd: candidate.originalEnd,\n generatedStart: generated_start,\n generatedEnd: generated_end,\n }];\n });\n}\n\ntype RelocationCandidate = {\n originalStart: number;\n originalEnd: number;\n text: string;\n match: \"exact\" | \"identifier\";\n};\n\nfunction collect_binding_relocation_candidates(\n name: ts.BindingName,\n candidates: RelocationCandidate[],\n): void {\n if (ts.isIdentifier(name)) {\n candidates.push({\n originalStart: name.getStart(),\n originalEnd: name.end,\n text: name.text,\n match: \"identifier\",\n });\n\n return;\n }\n\n for (const element of name.elements) {\n if (ts.isOmittedExpression(element)) {\n continue;\n }\n\n collect_binding_relocation_candidates(element.name, candidates);\n }\n}\n\nfunction find_available_generated_text(\n code: string,\n candidate: RelocationCandidate,\n used_ranges: Array<{ start: number; end: number }>,\n): number {\n let search_start = 0;\n\n while (search_start < code.length) {\n const index = code.indexOf(candidate.text, search_start);\n\n if (index < 0) {\n return -1;\n }\n\n const end = index + candidate.text.length;\n const overlaps_used_range = used_ranges.some((range) =>\n index < range.end && end > range.start\n );\n const is_text_match = candidate.match === \"exact\" ||\n is_identifier_text_match(code, index, end);\n\n if (!overlaps_used_range && is_text_match) {\n return index;\n }\n\n search_start = candidate.match === \"identifier\" ? index + 1 : end;\n }\n\n return -1;\n}\n\nfunction is_identifier_text_match(\n code: string,\n start: number,\n end: number,\n): boolean {\n const before = start === 0 ? 0 : code.charCodeAt(start - 1);\n const after = end >= code.length ? 0 : code.charCodeAt(end);\n\n return !is_identifier_part(before) && !is_identifier_part(after);\n}\n\nfunction is_identifier_part(char_code: number): boolean {\n return (\n (char_code >= 65 && char_code <= 90) ||\n (char_code >= 97 && char_code <= 122) ||\n (char_code >= 48 && char_code <= 57) ||\n char_code === 36 ||\n char_code === 95\n );\n}\n\nfunction validate_script_yield_boundaries(\n stmt: ts.Statement,\n content: string,\n filename: string,\n): void {\n const bad_member = find_class_member_with_yield_star(stmt);\n\n if (!bad_member) {\n return;\n }\n\n throw new PreprocessError(\n [\n `[ASYNC_EFFECT_IN_CLASS_MEMBER]: ${filename}: yield* cannot be used inside class members.`,\n `Class fields and methods are not component top-level reactive work. Move the Effect work into a script effect statement before assigning it to the class instance.`,\n \"\",\n \"Problematic member:\",\n slice(content, bad_member),\n ].join(\"\\n\"),\n filename,\n );\n}\n\nfunction find_class_member_with_yield_star(\n stmt: ts.Statement,\n): ts.Node | undefined {\n let found: ts.Node | undefined;\n\n function visit(node: ts.Node): void {\n if (found) {\n return;\n }\n\n if (\n ts.isPropertyDeclaration(node) &&\n node.initializer &&\n contains_top_level_yield_star(node.initializer)\n ) {\n found = node;\n return;\n }\n\n node.forEachChild(visit);\n }\n\n visit(stmt);\n\n return found;\n}\n\nfunction make_name_allocator(initial_names: readonly string[]): {\n reserve(name: string): string;\n} {\n const used_names = new Set(initial_names);\n\n return {\n reserve(name: string): string {\n let candidate = name;\n let suffix = 1;\n\n while (used_names.has(candidate)) {\n candidate = `${name}_${suffix}`;\n suffix += 1;\n }\n\n used_names.add(candidate);\n\n return candidate;\n },\n };\n}\n\nfunction make_generated_name(hint: string, suffix: string): string {\n const normalized_hint = hint.replace(/[^A-Za-z0-9_$]/g, \"_\");\n const safe_hint = /^[A-Za-z_$]/.test(normalized_hint)\n ? normalized_hint\n : `temp_${normalized_hint}`;\n\n return `__SER___${safe_hint}${suffix}`;\n}\n","import {\n type MarkupTransformTarget,\n transform_markup_effect,\n} from \"$/markup/transform.ts\";\nimport { transform_script_effect } from \"$/script-transform/index.ts\";\n\n/**\n * Result returned by the direct whole-file Svelte transform.\n *\n * @example\n * ```ts\n * const result = transform_svelte_effect(\"<p>{yield* load()}</p>\", \"App.svelte\");\n * result.code;\n * ```\n *\n * @since 2.5.0\n */\nexport interface SvelteTransformResult {\n /** Transformed Svelte source. */\n code: string;\n}\n\n/**\n * Options accepted by the direct whole-file Svelte transform.\n *\n * @example\n * ```ts\n * const options: SvelteTransformOptions = { target: \"client\" };\n * ```\n *\n * @since 2.5.0\n */\nexport interface SvelteTransformOptions {\n /** Markup emission target passed through to the markup transform. */\n target?: MarkupTransformTarget;\n}\n\n/**\n * Lowers SER syntax in a complete Svelte component without using Svelte's\n * adapter API.\n *\n * @example\n * ```ts\n * const result = transform_svelte_effect(\n * \"<script effect>const value = yield* load()</script>\",\n * \"App.svelte\",\n * );\n * ```\n *\n * @since 2.5.0\n * @param content - Full Svelte component source to lower before Svelte parses\n * it.\n * @param filename - Component filename used in generated cache identifiers and\n * diagnostics.\n * @param options - Optional target configuration for markup lowering.\n * @returns The transformed component source.\n */\nexport function transform_svelte_effect(\n content: string,\n filename = \"unknown.svelte\",\n options: SvelteTransformOptions = {},\n): SvelteTransformResult {\n const script = find_script(content);\n\n let combined = content;\n\n if (script?.has_effect) {\n const result = transform_script_effect(script.text, filename, {\n emit_types: script.is_typescript,\n });\n\n combined = content.slice(0, script.effect_attr_start) +\n content.slice(script.effect_attr_end, script.open_end) +\n result.code +\n content.slice(script.close_start);\n }\n\n const result = transform_markup_effect(combined, filename, {\n target: options.target,\n });\n\n return { code: result.code };\n}\n\nfunction find_script(content: string):\n | {\n text: string;\n open_end: number;\n close_start: number;\n has_effect: boolean;\n effect_attr_start: number;\n effect_attr_end: number;\n is_typescript: boolean;\n }\n | undefined {\n const pattern = /<script\\b([^>]*)>([\\s\\S]*?)<\\/script\\s*>/gi;\n\n for (const match of content.matchAll(pattern)) {\n if (match.index === undefined || /\\bmodule\\b/.test(match[1] ?? \"\")) {\n continue;\n }\n\n const attrs = match[1] ?? \"\";\n const effect_match = /\\s+effect(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+))?/\n .exec(attrs);\n const open_end = match.index + match[0].indexOf(\">\") + 1;\n const attr_start = effect_match?.index ?? attrs.length;\n const attr_end = attr_start + (effect_match?.[0].length ?? 0);\n\n return {\n text: match[2],\n open_end,\n close_start: match.index + match[0].lastIndexOf(\"<\"),\n has_effect: effect_match !== null,\n effect_attr_start: match.index + \"<script\".length + attr_start,\n effect_attr_end: match.index + \"<script\".length + attr_end,\n is_typescript: has_typescript_lang(attrs),\n };\n }\n\n return undefined;\n}\n\nfunction has_typescript_lang(attrs: string): boolean {\n const lang_match = /\\blang\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s>]+))/i.exec(\n attrs,\n );\n const lang = (lang_match?.[1] ?? lang_match?.[2] ?? lang_match?.[3] ?? \"\")\n .toLowerCase();\n\n return lang === \"ts\" || lang === \"typescript\";\n}\n\nexport {\n type MarkupTransformOptions,\n type MarkupTransformResult,\n type MarkupTransformTarget,\n transform_markup_effect,\n} from \"$/markup/transform.ts\";\n\nexport {\n type BlockRef,\n type ScriptTransformResult,\n transform_script_effect,\n} from \"$/script-transform/index.ts\";\n"],"mappings":";;;;;;;;;;;;;;;AA+BA,SAAgB,iCACd,QACA,UACQ;CACR,MAAM,eAAe,oBAAoB,MAAM;CAC/C,MAAM,YAAY,aAAa,KAAK,KAAK,QAAQ,KAAK,IAAI,EAAE;CAE5D,MAAM,OAAO,aAAa,WACvB,KAAK,cAAc,OAAO,WAAW,EACrC,KAAK,IAAI;CAEZ,OAAO;EACL;EACA;EACA,GAAG;EACH,WAAW,SAAS,iBAAiB,KAAK,SAAS,WAAW;EAC9D,WAAW,S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iB;GAC7B,mBAAmB,MAAM,QAAQ,IAAmB;GACpD,iBAAiB,MAAM,QAAQ,IAAmB;GAClD,eAAe,oBAAoB,KAAK;EAC1C;CACF;AAGF;AAEA,SAAS,oBAAoB,OAAwB;CACnD,MAAM,aAAa,kDAAkD,KACnE,KACF;CACA,MAAM,QAAQ,aAAa,MAAM,aAAa,MAAM,aAAa,MAAM,IACpE,YAAY;CAEf,OAAO,SAAS,QAAQ,SAAS;AACnC"}
|
|
1
|
+
{"version":3,"file":"transform.js","names":[],"sources":["../../../modules/svelte-effect-runtime/src/script-transform/runtime-block.ts","../../../modules/svelte-effect-runtime/src/script-transform/lower.ts","../../../modules/svelte-effect-runtime/src/script-transform/index.ts","../../../modules/svelte-effect-runtime/src/runtime/transform.ts"],"sourcesContent":["import type { EffectBlock, RuntimeImportBindings } from \"./types.ts\";\n\n/**\n * Builds the runtime blocks appended to lowered script effect code.\n *\n * @since 2.0.0\n * @param blocks - Effect bodies and dependency reads to emit.\n * @returns Full `$effect` blocks that fork generated `Effect.gen` programs.\n */\nexport function make_runtime_block(blocks: EffectBlock[]): string {\n\tconst bindings: RuntimeImportBindings = {\n\t\tcancel: \"__SER___cancel\",\n\t\tdispatcher: \"get_dispatcher\",\n\t\tdispatcher_value: \"__SER___dispatcher\",\n\t\teffect: \"Effect\",\n\t\tprogram: \"__SER___program\",\n\t\tuntrack: \"untrack\",\n\t};\n\n\treturn make_runtime_block_with_bindings(blocks, bindings);\n}\n\n/**\n * Builds the runtime blocks appended to lowered script effect code with\n * explicit runtime import bindings.\n *\n * @since 2.4.2\n * @param blocks - Effect bodies and dependency reads to emit.\n * @param bindings - Runtime binding names available in the generated code.\n * @returns Full `$effect` blocks that fork generated `Effect.gen` programs.\n */\nexport function make_runtime_block_with_bindings(\n\tblocks: EffectBlock[],\n\tbindings: RuntimeImportBindings,\n): string {\n\tconst merged_block = merge_effect_blocks(blocks);\n\tconst dep_reads = merged_block.deps.map((dep) => ` ${dep};`);\n\n\tconst body = merged_block.statements.map((statement) => ` ${statement}`).join(\"\\n\");\n\n\treturn [\n\t\t\"\",\n\t\t\"$effect(() => {\",\n\t\t...dep_reads,\n\t\t` const ${bindings.dispatcher_value} = ${bindings.dispatcher}();`,\n\t\t` const ${bindings.program} = ${bindings.effect}.gen(function* () {`,\n\t\tbody,\n\t\t\" });\",\n\t\t` const ${bindings.cancel} = ${bindings.untrack}(() => ${bindings.dispatcher_value}.fork(${bindings.program}));`,\n\t\t` import.meta.hot?.dispose(${bindings.cancel});`,\n\t\t` return ${bindings.cancel};`,\n\t\t\"});\",\n\t\t\"\",\n\t].join(\"\\n\");\n}\n\nfunction merge_effect_blocks(blocks: EffectBlock[]): EffectBlock {\n\tconst statements = blocks.flatMap((block) => block.statements);\n\tconst deps = blocks.flatMap((block) => block.deps);\n\n\treturn {\n\t\tstatements,\n\t\tdeps: [...new Set(deps)],\n\t};\n}\n","import { collect_free_identifiers } from \"$/markup/transform/expressions.ts\";\nimport { contains_top_level_yield_star } from \"$/detect.ts\";\nimport { collect_yield_star_nodes, find_yield_star_node, is_yield_star_expression } from \"./ast.ts\";\nimport { slice, slice_start } from \"./source.ts\";\nimport type {\n\tEffectBlock,\n\tLoweredExpression,\n\tLoweredStatement,\n\tScriptLoweringContext,\n\tTempBinding,\n} from \"./types.ts\";\n\nimport ts from \"typescript\";\n\n/**\n * Delegates a statement to the correct lowerer based on syntax kind.\n *\n * @since 2.0.0\n * @param stmt - Statement to lower.\n * @param content - Original source text.\n * @param context - Lowering services for this transform pass.\n * @returns Lowered statement descriptor.\n */\nexport function lower_statement(\n\tstmt: ts.Statement,\n\tcontent: string,\n\tcontext: ScriptLoweringContext,\n): LoweredStatement {\n\tif (ts.isExpressionStatement(stmt)) {\n\t\treturn lower_expression_statement(stmt, content, context);\n\t}\n\n\tif (ts.isVariableStatement(stmt)) {\n\t\treturn lower_variable_statement(stmt, content, context);\n\t}\n\n\tconst text = slice(content, stmt);\n\n\treturn {\n\t\ttemps: [],\n\t\trewritten_text: \"\",\n\t\teffect_blocks: [make_effect_block([text], collect_deps(text))],\n\t\trange: { start: stmt.getFullStart(), end: stmt.end },\n\t};\n}\n\nfunction lower_variable_statement(\n\tstmt: ts.VariableStatement,\n\tcontent: string,\n\tcontext: ScriptLoweringContext,\n): LoweredStatement {\n\tconst helper_declarations: string[] = [];\n\tconst rewritten_decls: string[] = [];\n\n\tconst decl_list = stmt.declarationList;\n\tconst kind = (decl_list.flags & ts.NodeFlags.Let) !== 0 ? \"let\" : \"const\";\n\tlet uses_dispatcher_promise = false;\n\n\tfor (const decl of decl_list.declarations) {\n\t\tif (!contains_top_level_yield_star(decl)) {\n\t\t\trewritten_decls.push(slice(content, decl).trim());\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst lowered = lower_node_yields_to_await(\n\t\t\tdecl,\n\t\t\tcontent,\n\t\t\tmake_binding_hint(decl.name),\n\t\t\tcontext,\n\t\t);\n\n\t\thelper_declarations.push(...lowered.helper_declarations);\n\t\trewritten_decls.push(lowered.rewritten_text);\n\t\tuses_dispatcher_promise ||= lowered.uses_dispatcher_promise;\n\t}\n\n\tconst rewritten_text = `${kind} ${rewritten_decls.join(\", \")};`;\n\n\treturn {\n\t\ttemps: [],\n\t\ttype_helpers: helper_declarations,\n\t\trewritten_text,\n\t\teffect_blocks: [],\n\t\tuses_dispatcher_promise,\n\t\trange: { start: stmt.getStart(), end: stmt.end },\n\t};\n}\n\nfunction lower_expression_statement(\n\tstmt: ts.ExpressionStatement,\n\tcontent: string,\n\tcontext: ScriptLoweringContext,\n): LoweredStatement {\n\tconst expr = stmt.expression;\n\n\tif (!contains_top_level_yield_star(expr)) {\n\t\treturn {\n\t\t\ttemps: [],\n\t\t\trewritten_text: slice(content, stmt).trim(),\n\t\t\teffect_blocks: [],\n\t\t\trange: { start: stmt.getStart(), end: stmt.end },\n\t\t};\n\t}\n\n\tif (is_yield_star_expression(expr)) {\n\t\tconst text = slice(content, expr).trim();\n\n\t\treturn {\n\t\t\ttemps: [],\n\t\t\trewritten_text: \"\",\n\t\t\teffect_blocks: [make_effect_block([text + \";\"], collect_deps(text))],\n\t\t\trange: { start: stmt.getFullStart(), end: stmt.end },\n\t\t};\n\t}\n\n\tif (ts.isBinaryExpression(expr) && is_assignment_operator(expr)) {\n\t\tconst target = slice(content, expr.left).trim();\n\t\tconst target_names = collect_assignment_target_names(expr.left);\n\n\t\tif (\n\t\t\texpr.operatorToken.kind === ts.SyntaxKind.EqualsToken &&\n\t\t\tis_yield_star_expression(expr.right)\n\t\t) {\n\t\t\tconst yield_text = extract_yield_star_full_text(expr.right, content);\n\n\t\t\treturn {\n\t\t\t\ttemps: [],\n\t\t\t\trewritten_text: \"\",\n\t\t\t\teffect_blocks: [\n\t\t\t\t\tmake_effect_block(\n\t\t\t\t\t\t[`${target} = ${yield_text};`],\n\t\t\t\t\t\tcollect_deps(yield_text, target_names),\n\t\t\t\t\t),\n\t\t\t\t],\n\t\t\t\trange: { start: stmt.getStart(), end: stmt.end },\n\t\t\t};\n\t\t}\n\n\t\tconst lowered = lower_expression_yields(\n\t\t\texpr.right,\n\t\t\tcontent,\n\t\t\tmake_temp_hint(target),\n\t\t\tcontext,\n\t\t);\n\t\tconst temp_names = lowered.temps.map((temp) => temp.name);\n\t\tconst statement = `${target} ${slice(\n\t\t\tcontent,\n\t\t\texpr.operatorToken,\n\t\t).trim()} ${lowered.rewritten_expr};`;\n\n\t\treturn {\n\t\t\ttemps: lowered.temps,\n\t\t\ttype_helpers: lowered.type_helpers,\n\t\t\trewritten_text: \"\",\n\t\t\teffect_blocks: [\n\t\t\t\tmake_effect_block(\n\t\t\t\t\t[...lowered.effect_blocks.flatMap((block) => block.statements), statement],\n\t\t\t\t\t[\n\t\t\t\t\t\t...lowered.effect_blocks.flatMap((block) => block.deps),\n\t\t\t\t\t\t...collect_deps(lowered.rewritten_expr, [...target_names, ...temp_names]),\n\t\t\t\t\t],\n\t\t\t\t),\n\t\t\t],\n\t\t\trange: { start: stmt.getStart(), end: stmt.end },\n\t\t};\n\t}\n\n\tconst lowered = lower_expression_yields(expr, content, \"call\", context);\n\n\tif (is_top_level_rune_call(expr)) {\n\t\treturn {\n\t\t\ttemps: lowered.temps,\n\t\t\ttype_helpers: lowered.type_helpers,\n\t\t\trewritten_text: lowered.rewritten_expr + \";\",\n\t\t\teffect_blocks: lowered.effect_blocks,\n\t\t\trange: { start: stmt.getStart(), end: stmt.end },\n\t\t};\n\t}\n\n\tconst temp_names = lowered.temps.map((temp) => temp.name);\n\n\treturn {\n\t\ttemps: lowered.temps,\n\t\ttype_helpers: lowered.type_helpers,\n\t\trewritten_text: \"\",\n\t\teffect_blocks: [\n\t\t\tmake_effect_block(\n\t\t\t\t[\n\t\t\t\t\t...lowered.effect_blocks.flatMap((block) => block.statements),\n\t\t\t\t\tlowered.rewritten_expr + \";\",\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\t...lowered.effect_blocks.flatMap((block) => block.deps),\n\t\t\t\t\t...collect_deps(lowered.rewritten_expr, temp_names),\n\t\t\t\t],\n\t\t\t),\n\t\t],\n\t\trange: { start: stmt.getStart(), end: stmt.end },\n\t};\n}\n\nfunction lower_expression_yields(\n\texpr: ts.Expression,\n\tcontent: string,\n\thint: string,\n\tcontext: ScriptLoweringContext,\n): LoweredExpression {\n\tconst replacements: Array<{\n\t\tstart: number;\n\t\tend: number;\n\t\ttext: string;\n\t}> = [];\n\n\tconst temps: TempBinding[] = [];\n\tconst type_helpers: string[] = [];\n\tconst statements: string[] = [];\n\tconst deps: string[] = [];\n\n\tcollect_yield_star_nodes(expr, (node) => {\n\t\tconst temp_name = context.next_temp_name(hint);\n\t\tconst yield_text = slice_start(content, node).trim();\n\t\tconst type_helper = make_yield_type_helper(yield_text, hint, context);\n\n\t\tif (type_helper) {\n\t\t\ttype_helpers.push(type_helper.declaration);\n\t\t\ttemps.push({ name: temp_name, type: type_helper.type });\n\t\t} else {\n\t\t\ttemps.push({ name: temp_name });\n\t\t}\n\n\t\tstatements.push(`${temp_name} = ${yield_text};`);\n\t\tdeps.push(...collect_deps(yield_text));\n\t\treplacements.push({\n\t\t\tstart: node.getStart(),\n\t\t\tend: node.end,\n\t\t\ttext: temp_name,\n\t\t});\n\t});\n\n\tif (replacements.length === 0) {\n\t\treturn {\n\t\t\ttemps,\n\t\t\ttype_helpers,\n\t\t\trewritten_expr: slice(content, expr).trim(),\n\t\t\teffect_blocks: [],\n\t\t};\n\t}\n\n\treplacements.sort((a, b) => b.start - a.start);\n\n\tlet text = slice(content, expr);\n\n\tconst offset_in_expr = expr.getFullStart();\n\n\tfor (const replacement of replacements) {\n\t\ttext =\n\t\t\ttext.slice(0, replacement.start - offset_in_expr) +\n\t\t\treplacement.text +\n\t\t\ttext.slice(replacement.end - offset_in_expr);\n\t}\n\n\treturn {\n\t\ttemps,\n\t\ttype_helpers,\n\t\trewritten_expr: text.trim(),\n\t\teffect_blocks: [make_effect_block(statements, deps)],\n\t};\n}\n\nfunction lower_node_yields_to_await(\n\tnode: ts.Node,\n\tcontent: string,\n\thint: string,\n\tcontext: ScriptLoweringContext,\n): {\n\thelper_declarations: string[];\n\trewritten_text: string;\n\tuses_dispatcher_promise: boolean;\n} {\n\tconst helper_declarations: string[] = [];\n\tconst replacements: Array<{\n\t\tstart: number;\n\t\tend: number;\n\t\ttext: string;\n\t}> = [];\n\n\tcollect_yield_star_nodes(node, (yield_node) => {\n\t\tconst awaited = make_awaited_yield_expression(yield_node, content, hint, context);\n\n\t\thelper_declarations.push(awaited.declaration);\n\t\treplacements.push({\n\t\t\tstart: yield_node.getStart(),\n\t\t\tend: yield_node.end,\n\t\t\ttext: awaited.expression,\n\t\t});\n\t});\n\n\treplacements.sort((a, b) => b.start - a.start);\n\n\tlet text = slice_start(content, node);\n\tconst offset_in_node = node.getStart();\n\n\tfor (const replacement of replacements) {\n\t\ttext =\n\t\t\ttext.slice(0, replacement.start - offset_in_node) +\n\t\t\treplacement.text +\n\t\t\ttext.slice(replacement.end - offset_in_node);\n\t}\n\n\treturn {\n\t\thelper_declarations,\n\t\trewritten_text: text.trim(),\n\t\tuses_dispatcher_promise: replacements.length > 0,\n\t};\n}\n\nfunction make_awaited_yield_expression(\n\tnode: ts.Node,\n\tcontent: string,\n\thint: string,\n\tcontext: ScriptLoweringContext,\n): { declaration: string; expression: string } {\n\tconst yield_text = slice_start(content, node).trim();\n\tconst helper_name = context.next_helper_name(`effect_${hint}`);\n\tconst helper_id = make_script_effect_id(node, context);\n\tconst deps = collect_deps(yield_text);\n\tconst deps_text = `[${deps.join(\", \")}]`;\n\n\treturn {\n\t\tdeclaration: `function* ${helper_name}() { return (${yield_text}); }`,\n\t\texpression: [\n\t\t\t`await ${context.dispatcher_name}().promise({`,\n\t\t\t`id: ${JSON.stringify(helper_id)}, `,\n\t\t\t`deps: ${deps_text}, `,\n\t\t\t`factory: () => ${helper_name}()`,\n\t\t\t`})`,\n\t\t].join(\"\"),\n\t};\n}\n\nfunction make_yield_type_helper(\n\tyield_text: string,\n\thint: string,\n\tcontext: ScriptLoweringContext,\n): { declaration: string; type: string } | undefined {\n\tif (!context.emit_types) {\n\t\treturn undefined;\n\t}\n\n\tconst helper_name = context.next_type_helper_name(hint);\n\tconst effect_text = strip_yield_star(yield_text);\n\n\treturn {\n\t\tdeclaration: `function ${helper_name}() { return (${effect_text}); }`,\n\t\ttype: `${context.effect_name}.Success<ReturnType<typeof ${helper_name}>> | undefined`,\n\t};\n}\n\nfunction strip_yield_star(yield_text: string): string {\n\treturn yield_text.replace(/^yield\\*\\s*/, \"\");\n}\n\nfunction make_script_effect_id(expr: ts.Node, context: ScriptLoweringContext): string {\n\treturn `${context.filename}:${expr.getStart()}:${expr.end}`;\n}\n\nfunction is_assignment_operator(expr: ts.BinaryExpression): boolean {\n\treturn (\n\t\texpr.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&\n\t\texpr.operatorToken.kind <= ts.SyntaxKind.LastAssignment\n\t);\n}\n\nfunction is_top_level_rune_call(expr: ts.Expression): boolean {\n\tif (!ts.isCallExpression(expr)) {\n\t\treturn false;\n\t}\n\n\tconst callee = expr.expression;\n\n\tif (ts.isIdentifier(callee)) {\n\t\treturn callee.text.startsWith(\"$\");\n\t}\n\n\treturn (\n\t\tts.isPropertyAccessExpression(callee) &&\n\t\tts.isIdentifier(callee.expression) &&\n\t\tcallee.expression.text.startsWith(\"$\")\n\t);\n}\n\nfunction make_temp_hint(target: string): string {\n\tconst match = target.match(/[A-Za-z_$][\\w$]*$/);\n\n\treturn match?.[0] ?? \"assignment\";\n}\n\nfunction make_binding_hint(name: ts.BindingName): string {\n\tif (ts.isIdentifier(name)) {\n\t\treturn name.text;\n\t}\n\n\treturn \"destructure\";\n}\n\nfunction extract_yield_star_full_text(expr: ts.Expression, content: string): string {\n\tlet found: string | undefined;\n\n\tfind_yield_star_node(expr, (node) => {\n\t\tfound = slice_start(content, node).trim();\n\t});\n\n\treturn found ?? \"undefined\";\n}\n\nfunction make_effect_block(statements: string[], deps: string[]): EffectBlock {\n\treturn {\n\t\tstatements,\n\t\tdeps: [...new Set(deps)],\n\t};\n}\n\nfunction collect_deps(expr_text: string, excluded_names: readonly string[] = []): string[] {\n\tconst excluded = new Set(excluded_names);\n\n\treturn collect_free_identifiers(expr_text).filter(\n\t\t(identifier) => !identifier.startsWith(\"__SER___\") && !excluded.has(identifier),\n\t);\n}\n\nfunction collect_assignment_target_names(node: ts.Node): string[] {\n\tif (ts.isIdentifier(node)) {\n\t\treturn [node.text];\n\t}\n\n\tif (ts.isParenthesizedExpression(node)) {\n\t\treturn collect_assignment_target_names(node.expression);\n\t}\n\n\tif (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) {\n\t\treturn collect_assignment_target_names(node.expression);\n\t}\n\n\tif (ts.isObjectLiteralExpression(node)) {\n\t\treturn node.properties.flatMap((property) => {\n\t\t\tif (ts.isShorthandPropertyAssignment(property)) {\n\t\t\t\treturn [property.name.text];\n\t\t\t}\n\n\t\t\tif (ts.isPropertyAssignment(property)) {\n\t\t\t\treturn collect_assignment_target_names(property.initializer);\n\t\t\t}\n\n\t\t\tif (ts.isSpreadAssignment(property)) {\n\t\t\t\treturn collect_assignment_target_names(property.expression);\n\t\t\t}\n\n\t\t\treturn [];\n\t\t});\n\t}\n\n\tif (ts.isArrayLiteralExpression(node)) {\n\t\treturn node.elements.flatMap((element) =>\n\t\t\tts.isSpreadElement(element)\n\t\t\t\t? collect_assignment_target_names(element.expression)\n\t\t\t\t: collect_assignment_target_names(element),\n\t\t);\n\t}\n\n\treturn [];\n}\n","import { contains_top_level_yield_star } from \"$/detect.ts\";\nimport {\n\tcollect_top_level_binding_names,\n\thas_local_import_binding,\n\tmake_imports,\n} from \"./imports.ts\";\nimport { create_source_map, slice } from \"./source.ts\";\nimport { AwaitInEffectWorkError, PreprocessError } from \"$/errors.ts\";\nimport { make_runtime_block_with_bindings } from \"./runtime-block.ts\";\nimport { collect_yield_star_nodes, contains_top_level_await } from \"./ast.ts\";\nimport { lower_statement } from \"./lower.ts\";\nimport { validate_rune_yield_usage } from \"./runes.ts\";\nimport type {\n\tBlockRef,\n\tEffectBlock,\n\tRelocation,\n\tRuntimeImportBindings,\n\tScriptLoweringContext,\n\tScriptTransformResult,\n} from \"./types.ts\";\n\nimport MagicString from \"magic-string\";\nimport ts from \"typescript\";\n\nexport type { BlockRef, ScriptTransformResult } from \"./types.ts\";\n\ninterface ScriptTransformOptions {\n\temit_types?: boolean;\n}\n\n/**\n * Transforms a `<script effect>` body by lowering top-level `yield*`\n * expressions into Svelte-compatible async rendering declarations or into\n * dependency-tracked `$effect` blocks for effectful statements.\n *\n * @example\n * ```ts\n * const result = transform_script_effect(\n * `let user = $state(yield* getUser(id));`,\n * \"App.svelte\",\n * );\n * ```\n *\n * @since 2.0.0\n * @param content - The raw `<script effect>` body content.\n * @param filename - The source filename, used in error messages.\n * @param options - Optional transform settings for generated script code.\n * @returns The transformed code and any block references.\n */\nexport function transform_script_effect(\n\tcontent: string,\n\tfilename: string,\n\toptions: ScriptTransformOptions = {},\n): ScriptTransformResult {\n\tlet temp_counter = 0;\n\n\tconst source_file = ts.createSourceFile(\n\t\tfilename,\n\t\tcontent,\n\t\tts.ScriptTarget.Latest,\n\t\ttrue,\n\t\tts.ScriptKind.TS,\n\t);\n\n\tconst magic = new MagicString(content);\n\tconst effect_blocks: EffectBlock[] = [];\n\tconst block_refs: BlockRef[] = [];\n\tconst top_level_binding_names = collect_top_level_binding_names(source_file);\n\tconst top_level_binding_names_set = new Set(top_level_binding_names);\n\tconst name_allocator = make_name_allocator(top_level_binding_names);\n\tconst emit_types = options.emit_types ?? true;\n\n\tlet has_effect = false;\n\tlet uses_dispatcher_promise = false;\n\tlet uses_effect_types = false;\n\n\t/** Phase 1: detect imports already provided by the user. */\n\tconst has_effect_import = has_local_import_binding(source_file, \"effect\", \"Effect\");\n\n\tconst has_dispatcher_import = has_local_import_binding(\n\t\tsource_file,\n\t\t\"svelte-effect-runtime/internal/generators\",\n\t\t\"get_dispatcher\",\n\t);\n\n\tconst has_untrack_import = has_local_import_binding(source_file, \"svelte\", \"untrack\");\n\n\tconst reserve_runtime_import = (name: string) =>\n\t\ttop_level_binding_names_set.has(name)\n\t\t\t? name_allocator.reserve(make_generated_name(name, \"\"))\n\t\t\t: name_allocator.reserve(name);\n\n\tconst runtime_bindings: RuntimeImportBindings = {\n\t\tcancel: name_allocator.reserve(\"__SER___cancel\"),\n\t\tdispatcher: has_dispatcher_import\n\t\t\t? \"get_dispatcher\"\n\t\t\t: reserve_runtime_import(\"get_dispatcher\"),\n\t\tdispatcher_value: name_allocator.reserve(\"__SER___dispatcher\"),\n\t\teffect: has_effect_import ? \"Effect\" : reserve_runtime_import(\"Effect\"),\n\t\tprogram: name_allocator.reserve(\"__SER___program\"),\n\t\tuntrack: has_untrack_import ? \"untrack\" : reserve_runtime_import(\"untrack\"),\n\t};\n\n\tconst context: ScriptLoweringContext = {\n\t\tfilename,\n\t\tdispatcher_name: runtime_bindings.dispatcher,\n\t\teffect_name: runtime_bindings.effect,\n\t\temit_types,\n\t\tnext_helper_name(hint?: string) {\n\t\t\treturn name_allocator.reserve(make_generated_name(hint ?? \"helper\", \"\"));\n\t\t},\n\t\tnext_temp_name(hint?: string) {\n\t\t\tconst suffix = temp_counter === 0 ? \"\" : `_${temp_counter}`;\n\t\t\tconst name = make_generated_name(hint ?? String(temp_counter), suffix);\n\n\t\t\ttemp_counter += 1;\n\n\t\t\treturn name_allocator.reserve(name);\n\t\t},\n\t\tnext_type_helper_name(hint?: string) {\n\t\t\treturn name_allocator.reserve(make_generated_name(`type_${hint ?? \"effect\"}`, \"\"));\n\t\t},\n\t};\n\n\t/** Phase 2: lower every top-level statement that contains `yield*`. */\n\tfor (const stmt of source_file.statements) {\n\t\tvalidate_rune_yield_usage(stmt, content, filename);\n\t\tvalidate_script_yield_boundaries(stmt, content, filename);\n\n\t\tconst has_top_level_yield_star = contains_top_level_yield_star(stmt);\n\n\t\tif (!has_top_level_yield_star) {\n\t\t\tcontinue;\n\t\t}\n\n\t\thas_effect = true;\n\t\tconst lowered = lower_statement(stmt, content, context);\n\n\t\tif (lowered.effect_blocks.length > 0 && contains_top_level_await(stmt)) {\n\t\t\tconst text = slice(content, stmt);\n\t\t\tthrow new AwaitInEffectWorkError(filename, text);\n\t\t}\n\n\t\tmagic.overwrite(lowered.range.start, lowered.range.end, lowered.rewritten_text);\n\n\t\tif (lowered.temps.length > 0 || lowered.type_helpers?.length) {\n\t\t\tconst temp_declarations = lowered.temps.map((temp) =>\n\t\t\t\ttemp.type\n\t\t\t\t\t? `let ${temp.name} = $state<${temp.type}>(undefined);`\n\t\t\t\t\t: `let ${temp.name} = $state(undefined);`,\n\t\t\t);\n\n\t\t\tconst prefix = [...(lowered.type_helpers ?? []), ...temp_declarations].join(\"\\n\");\n\n\t\t\tmagic.appendLeft(lowered.range.start, prefix + \"\\n\");\n\t\t}\n\n\t\teffect_blocks.push(...lowered.effect_blocks);\n\t\tuses_dispatcher_promise ||= lowered.uses_dispatcher_promise ?? false;\n\t\tuses_effect_types ||= lowered.temps.some(\n\t\t\t(temp) => temp.type?.includes(`${runtime_bindings.effect}.Success`) ?? false,\n\t\t);\n\t}\n\n\tif (!has_effect) {\n\t\tblock_refs.push({ id: filename, kind: \"script\" });\n\n\t\treturn { code: content, blocks: block_refs };\n\t}\n\n\t/** Phase 3: inject runtime imports after the last user import. */\n\tconst imports = make_imports(\n\t\thas_effect_import,\n\t\thas_dispatcher_import,\n\t\thas_untrack_import,\n\t\truntime_bindings,\n\t\t{\n\t\t\tneeds_dispatcher: effect_blocks.length > 0 || uses_dispatcher_promise,\n\t\t\tneeds_effect: effect_blocks.length > 0 || uses_effect_types,\n\t\t\tneeds_untrack: effect_blocks.length > 0,\n\t\t},\n\t);\n\n\tconst last_import = [...source_file.statements].reverse().find(ts.isImportDeclaration);\n\n\tif (imports) {\n\t\tif (last_import) {\n\t\t\tmagic.appendRight(last_import.end, \"\\n\" + imports);\n\t\t} else {\n\t\t\tmagic.prepend(imports + \"\\n\");\n\t\t}\n\t}\n\n\t/** Phase 4: append the runtime program and lifecycle wiring. */\n\tif (effect_blocks.length > 0) {\n\t\tconst runtime_block = make_runtime_block_with_bindings(effect_blocks, runtime_bindings);\n\n\t\tmagic.append(\"\\n\" + runtime_block);\n\t}\n\n\tblock_refs.push({ id: filename, kind: \"script\" });\n\n\tconst code = magic.toString();\n\n\treturn {\n\t\tcode,\n\t\tblocks: block_refs,\n\t\tmap: create_source_map(magic, filename),\n\t\trelocations: create_script_relocations(content, code, source_file),\n\t};\n}\n\nfunction create_script_relocations(\n\tcontent: string,\n\tcode: string,\n\tsource_file: ts.SourceFile,\n): Relocation[] {\n\tconst candidates = source_file.statements.flatMap((stmt) => {\n\t\tconst relocations: RelocationCandidate[] = [];\n\n\t\tif (contains_top_level_yield_star(stmt) && ts.isVariableStatement(stmt)) {\n\t\t\tfor (const decl of stmt.declarationList.declarations) {\n\t\t\t\tcollect_binding_relocation_candidates(decl.name, relocations);\n\t\t\t}\n\t\t}\n\n\t\tcollect_yield_star_nodes(stmt, (node) => {\n\t\t\tconst text = content.slice(node.getStart(), node.end).trim();\n\n\t\t\trelocations.push({\n\t\t\t\toriginalStart: node.getStart(),\n\t\t\t\toriginalEnd: node.end,\n\t\t\t\ttext,\n\t\t\t\tmatch: \"exact\",\n\t\t\t});\n\t\t});\n\n\t\treturn relocations;\n\t});\n\n\tconst used_ranges: Array<{ start: number; end: number }> = [];\n\n\treturn candidates.flatMap((candidate) => {\n\t\tconst generated_start = find_available_generated_text(code, candidate, used_ranges);\n\n\t\tif (generated_start < 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst generated_end = generated_start + candidate.text.length;\n\t\tused_ranges.push({ start: generated_start, end: generated_end });\n\n\t\treturn [\n\t\t\t{\n\t\t\t\toriginalStart: candidate.originalStart,\n\t\t\t\toriginalEnd: candidate.originalEnd,\n\t\t\t\tgeneratedStart: generated_start,\n\t\t\t\tgeneratedEnd: generated_end,\n\t\t\t},\n\t\t];\n\t});\n}\n\ntype RelocationCandidate = {\n\toriginalStart: number;\n\toriginalEnd: number;\n\ttext: string;\n\tmatch: \"exact\" | \"identifier\";\n};\n\nfunction collect_binding_relocation_candidates(\n\tname: ts.BindingName,\n\tcandidates: RelocationCandidate[],\n): void {\n\tif (ts.isIdentifier(name)) {\n\t\tcandidates.push({\n\t\t\toriginalStart: name.getStart(),\n\t\t\toriginalEnd: name.end,\n\t\t\ttext: name.text,\n\t\t\tmatch: \"identifier\",\n\t\t});\n\n\t\treturn;\n\t}\n\n\tfor (const element of name.elements) {\n\t\tif (ts.isOmittedExpression(element)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tcollect_binding_relocation_candidates(element.name, candidates);\n\t}\n}\n\nfunction find_available_generated_text(\n\tcode: string,\n\tcandidate: RelocationCandidate,\n\tused_ranges: Array<{ start: number; end: number }>,\n): number {\n\tlet search_start = 0;\n\n\twhile (search_start < code.length) {\n\t\tconst index = code.indexOf(candidate.text, search_start);\n\n\t\tif (index < 0) {\n\t\t\treturn -1;\n\t\t}\n\n\t\tconst end = index + candidate.text.length;\n\t\tconst overlaps_used_range = used_ranges.some(\n\t\t\t(range) => index < range.end && end > range.start,\n\t\t);\n\t\tconst is_text_match =\n\t\t\tcandidate.match === \"exact\" || is_identifier_text_match(code, index, end);\n\n\t\tif (!overlaps_used_range && is_text_match) {\n\t\t\treturn index;\n\t\t}\n\n\t\tsearch_start = candidate.match === \"identifier\" ? index + 1 : end;\n\t}\n\n\treturn -1;\n}\n\nfunction is_identifier_text_match(code: string, start: number, end: number): boolean {\n\tconst before = start === 0 ? 0 : code.charCodeAt(start - 1);\n\tconst after = end >= code.length ? 0 : code.charCodeAt(end);\n\n\treturn !is_identifier_part(before) && !is_identifier_part(after);\n}\n\nfunction is_identifier_part(char_code: number): boolean {\n\treturn (\n\t\t(char_code >= 65 && char_code <= 90) ||\n\t\t(char_code >= 97 && char_code <= 122) ||\n\t\t(char_code >= 48 && char_code <= 57) ||\n\t\tchar_code === 36 ||\n\t\tchar_code === 95\n\t);\n}\n\nfunction validate_script_yield_boundaries(\n\tstmt: ts.Statement,\n\tcontent: string,\n\tfilename: string,\n): void {\n\tconst bad_member = find_class_member_with_yield_star(stmt);\n\n\tif (!bad_member) {\n\t\treturn;\n\t}\n\n\tthrow new PreprocessError(\n\t\t[\n\t\t\t`[ASYNC_EFFECT_IN_CLASS_MEMBER]: ${filename}: yield* cannot be used inside class members.`,\n\t\t\t`Class fields and methods are not component top-level reactive work. Move the Effect work into a script effect statement before assigning it to the class instance.`,\n\t\t\t\"\",\n\t\t\t\"Problematic member:\",\n\t\t\tslice(content, bad_member),\n\t\t].join(\"\\n\"),\n\t\tfilename,\n\t);\n}\n\nfunction find_class_member_with_yield_star(stmt: ts.Statement): ts.Node | undefined {\n\tlet found: ts.Node | undefined;\n\n\tfunction visit(node: ts.Node): void {\n\t\tif (found) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (\n\t\t\tts.isPropertyDeclaration(node) &&\n\t\t\tnode.initializer &&\n\t\t\tcontains_top_level_yield_star(node.initializer)\n\t\t) {\n\t\t\tfound = node;\n\t\t\treturn;\n\t\t}\n\n\t\tnode.forEachChild(visit);\n\t}\n\n\tvisit(stmt);\n\n\treturn found;\n}\n\nfunction make_name_allocator(initial_names: readonly string[]): {\n\treserve(name: string): string;\n} {\n\tconst used_names = new Set(initial_names);\n\n\treturn {\n\t\treserve(name: string): string {\n\t\t\tlet candidate = name;\n\t\t\tlet suffix = 1;\n\n\t\t\twhile (used_names.has(candidate)) {\n\t\t\t\tcandidate = `${name}_${suffix}`;\n\t\t\t\tsuffix += 1;\n\t\t\t}\n\n\t\t\tused_names.add(candidate);\n\n\t\t\treturn candidate;\n\t\t},\n\t};\n}\n\nfunction make_generated_name(hint: string, suffix: string): string {\n\tconst normalized_hint = hint.replace(/[^A-Za-z0-9_$]/g, \"_\");\n\tconst safe_hint = /^[A-Za-z_$]/.test(normalized_hint)\n\t\t? normalized_hint\n\t\t: `temp_${normalized_hint}`;\n\n\treturn `__SER___${safe_hint}${suffix}`;\n}\n","import { type MarkupTransformTarget, transform_markup_effect } from \"$/markup/transform.ts\";\nimport { transform_script_effect } from \"$/script-transform/index.ts\";\n\n/**\n * Result returned by the direct whole-file Svelte transform.\n *\n * @example\n * ```ts\n * const result = transform_svelte_effect(\"<p>{yield* load()}</p>\", \"App.svelte\");\n * result.code;\n * ```\n *\n * @since 2.5.0\n */\nexport interface SvelteTransformResult {\n\t/** Transformed Svelte source. */\n\tcode: string;\n}\n\n/**\n * Options accepted by the direct whole-file Svelte transform.\n *\n * @example\n * ```ts\n * const options: SvelteTransformOptions = { target: \"client\" };\n * ```\n *\n * @since 2.5.0\n */\nexport interface SvelteTransformOptions {\n\t/** Markup emission target passed through to the markup transform. */\n\ttarget?: MarkupTransformTarget;\n}\n\n/**\n * Lowers SER syntax in a complete Svelte component without using Svelte's\n * adapter API.\n *\n * @example\n * ```ts\n * const result = transform_svelte_effect(\n * \"<script effect>const value = yield* load()</script>\",\n * \"App.svelte\",\n * );\n * ```\n *\n * @since 2.5.0\n * @param content - Full Svelte component source to lower before Svelte parses\n * it.\n * @param filename - Component filename used in generated cache identifiers and\n * diagnostics.\n * @param options - Optional target configuration for markup lowering.\n * @returns The transformed component source.\n */\nexport function transform_svelte_effect(\n\tcontent: string,\n\tfilename = \"unknown.svelte\",\n\toptions: SvelteTransformOptions = {},\n): SvelteTransformResult {\n\tconst script = find_script(content);\n\n\tlet combined = content;\n\n\tif (script?.has_effect) {\n\t\tconst result = transform_script_effect(script.text, filename, {\n\t\t\temit_types: script.is_typescript,\n\t\t});\n\n\t\tcombined =\n\t\t\tcontent.slice(0, script.effect_attr_start) +\n\t\t\tcontent.slice(script.effect_attr_end, script.open_end) +\n\t\t\tresult.code +\n\t\t\tcontent.slice(script.close_start);\n\t}\n\n\tconst result = transform_markup_effect(combined, filename, {\n\t\ttarget: options.target,\n\t});\n\n\treturn { code: result.code };\n}\n\nfunction find_script(content: string):\n\t| {\n\t\t\ttext: string;\n\t\t\topen_end: number;\n\t\t\tclose_start: number;\n\t\t\thas_effect: boolean;\n\t\t\teffect_attr_start: number;\n\t\t\teffect_attr_end: number;\n\t\t\tis_typescript: boolean;\n\t }\n\t| undefined {\n\tconst pattern = /<script\\b([^>]*)>([\\s\\S]*?)<\\/script\\s*>/gi;\n\n\tfor (const match of content.matchAll(pattern)) {\n\t\tif (match.index === undefined || /\\bmodule\\b/.test(match[1] ?? \"\")) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst attrs = match[1] ?? \"\";\n\t\tconst effect_match = /\\s+effect(?:\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s>]+))?/.exec(attrs);\n\t\tconst open_end = match.index + match[0].indexOf(\">\") + 1;\n\t\tconst attr_start = effect_match?.index ?? attrs.length;\n\t\tconst attr_end = attr_start + (effect_match?.[0].length ?? 0);\n\n\t\treturn {\n\t\t\ttext: match[2],\n\t\t\topen_end,\n\t\t\tclose_start: match.index + match[0].lastIndexOf(\"<\"),\n\t\t\thas_effect: effect_match !== null,\n\t\t\teffect_attr_start: match.index + \"<script\".length + attr_start,\n\t\t\teffect_attr_end: match.index + \"<script\".length + attr_end,\n\t\t\tis_typescript: has_typescript_lang(attrs),\n\t\t};\n\t}\n\n\treturn undefined;\n}\n\nfunction has_typescript_lang(attrs: string): boolean {\n\tconst lang_match = /\\blang\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s>]+))/i.exec(attrs);\n\tconst lang = (lang_match?.[1] ?? lang_match?.[2] ?? lang_match?.[3] ?? \"\").toLowerCase();\n\n\treturn lang === \"ts\" || lang === \"typescript\";\n}\n\nexport {\n\ttype MarkupTransformOptions,\n\ttype MarkupTransformResult,\n\ttype MarkupTransformTarget,\n\ttransform_markup_effect,\n} from \"$/markup/transform.ts\";\n\nexport {\n\ttype BlockRef,\n\ttype ScriptTransformResult,\n\ttransform_script_effect,\n} from \"$/script-transform/index.ts\";\n"],"mappings":";;;;;;;;;;;;;;;AA+BA,SAAgB,iCACf,QACA,UACS;CACT,MAAM,eAAe,oBAAoB,MAAM;CAC/C,MAAM,YAAY,aAAa,KAAK,KAAK,QAAQ,KAAK,IAAI,EAAE;CAE5D,MAAM,OAAO,aAAa,WAAW,KAAK,cAAc,OAAO,WAAW,CAAC,CAAC,KAAK,IAAI;CAErF,OAAO;EACN;EACA;EACA,GAAG;EACH,WAAW,SAAS,iBAAiB,KAAK,SAAS,WAAW;EAC9D,WAAW,SAAS,QAAQ,KAAK,SAAS,OAAO;EACjD;EACA;EACA,WAAW,SAAS,OAAO,KAAK,SAAS,QAAQ,SAAS,SAAS,iBAAiB,QAAQ,SAAS,QAAQ;EAC7G,8BAA8B,SAAS,OAAO;EAC9C,YAAY,SAAS,OAAO;EAC5B;EACA;CACD,CAAC,CAAC,KAAK,IAAI;AACZ;AAEA,SAAS,oBAAoB,QAAoC;CAChE,MAAM,aAAa,OAAO,SAAS,UAAU,MAAM,UAAU;CAC7D,MAAM,OAAO,OAAO,SAAS,UAAU,MAAM,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AAGD;AAEA,SAAS,oBAAoB,OAAwB;CACpD,MAAM,aAAa,kDAAkD,KAAK,KAAK;CAC/E,MAAM,QAAQ,aAAa,MAAM,aAAa,MAAM,aAAa,MAAM,GAAA,CAAI,YAAY;CAEvF,OAAO,SAAS,QAAQ,SAAS;AAClC"}
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
* Block reference emitted by the script transform to track what blocks were
|
|
3
3
|
* generated in a given file.
|
|
4
4
|
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const block: BlockRef = {
|
|
8
|
+
* id: "App.svelte",
|
|
9
|
+
* kind: "script",
|
|
10
|
+
* };
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
5
13
|
* @since 2.0.0
|
|
6
14
|
*/
|
|
7
15
|
export interface BlockRef {
|
|
@@ -13,6 +21,14 @@ export interface BlockRef {
|
|
|
13
21
|
/**
|
|
14
22
|
* Result of the script transform pass.
|
|
15
23
|
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const result: ScriptTransformResult = {
|
|
27
|
+
* code: "const value = __SER___dispatcher.value(...);",
|
|
28
|
+
* blocks: [{ id: "App.svelte", kind: "script" }],
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
16
32
|
* @since 2.0.0
|
|
17
33
|
*/
|
|
18
34
|
export interface ScriptTransformResult {
|
|
@@ -50,6 +66,14 @@ export interface Relocation {
|
|
|
50
66
|
* Internal descriptor for a single `$state` temp variable that will be
|
|
51
67
|
* emitted at component scope before the rewritten statement.
|
|
52
68
|
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const temp: TempBinding = {
|
|
72
|
+
* name: "__SER___user",
|
|
73
|
+
* type: "Effect.Success<typeof user>",
|
|
74
|
+
* };
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
53
77
|
* @since 2.0.0
|
|
54
78
|
*/
|
|
55
79
|
export interface TempBinding {
|
|
@@ -59,6 +83,16 @@ export interface TempBinding {
|
|
|
59
83
|
/**
|
|
60
84
|
* Describes how a single statement was lowered.
|
|
61
85
|
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const lowered: LoweredStatement = {
|
|
89
|
+
* temps: [],
|
|
90
|
+
* rewritten_text: "const user = __SER___dispatcher.value(...);",
|
|
91
|
+
* effect_blocks: [],
|
|
92
|
+
* range: { start: 0, end: 26 },
|
|
93
|
+
* };
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
62
96
|
* @since 2.0.0
|
|
63
97
|
*/
|
|
64
98
|
export interface LoweredStatement {
|
|
@@ -82,6 +116,14 @@ export interface LoweredStatement {
|
|
|
82
116
|
* Describes a generated script effect body and the identifiers it reads
|
|
83
117
|
* synchronously for Svelte dependency tracking.
|
|
84
118
|
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const block: EffectBlock = {
|
|
122
|
+
* statements: ["const user = yield* load_user(id);"],
|
|
123
|
+
* deps: ["id"],
|
|
124
|
+
* };
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
85
127
|
* @since 2.0.0
|
|
86
128
|
*/
|
|
87
129
|
export interface EffectBlock {
|
|
@@ -93,6 +135,15 @@ export interface EffectBlock {
|
|
|
93
135
|
/**
|
|
94
136
|
* Describes how a single expression was lowered.
|
|
95
137
|
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* const expression: LoweredExpression = {
|
|
141
|
+
* temps: [],
|
|
142
|
+
* rewritten_expr: "__SER___dispatcher.value(...)",
|
|
143
|
+
* effect_blocks: [],
|
|
144
|
+
* };
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
96
147
|
* @since 2.0.0
|
|
97
148
|
*/
|
|
98
149
|
export interface LoweredExpression {
|
|
@@ -104,6 +155,19 @@ export interface LoweredExpression {
|
|
|
104
155
|
/**
|
|
105
156
|
* Stateful services used while lowering one script block.
|
|
106
157
|
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* const context: ScriptLoweringContext = {
|
|
161
|
+
* filename: "App.svelte",
|
|
162
|
+
* dispatcher_name: "get_dispatcher",
|
|
163
|
+
* effect_name: "Effect",
|
|
164
|
+
* emit_types: true,
|
|
165
|
+
* next_helper_name: (hint = "helper") => hint,
|
|
166
|
+
* next_temp_name: (hint = "temp") => hint,
|
|
167
|
+
* next_type_helper_name: (hint = "type") => hint,
|
|
168
|
+
* };
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
107
171
|
* @since 2.0.0
|
|
108
172
|
*/
|
|
109
173
|
export interface ScriptLoweringContext {
|
|
@@ -111,16 +175,47 @@ export interface ScriptLoweringContext {
|
|
|
111
175
|
filename: string;
|
|
112
176
|
/** Binding name used for the dispatcher factory in generated code. */
|
|
113
177
|
dispatcher_name: string;
|
|
178
|
+
/** Binding name used for the Effect namespace in generated code. */
|
|
114
179
|
effect_name: string;
|
|
115
180
|
/** Whether generated state placeholders should carry TypeScript types. */
|
|
116
181
|
emit_types: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Reserves a generated helper identifier.
|
|
184
|
+
*
|
|
185
|
+
* @param hint - Optional readable stem for the generated identifier.
|
|
186
|
+
* @returns A collision-free helper identifier.
|
|
187
|
+
*/
|
|
117
188
|
next_helper_name(hint?: string): string;
|
|
189
|
+
/**
|
|
190
|
+
* Reserves a generated `$state` temporary identifier.
|
|
191
|
+
*
|
|
192
|
+
* @param hint - Optional readable stem for the generated identifier.
|
|
193
|
+
* @returns A collision-free temporary identifier.
|
|
194
|
+
*/
|
|
118
195
|
next_temp_name(hint?: string): string;
|
|
196
|
+
/**
|
|
197
|
+
* Reserves a generated type-helper identifier.
|
|
198
|
+
*
|
|
199
|
+
* @param hint - Optional readable stem for the generated identifier.
|
|
200
|
+
* @returns A collision-free type-helper identifier.
|
|
201
|
+
*/
|
|
119
202
|
next_type_helper_name(hint?: string): string;
|
|
120
203
|
}
|
|
121
204
|
/**
|
|
122
205
|
* Runtime import bindings selected for generated script effect code.
|
|
123
206
|
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* const bindings: RuntimeImportBindings = {
|
|
210
|
+
* effect: "Effect",
|
|
211
|
+
* dispatcher: "get_dispatcher",
|
|
212
|
+
* dispatcher_value: "__SER___dispatcher",
|
|
213
|
+
* program: "__SER___program",
|
|
214
|
+
* cancel: "__SER___cancel",
|
|
215
|
+
* untrack: "untrack",
|
|
216
|
+
* };
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
124
219
|
* @since 2.4.2
|
|
125
220
|
*/
|
|
126
221
|
export interface RuntimeImportBindings {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { error as svelte_error } from "@sveltejs/kit";
|
|
2
1
|
import { Effect } from "effect";
|
|
3
2
|
declare const error_status_codes: {
|
|
4
3
|
readonly ProxyAuthenticationRequired: 407;
|
|
@@ -55,7 +54,9 @@ declare const redirect_status_codes: {
|
|
|
55
54
|
readonly UseProxy: 305;
|
|
56
55
|
readonly Found: 302;
|
|
57
56
|
};
|
|
58
|
-
type
|
|
57
|
+
type AppErrorStatus = App.Error extends {
|
|
58
|
+
readonly status?: infer Status;
|
|
59
|
+
} ? Status : number;
|
|
59
60
|
/**
|
|
60
61
|
* Named HTTP status accepted by the {@link Error} helper.
|
|
61
62
|
*
|
|
@@ -78,6 +79,31 @@ export type ErrorStatusName = keyof typeof error_status_codes;
|
|
|
78
79
|
* @since 2.3.0
|
|
79
80
|
*/
|
|
80
81
|
export type ErrorStatus = ErrorStatusName | number;
|
|
82
|
+
/**
|
|
83
|
+
* Error body accepted by the {@link Error} helper.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const body: ErrorBody = { message: "Post not found" };
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @since 3.4.3
|
|
91
|
+
*/
|
|
92
|
+
export type ErrorBody = (Omit<App.Error, "status"> & {
|
|
93
|
+
readonly status?: AppErrorStatus;
|
|
94
|
+
}) | string | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Extra SvelteKit app error properties accepted by the {@link Error} helper
|
|
97
|
+
* when using the SvelteKit 3 string-body overload.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const properties: ErrorProperties = { code: "POST_NOT_FOUND" };
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @since 3.4.3
|
|
105
|
+
*/
|
|
106
|
+
export type ErrorProperties = Omit<App.Error, "status" | "message">;
|
|
81
107
|
/**
|
|
82
108
|
* Named HTTP status accepted by the {@link Redirect} helper.
|
|
83
109
|
*
|
|
@@ -100,6 +126,19 @@ export type RedirectStatusName = keyof typeof redirect_status_codes;
|
|
|
100
126
|
* @since 2.3.0
|
|
101
127
|
*/
|
|
102
128
|
export type RedirectStatus = RedirectStatusName | number;
|
|
129
|
+
/**
|
|
130
|
+
* Options accepted by the {@link Redirect} helper.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const options: RedirectOptions = { external: true };
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @since 3.4.3
|
|
138
|
+
*/
|
|
139
|
+
export type RedirectOptions = {
|
|
140
|
+
readonly external?: boolean | string[];
|
|
141
|
+
};
|
|
103
142
|
/**
|
|
104
143
|
* Callable shape for the exported {@link Error} helper.
|
|
105
144
|
*
|
|
@@ -127,7 +166,28 @@ export interface ErrorEffectFactory {
|
|
|
127
166
|
* @returns An Effect that never succeeds because SvelteKit takes over request
|
|
128
167
|
* control flow.
|
|
129
168
|
*/
|
|
130
|
-
(status: ErrorStatus, body?:
|
|
169
|
+
(status: ErrorStatus, body?: ErrorBody): Effect.Effect<never, never, never>;
|
|
170
|
+
/**
|
|
171
|
+
* Creates an Effect that throws SvelteKit's HTTP error control-flow value
|
|
172
|
+
* using the SvelteKit 3 string-body overload with extra properties.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* return yield* Error("NotFound", "Post not found", {
|
|
177
|
+
* code: "POST_NOT_FOUND",
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @since 3.4.3
|
|
182
|
+
* @param status - Numeric HTTP status or PascalCase status name to pass to
|
|
183
|
+
* SvelteKit's `error` helper.
|
|
184
|
+
* @param body - Error message forwarded to SvelteKit.
|
|
185
|
+
* @param properties - Additional app error properties forwarded to
|
|
186
|
+
* SvelteKit.
|
|
187
|
+
* @returns An Effect that never succeeds because SvelteKit takes over request
|
|
188
|
+
* control flow.
|
|
189
|
+
*/
|
|
190
|
+
(status: ErrorStatus, body: string, properties: ErrorProperties): Effect.Effect<never, never, never>;
|
|
131
191
|
}
|
|
132
192
|
/**
|
|
133
193
|
* Callable shape for the exported {@link Redirect} helper.
|
|
@@ -152,10 +212,12 @@ export interface RedirectEffectFactory {
|
|
|
152
212
|
* @param status - Numeric redirect status or PascalCase status name to pass
|
|
153
213
|
* to SvelteKit's `redirect` helper.
|
|
154
214
|
* @param location - Target URL forwarded unchanged to SvelteKit.
|
|
215
|
+
* @param options - Optional SvelteKit redirect options. In SvelteKit 3, pass
|
|
216
|
+
* `{ external: true }` or an allowlist to redirect to external URLs.
|
|
155
217
|
* @returns An Effect that never succeeds because SvelteKit takes over request
|
|
156
218
|
* control flow.
|
|
157
219
|
*/
|
|
158
|
-
(status: RedirectStatus, location: string | URL): Effect.Effect<never, never, never>;
|
|
220
|
+
(status: RedirectStatus, location: string | URL, options?: RedirectOptions): Effect.Effect<never, never, never>;
|
|
159
221
|
}
|
|
160
222
|
/**
|
|
161
223
|
* Creates an Effect that raises SvelteKit's HTTP error control flow.
|
|
@@ -170,6 +232,8 @@ export interface RedirectEffectFactory {
|
|
|
170
232
|
* SvelteKit's `error` helper.
|
|
171
233
|
* @param body - Optional SvelteKit error body or message forwarded unchanged
|
|
172
234
|
* to SvelteKit.
|
|
235
|
+
* @param properties - Optional SvelteKit 3 app error properties forwarded when
|
|
236
|
+
* using a string error message.
|
|
173
237
|
* @returns An Effect that never succeeds because SvelteKit takes over request
|
|
174
238
|
* control flow.
|
|
175
239
|
*/
|
|
@@ -186,6 +250,8 @@ export declare const Error: ErrorEffectFactory;
|
|
|
186
250
|
* @param status - Numeric redirect status or PascalCase status name to pass to
|
|
187
251
|
* SvelteKit's `redirect` helper.
|
|
188
252
|
* @param location - Target URL forwarded unchanged to SvelteKit.
|
|
253
|
+
* @param options - Optional SvelteKit redirect options. In SvelteKit 3, pass
|
|
254
|
+
* `{ external: true }` or an allowlist to redirect to external URLs.
|
|
189
255
|
* @returns An Effect that never succeeds because SvelteKit takes over request
|
|
190
256
|
* control flow.
|
|
191
257
|
*/
|
|
@@ -18,7 +18,21 @@ export declare function is_generator_result<A>(value: unknown): value is Effect.
|
|
|
18
18
|
* @param value - Effect or generator return value.
|
|
19
19
|
* @returns Normalized Effect.
|
|
20
20
|
*/
|
|
21
|
-
export declare function
|
|
21
|
+
export declare function ToEffect<A, E, R>(value: EffectLike<A, E, R>): Effect.Effect<A, E, R>;
|
|
22
|
+
/**
|
|
23
|
+
* Compatibility alias for {@link ToEffect}.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const program = to_effect(Effect.succeed(1));
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @since 2.0.0
|
|
31
|
+
* @param value - Effect or generator return value.
|
|
32
|
+
* @returns Normalized Effect.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare const to_effect: typeof ToEffect;
|
|
22
36
|
/**
|
|
23
37
|
* Checks whether a value is a live query source SvelteKit can consume.
|
|
24
38
|
*
|