svelte-effect-runtime 1.6.0 → 1.6.2

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.
@@ -1,5 +1,5 @@
1
- import { t as effect_preprocess } from "./preprocess-CGKEA3Py.js";
2
- import { n as sveltekit_effect_runtime } from "./vite-C8ujN78r.js";
1
+ import { t as effect_preprocess } from "./preprocess-BFePqOC6.js";
2
+ import { n as sveltekit_effect_runtime } from "./vite-BlUTKv2u.js";
3
3
  import { preprocess } from "svelte/compiler";
4
4
  //#region v3/effect.ts
5
5
  /**
@@ -48,4 +48,4 @@ function effect(options = {}) {
48
48
  //#endregion
49
49
  export { effect as t };
50
50
 
51
- //# sourceMappingURL=effect-Cx8OzrcW.js.map
51
+ //# sourceMappingURL=effect-Crj3S8Cg.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"effect-Cx8OzrcW.js","names":[],"sources":["../../../modules/svelte-effect-runtime/v3/effect.ts"],"sourcesContent":["/**\n * High-level Vite integration for `svelte-effect-runtime`.\n *\n * @example\n * ```ts\n * import { effect } from \"svelte-effect-runtime\";\n *\n * export default {\n * plugins: [effect()],\n * };\n * ```\n *\n * @module\n */\nimport { preprocess } from \"svelte/compiler\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n effect_preprocess,\n type EffectPreprocessOptions,\n} from \"$/v3/preprocess.ts\";\nimport { sveltekit_effect_runtime } from \"$/v3/vite.ts\";\n\n/** Options for the high-level {@link effect} Vite plugin. */\nexport interface EffectPluginOptions {\n effect?: EffectPreprocessOptions;\n remoteModuleId?: string;\n}\n\nfunction create_effect_svelte_transform(\n options: EffectPreprocessOptions = {},\n): Plugin {\n const preprocessor = effect_preprocess(options);\n\n return {\n name: \"svelte-effect-runtime-transform\",\n enforce: \"pre\",\n async transform(code, id, _options) {\n const filename = id.split(\"?\", 1)[0];\n if (!filename.endsWith(\".svelte\")) {\n return null;\n }\n\n const transformed = await preprocess(code, preprocessor, { filename });\n if (transformed.code === code) {\n return null;\n }\n\n return {\n code: transformed.code,\n ...(transformed.map ? { map: transformed.map as never } : {}),\n };\n },\n };\n}\n\n/**\n * Convenience Vite plugin that enables `<script effect>` transforms and wires\n * SvelteKit remote functions to the Effect-aware client adapters.\n *\n * Use this in `vite.config.ts` instead of composing lower-level runtime\n * plugins yourself.\n *\n * @see https://ser.barekey.dev/\n */\nexport function effect(\n options: EffectPluginOptions = {},\n): PluginOption[] {\n const transform_plugin = create_effect_svelte_transform(options.effect);\n\n return [\n transform_plugin,\n sveltekit_effect_runtime({\n remoteModuleId: options.remoteModuleId,\n }),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,SAAS,+BACP,UAAmC,EAAE,EAC7B;CACR,MAAM,eAAe,kBAAkB,QAAQ;AAE/C,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,UAAU,MAAM,IAAI,UAAU;GAClC,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC;AAClC,OAAI,CAAC,SAAS,SAAS,UAAU,CAC/B,QAAO;GAGT,MAAM,cAAc,MAAM,WAAW,MAAM,cAAc,EAAE,UAAU,CAAC;AACtE,OAAI,YAAY,SAAS,KACvB,QAAO;AAGT,UAAO;IACL,MAAM,YAAY;IAClB,GAAI,YAAY,MAAM,EAAE,KAAK,YAAY,KAAc,GAAG,EAAE;IAC7D;;EAEJ;;;;;;;;;;;AAYH,SAAgB,OACd,UAA+B,EAAE,EACjB;AAGhB,QAAO,CAFkB,+BAA+B,QAAQ,OAAO,EAIrE,yBAAyB,EACvB,gBAAgB,QAAQ,gBACzB,CAAC,CACH"}
1
+ {"version":3,"file":"effect-Crj3S8Cg.js","names":[],"sources":["../../../modules/svelte-effect-runtime/v3/effect.ts"],"sourcesContent":["/**\n * High-level Vite integration for `svelte-effect-runtime`.\n *\n * @example\n * ```ts\n * import { effect } from \"svelte-effect-runtime\";\n *\n * export default {\n * plugins: [effect()],\n * };\n * ```\n *\n * @module\n */\nimport { preprocess } from \"svelte/compiler\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n effect_preprocess,\n type EffectPreprocessOptions,\n} from \"$/v3/preprocess.ts\";\nimport { sveltekit_effect_runtime } from \"$/v3/vite.ts\";\n\n/** Options for the high-level {@link effect} Vite plugin. */\nexport interface EffectPluginOptions {\n effect?: EffectPreprocessOptions;\n remoteModuleId?: string;\n}\n\nfunction create_effect_svelte_transform(\n options: EffectPreprocessOptions = {},\n): Plugin {\n const preprocessor = effect_preprocess(options);\n\n return {\n name: \"svelte-effect-runtime-transform\",\n enforce: \"pre\",\n async transform(code, id, _options) {\n const filename = id.split(\"?\", 1)[0];\n if (!filename.endsWith(\".svelte\")) {\n return null;\n }\n\n const transformed = await preprocess(code, preprocessor, { filename });\n if (transformed.code === code) {\n return null;\n }\n\n return {\n code: transformed.code,\n ...(transformed.map ? { map: transformed.map as never } : {}),\n };\n },\n };\n}\n\n/**\n * Convenience Vite plugin that enables `<script effect>` transforms and wires\n * SvelteKit remote functions to the Effect-aware client adapters.\n *\n * Use this in `vite.config.ts` instead of composing lower-level runtime\n * plugins yourself.\n *\n * @see https://ser.barekey.dev/\n */\nexport function effect(\n options: EffectPluginOptions = {},\n): PluginOption[] {\n const transform_plugin = create_effect_svelte_transform(options.effect);\n\n return [\n transform_plugin,\n sveltekit_effect_runtime({\n remoteModuleId: options.remoteModuleId,\n }),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4BA,SAAS,+BACP,UAAmC,EAAE,EAC7B;CACR,MAAM,eAAe,kBAAkB,QAAQ;AAE/C,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,UAAU,MAAM,IAAI,UAAU;GAClC,MAAM,WAAW,GAAG,MAAM,KAAK,EAAE,CAAC;AAClC,OAAI,CAAC,SAAS,SAAS,UAAU,CAC/B,QAAO;GAGT,MAAM,cAAc,MAAM,WAAW,MAAM,cAAc,EAAE,UAAU,CAAC;AACtE,OAAI,YAAY,SAAS,KACvB,QAAO;AAGT,UAAO;IACL,MAAM,YAAY;IAClB,GAAI,YAAY,MAAM,EAAE,KAAK,YAAY,KAAc,GAAG,EAAE;IAC7D;;EAEJ;;;;;;;;;;;AAYH,SAAgB,OACd,UAA+B,EAAE,EACjB;AAGhB,QAAO,CAFkB,+BAA+B,QAAQ,OAAO,EAIrE,yBAAyB,EACvB,gBAAgB,QAAQ,gBACzB,CAAC,CACH"}
@@ -12555,15 +12555,9 @@ const DEFAULT_EFFECT_MODULE_ID = "effect";
12555
12555
  const DEFAULT_SVELTE_MODULE_ID = "svelte";
12556
12556
  const MARKUP_HELPER_PREFIX = "__svelteEffectRuntimeMarkup";
12557
12557
  function transformEffectMarkup(content, options) {
12558
+ if (!containsAnyYieldStarText(content)) return identityMarkupResult(content, options.filename);
12558
12559
  const sanitized = sanitizeEffectMarkup(content, options.filename);
12559
- if (sanitized.candidates.length === 0) return {
12560
- code: content,
12561
- map: new MagicString(content).generateMap({
12562
- hires: true,
12563
- includeContent: true,
12564
- source: options.filename
12565
- })
12566
- };
12560
+ if (sanitized.candidates.length === 0) return identityMarkupResult(content, options.filename);
12567
12561
  const replacements = collectMarkupReplacements(createParseSafeMarkupSource(sanitized.code), sanitized.candidates, options.filename);
12568
12562
  const magicString = new MagicString(content);
12569
12563
  for (const replacement of replacements) magicString.overwrite(replacement.start, replacement.end, replacement.text);
@@ -12577,6 +12571,19 @@ function transformEffectMarkup(content, options) {
12577
12571
  })
12578
12572
  };
12579
12573
  }
12574
+ function containsAnyYieldStarText(content) {
12575
+ return /\byield\s*\*/.test(content);
12576
+ }
12577
+ function identityMarkupResult(content, filename) {
12578
+ return {
12579
+ code: content,
12580
+ map: new MagicString(content).generateMap({
12581
+ hires: true,
12582
+ includeContent: true,
12583
+ source: filename
12584
+ })
12585
+ };
12586
+ }
12580
12587
  function createParseSafeMarkupSource(content) {
12581
12588
  const excludedRanges = findParseSafeMaskRanges(content);
12582
12589
  if (excludedRanges.length === 0) return content;
@@ -12643,7 +12650,7 @@ function getCandidateForBraceTag(openBraceIndex, closeBraceIndex, inner, filenam
12643
12650
  const leadingWhitespaceLength = inner.length - trimmed.length;
12644
12651
  const tag = getBraceTagInfo(trimmed);
12645
12652
  if (trimmed.includes(MARKUP_HELPER_PREFIX)) return;
12646
- if (!containsYieldStarText(trimmed)) return;
12653
+ if (!containsYieldStarText(trimmed.slice(tag.prefixLength))) return;
12647
12654
  if (tag.kind === "const") {
12648
12655
  const initializerRange = findConstInitializerRange(trimmed.slice(tag.prefixLength), filename);
12649
12656
  return initializerRange ? makeMarkupCandidate(openBraceIndex + 1 + leadingWhitespaceLength + tag.prefixLength + initializerRange.start, openBraceIndex + 1 + leadingWhitespaceLength + tag.prefixLength + initializerRange.end, trimmed.slice(tag.prefixLength + initializerRange.start, tag.prefixLength + initializerRange.end), helperIndex) : void 0;
@@ -12930,7 +12937,34 @@ function shouldSkipIdentifier(node) {
12930
12937
  return ts.isPropertyAccessExpression(parent) && parent.name === node || ts.isPropertyAssignment(parent) && parent.name === node || ts.isShorthandPropertyAssignment(parent) && parent.objectAssignmentInitializer === node || ts.isBindingElement(parent) && parent.propertyName === node || ts.isImportSpecifier(parent) || ts.isExportSpecifier(parent) || ts.isLabeledStatement(parent) && parent.label === node;
12931
12938
  }
12932
12939
  function containsYieldStarText(text) {
12933
- return /\byield\s*\*/.test(text);
12940
+ if (!/\byield\s*\*/.test(text)) return false;
12941
+ try {
12942
+ return topLevelYieldStarPresent(text);
12943
+ } catch {
12944
+ return true;
12945
+ }
12946
+ }
12947
+ function topLevelYieldStarPresent(text) {
12948
+ return hasTopLevelYieldStar((0, import_lib.parseExpression)(text, {
12949
+ sourceType: "module",
12950
+ allowAwaitOutsideFunction: true,
12951
+ allowYieldOutsideFunction: true
12952
+ }));
12953
+ }
12954
+ function hasTopLevelYieldStar(node) {
12955
+ if (!node || typeof node !== "object" || typeof node.type !== "string") return false;
12956
+ if (node.type === "YieldExpression" && node.delegate === true) return true;
12957
+ if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "ObjectMethod" || node.type === "ClassMethod" || node.type === "ClassPrivateMethod") return false;
12958
+ for (const key of Object.keys(node)) {
12959
+ if (key === "type" || key === "loc" || key === "start" || key === "end") continue;
12960
+ const value = node[key];
12961
+ if (Array.isArray(value)) {
12962
+ for (const item of value) if (hasTopLevelYieldStar(item)) return true;
12963
+ } else if (value && typeof value === "object") {
12964
+ if (hasTopLevelYieldStar(value)) return true;
12965
+ }
12966
+ }
12967
+ return false;
12934
12968
  }
12935
12969
  function findMarkupBraceClose(content, openBraceIndex, filename) {
12936
12970
  const expressionClose = findExpressionBraceCloseWithBabel(content, openBraceIndex, filename);
@@ -13353,4 +13387,4 @@ function indentBlock(text, indent) {
13353
13387
  //#endregion
13354
13388
  export { transformEffectMarkup as t };
13355
13389
 
13356
- //# sourceMappingURL=markup-BMn2sQOB.js.map
13390
+ //# sourceMappingURL=markup-CkPUZIJt.js.map