@matthesketh/utopia-compiler 0.7.1 → 0.7.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.
package/dist/index.cjs CHANGED
@@ -563,6 +563,10 @@ ${fnBody}
563
563
  const OPTION_MODS = /* @__PURE__ */ new Set(["once", "capture", "passive"]);
564
564
  const handlerMods = modifiers.filter((m) => !OPTION_MODS.has(m));
565
565
  const optionMods = modifiers.filter((m) => OPTION_MODS.has(m));
566
+ const IS_HANDLER_REF = /^[\w$.]+$/;
567
+ const IS_ARROW_FN = /^\s*(?:\(.*?\)|[\w$]+)\s*=>/;
568
+ const hasExpression = handler !== "''";
569
+ const isInlineExpr = hasExpression && !IS_HANDLER_REF.test(handler) && !IS_ARROW_FN.test(handler);
566
570
  let handlerExpr = handler;
567
571
  if (handlerMods.length > 0) {
568
572
  const guards = [];
@@ -580,8 +584,18 @@ ${fnBody}
580
584
  break;
581
585
  }
582
586
  }
583
- const body = [...guards, ...calls, `(${handler})(_e)`].join("; ");
584
- handlerExpr = `(_e) => { ${body} }`;
587
+ if (!hasExpression) {
588
+ const body = [...guards, ...calls].join("; ");
589
+ handlerExpr = `(_e) => { ${body} }`;
590
+ } else if (isInlineExpr) {
591
+ const body = [...guards, ...calls, handler.replace(/\$event/g, "_e")].join("; ");
592
+ handlerExpr = `(_e) => { ${body} }`;
593
+ } else {
594
+ const body = [...guards, ...calls, `(${handler})(_e)`].join("; ");
595
+ handlerExpr = `(_e) => { ${body} }`;
596
+ }
597
+ } else if (isInlineExpr) {
598
+ handlerExpr = `(_e) => { ${handler.replace(/\$event/g, "_e")} }`;
585
599
  }
586
600
  const optionsStr = optionMods.length > 0 ? `, { ${optionMods.map((m) => `${m}: true`).join(", ")} }` : "";
587
601
  this.emit(`addEventListener(${elVar}, '${escapeStr(event)}', ${handlerExpr}${optionsStr})`);
package/dist/index.js CHANGED
@@ -530,6 +530,10 @@ ${fnBody}
530
530
  const OPTION_MODS = /* @__PURE__ */ new Set(["once", "capture", "passive"]);
531
531
  const handlerMods = modifiers.filter((m) => !OPTION_MODS.has(m));
532
532
  const optionMods = modifiers.filter((m) => OPTION_MODS.has(m));
533
+ const IS_HANDLER_REF = /^[\w$.]+$/;
534
+ const IS_ARROW_FN = /^\s*(?:\(.*?\)|[\w$]+)\s*=>/;
535
+ const hasExpression = handler !== "''";
536
+ const isInlineExpr = hasExpression && !IS_HANDLER_REF.test(handler) && !IS_ARROW_FN.test(handler);
533
537
  let handlerExpr = handler;
534
538
  if (handlerMods.length > 0) {
535
539
  const guards = [];
@@ -547,8 +551,18 @@ ${fnBody}
547
551
  break;
548
552
  }
549
553
  }
550
- const body = [...guards, ...calls, `(${handler})(_e)`].join("; ");
551
- handlerExpr = `(_e) => { ${body} }`;
554
+ if (!hasExpression) {
555
+ const body = [...guards, ...calls].join("; ");
556
+ handlerExpr = `(_e) => { ${body} }`;
557
+ } else if (isInlineExpr) {
558
+ const body = [...guards, ...calls, handler.replace(/\$event/g, "_e")].join("; ");
559
+ handlerExpr = `(_e) => { ${body} }`;
560
+ } else {
561
+ const body = [...guards, ...calls, `(${handler})(_e)`].join("; ");
562
+ handlerExpr = `(_e) => { ${body} }`;
563
+ }
564
+ } else if (isInlineExpr) {
565
+ handlerExpr = `(_e) => { ${handler.replace(/\$event/g, "_e")} }`;
552
566
  }
553
567
  const optionsStr = optionMods.length > 0 ? `, { ${optionMods.map((m) => `${m}: true`).join(", ")} }` : "";
554
568
  this.emit(`addEventListener(${elVar}, '${escapeStr(event)}', ${handlerExpr}${optionsStr})`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matthesketh/utopia-compiler",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Compiler for .utopia single-file components",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -43,6 +43,6 @@
43
43
  "dev": "tsup src/index.ts --format esm,cjs --dts --watch"
44
44
  },
45
45
  "dependencies": {
46
- "@matthesketh/utopia-core": "^0.7.0"
46
+ "@matthesketh/utopia-core": "^0.7.x"
47
47
  }
48
48
  }