@stacksjs/stx 0.2.180 → 0.2.182

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.
@@ -4,6 +4,7 @@ import { getPublicEnvDefine } from "./public-env.js";
4
4
  import { STX_RUNTIME_GLOBALS } from "./runtime-globals.js";
5
5
  import { readSigned, sourceSignature, writeSigned } from "./source-signature.js";
6
6
  import { stripModuleImports, transformStoreImports } from "./store-imports.js";
7
+ import { getSharedTranspiler } from "./utils.js";
7
8
  const _cachedStoreScripts = new Map;
8
9
  function collectDeclaredNames(code, into) {
9
10
  for (const match of code.matchAll(/\b(?:const|let|var|function|class)\s+([A-Z_a-z$][\w$]*)/g))
@@ -64,7 +65,7 @@ export async function getStoreScript(storesDir) {
64
65
  return 0;
65
66
  return a.hasUseStore ? 1 : -1;
66
67
  });
67
- const sortedFiles = filesWithDeps.map((f) => f.file), chunks = [], declaredNames = new Set, transpiler = new Bun.Transpiler({ loader: "ts", target: "browser", define: getPublicEnvDefine() });
68
+ const sortedFiles = filesWithDeps.map((f) => f.file), chunks = [], declaredNames = new Set, transpiler = getSharedTranspiler({ loader: "ts", target: "browser", define: getPublicEnvDefine() });
68
69
  for (const file of sortedFiles)
69
70
  try {
70
71
  let code = await Bun.file(file).text();
package/dist/utils.js CHANGED
@@ -11,6 +11,7 @@ import { getPublicEnvDefine } from "./public-env.js";
11
11
  import { processScopedStyles } from "./style-scoping.js";
12
12
  import { findSfcTemplateBlock } from "./sfc-template.js";
13
13
  import { importOnce } from "./lazy-module.js";
14
+ import { stashScriptElements } from "./html-masking.js";
14
15
  export {
15
16
  extractDirectiveNames,
16
17
  getPositionInfo,
@@ -581,7 +582,14 @@ ${triedPaths.map((p) => ` - ${p}`).join(`
581
582
  for (const [key, val] of Object.entries(parentContext))
582
583
  if (!key.startsWith("__") || internalKeysToPreserve.has(key))
583
584
  filteredParentContext[key] = val;
584
- const { extractSlotContent } = await importOnce("stx/slots", () => import("./slots.js")), parsedSlotContent = extractSlotContent(slotContent), $slots = {};
585
+ const stashedCallerScripts = stashScriptElements(slotContent), callerClientScripts = [], componentSlotContent = stashedCallerScripts.output.replace(/\x00STX_SCRIPT_(\d+)\x00/g, (_match, index) => {
586
+ const script = stashedCallerScripts.scripts[Number(index)] || "", attrs = script.match(/^<script\b([^>]*)>/i)?.[1] || "", type = attrs.match(/\btype\s*=\s*["']([^"']+)["']/i)?.[1]?.toLowerCase(), executable = !type || ["module", "text/javascript", "application/javascript"].includes(type);
587
+ if (!/\bserver\b/i.test(attrs) && executable) {
588
+ callerClientScripts.push(script);
589
+ return "";
590
+ }
591
+ return script;
592
+ }), { extractSlotContent } = await importOnce("stx/slots", () => import("./slots.js")), parsedSlotContent = extractSlotContent(componentSlotContent), $slots = {};
585
593
  if (parsedSlotContent.defaultSlot?.trim())
586
594
  $slots.default = parsedSlotContent.defaultSlot;
587
595
  for (const [slotName, slotDef] of parsedSlotContent.namedSlots)
@@ -590,7 +598,7 @@ ${triedPaths.map((p) => ` - ${p}`).join(`
590
598
  ...filteredParentContext,
591
599
  ...props,
592
600
  props,
593
- slot: slotContent,
601
+ slot: componentSlotContent,
594
602
  $slots,
595
603
  __processedComponents: branchComponents,
596
604
  __sections: {},
@@ -779,7 +787,9 @@ finally {
779
787
  output,
780
788
  dependencies: [...dependencies].filter((dependency) => !dependencyBaseline.has(dependency))
781
789
  });
782
- return output;
790
+ return callerClientScripts.length > 0 ? `${output}
791
+ ${callerClientScripts.join(`
792
+ `)}` : output;
783
793
  } catch (error) {
784
794
  return `[Error processing component: ${error instanceof Error ? error.message : String(error)}]`;
785
795
  } finally {
@@ -1,5 +1,6 @@
1
1
  var {require}=import.meta;import path from "node:path";
2
2
  import process from "node:process";
3
+ import { getSharedTranspiler } from "./utils.js";
3
4
  export const STX_ENGINE_BINDING_NAMES = [
4
5
  "module",
5
6
  "exports",
@@ -272,7 +273,7 @@ export async function extractVariables(scriptContent, context, filePath, options
272
273
  return;
273
274
  let jsContent;
274
275
  try {
275
- const transpiler = new Bun.Transpiler({ loader: "ts", target: "browser", define: getPublicEnvDefine() });
276
+ const transpiler = getSharedTranspiler({ loader: "ts", target: "browser", define: getPublicEnvDefine() });
276
277
  let processedCode = scriptContent.replace(/^\s*import\s+\w+\s+from\s+['"][^'"]*\.stx['"]\s*;?\s*$/gm, "");
277
278
  processedCode = processedCode.replace(/^\s*import\s+['"][^'"]*\.stx['"]\s*;?\s*$/gm, "");
278
279
  jsContent = transpiler.transformSync(processedCode);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.180",
4
+ "version": "0.2.182",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -117,12 +117,12 @@
117
117
  "dependencies": {
118
118
  "@cwcss/crosswind": "^0.2.14",
119
119
  "@stacksjs/clapp": "^0.2.0",
120
- "@stacksjs/desktop": "0.2.180",
121
- "@stacksjs/sanitizer": "0.2.180",
120
+ "@stacksjs/desktop": "0.2.182",
121
+ "@stacksjs/sanitizer": "0.2.182",
122
122
  "@stacksjs/ts-i18n": "^0.1.11",
123
- "bun-plugin-stx": "0.2.180",
123
+ "bun-plugin-stx": "0.2.182",
124
124
  "bunfig": "^0.15.17",
125
- "stx-router": "0.2.180",
125
+ "stx-router": "0.2.182",
126
126
  "ts-broadcasting": "^0.0.9",
127
127
  "ts-images": "^0.1.9",
128
128
  "ts-syntax-highlighter": "^0.2.1"