@stacksjs/stx 0.2.185 → 0.2.187

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.
@@ -216,13 +216,7 @@ function compileScriptScope(source, file, outputDir) {
216
216
  code = code.replace(propMatch[0], "");
217
217
  }
218
218
  code = code.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g, "");
219
- let body;
220
- try {
221
- body = new Bun.Transpiler({ loader: "ts" }).transformSync(code);
222
- } catch (error) {
223
- throw Error(`${file}: failed to transpile component script (${error.message})`);
224
- }
225
- return { imports, body: body.trim(), propNames, defaults };
219
+ return { imports, body: code.trim(), propNames, defaults };
226
220
  }
227
221
  function compileEventDirectives(template) {
228
222
  const eventTypes = new Set;
@@ -608,16 +602,33 @@ ${body}
608
602
 
609
603
  `), scope = component.scope, destructured = [...new Set([...Object.keys(component.properties), ...scope.propNames])].map((name) => scope.defaults[name] === void 0 ? name : `${name} = ${scope.defaults[name]}`).join(", "), indent = (code) => code.split(`
610
604
  `).map((line) => line.trim() === "" ? line : ` ${line}`).join(`
611
- `), renderMethod = component.render.trim() === "" && scope.body === "" && destructured === "" ? "" : `
605
+ `);
606
+ let renderMethod = "";
607
+ if (component.render.trim() !== "" || scope.body !== "" || destructured !== "") {
608
+ const inner = [
609
+ destructured ? `const { ${destructured} } = this._props();` : "",
610
+ scope.body,
611
+ "let out = '';",
612
+ component.render,
613
+ "return out;"
614
+ ].filter(Boolean).join(`
615
+ `);
616
+ let compiled;
617
+ try {
618
+ const wrapped = new Bun.Transpiler({ loader: "ts" }).transformSync(`export function __render(__helpers) {
619
+ ${inner}
620
+ }`), opening = wrapped.indexOf("{"), closing = wrapped.lastIndexOf("}");
621
+ compiled = wrapped.slice(opening + 1, closing).trim();
622
+ } catch (error) {
623
+ throw Error(`${component.sourcePath}: failed to compile render (${error.message})`);
624
+ }
625
+ renderMethod = `
612
626
  render(__helpers) {
613
627
  const { escape: __escape, raw: __raw, values: __values, entries: __entries } = __helpers;
614
- ${destructured ? ` const { ${destructured} } = this._props();
615
- ` : ""}${scope.body ? `${indent(scope.body)}
616
- ` : ""} let out = '';
617
- ${indent(component.render)}
618
- return out;
628
+ ${indent(compiled.trim())}
619
629
  }
620
630
  `;
631
+ }
621
632
  return `import { StxElement, defineComponent } from './runtime.js';
622
633
  ${scope.imports.length ? `${scope.imports.join(`
623
634
  `)}