@stacksjs/stx 0.2.163 → 0.2.165

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.
@@ -103,7 +103,7 @@ export declare const UNWRAP_HELPER: '__StxTemplateValue';
103
103
  * Mirrors what `serve.ts` puts in scope. Declaring these is what lets the
104
104
  * checker report a genuine typo instead of suppressing every unresolved name.
105
105
  */
106
- export declare const STX_SERVER_CONTEXT: readonly ['params', 'query', 'cookies', 'host', 'ip', 'setResponseStatus', 'setResponseHeader', 'request', 'url', 'definePageMeta'];
106
+ export declare const STX_SERVER_CONTEXT: readonly ['params', 'query', 'cookies', 'host', 'ip', 'setResponseStatus', 'setResponseHeader', 'notFound', 'request', 'url', 'definePageMeta'];
107
107
  /**
108
108
  * Names the template engine puts in scope for every page.
109
109
  *
@@ -226,6 +226,7 @@ export const STX_SERVER_CONTEXT = [
226
226
  "ip",
227
227
  "setResponseStatus",
228
228
  "setResponseHeader",
229
+ "notFound",
229
230
  "request",
230
231
  "url",
231
232
  "definePageMeta"
@@ -587,6 +587,7 @@ export function isCompleteImport(statement) {
587
587
  }
588
588
  return quote === null && braces === 0 && closedSpecifier;
589
589
  }
590
+ const UNINITIALIZED_DECLARATION = /^(?:export\s+)?(?:const|let|var)\s+[A-Za-z_$][\w$]*(?:\s*,\s*[A-Za-z_$][\w$]*)*\s*;?$/;
590
591
  export function convertToCommonJS(scriptContent, filePath) {
591
592
  const templateDir = filePath ? path.dirname(filePath) : process.cwd(), projectRoot = process.cwd(), lines = scriptContent.split(`
592
593
  `), convertedLines = [];
@@ -714,7 +715,7 @@ export function convertToCommonJS(scriptContent, filePath) {
714
715
  i++;
715
716
  continue;
716
717
  }
717
- if ((line.startsWith("const ") || line.startsWith("let ") || line.startsWith("var ") || line.startsWith("export const ") || line.startsWith("export let ") || line.startsWith("export var ")) && !line.includes("=")) {
718
+ if (UNINITIALIZED_DECLARATION.test(line)) {
718
719
  convertedLines.push(lines[i]);
719
720
  i++;
720
721
  } else if (line.startsWith("export const ") || line.startsWith("export let ") || line.startsWith("export var ")) {
@@ -937,17 +938,14 @@ function extractDestructuredNames(pattern) {
937
938
  while (i < inner.length) {
938
939
  const char = inner[i];
939
940
  if (char === "{" || char === "[") {
940
- depth++;
941
- if (depth === 1) {
942
- const nested = extractDestructuringPattern(inner, i);
943
- if (nested) {
944
- const nestedNames = extractDestructuredNames(nested.pattern);
945
- names.push(...nestedNames);
946
- i = nested.endPos;
947
- currentName = "";
948
- continue;
949
- }
941
+ const nested = depth === 0 ? extractDestructuringPattern(inner, i) : null;
942
+ if (nested) {
943
+ names.push(...extractDestructuredNames(nested.pattern));
944
+ i = nested.endPos;
945
+ currentName = "";
946
+ continue;
950
947
  }
948
+ depth++;
951
949
  } else if (char === "}" || char === "]")
952
950
  depth--;
953
951
  if (depth > 0) {
@@ -1041,20 +1039,50 @@ export function splitDeclaration(line) {
1041
1039
  value: line.slice(index + 1).trim()
1042
1040
  };
1043
1041
  }
1042
+ function countPatternDepth(text, openChar, closeChar, depth) {
1043
+ let quote = null, escaped = !1;
1044
+ for (const character of text) {
1045
+ if (escaped) {
1046
+ escaped = !1;
1047
+ continue;
1048
+ }
1049
+ if (character === "\\") {
1050
+ escaped = !0;
1051
+ continue;
1052
+ }
1053
+ if (quote) {
1054
+ if (character === quote)
1055
+ quote = null;
1056
+ continue;
1057
+ }
1058
+ if (character === "'" || character === '"' || character === "`") {
1059
+ quote = character;
1060
+ continue;
1061
+ }
1062
+ if (character === openChar)
1063
+ depth++;
1064
+ else if (character === closeChar)
1065
+ depth--;
1066
+ }
1067
+ return depth;
1068
+ }
1044
1069
  function parseVariableDeclaration(lines, startIndex) {
1045
1070
  const firstLine = lines[startIndex].trim(), split = splitDeclaration(firstLine), match = split ? [firstLine, split.type, split.name, split.value] : null;
1046
1071
  if (!match) {
1047
1072
  const destructuringPrefix = firstLine.match(/^(?:export\s+)?(const|let|var)\s+/);
1048
1073
  if (destructuringPrefix) {
1049
1074
  let afterKeyword = firstLine.slice(destructuringPrefix[0].length), joinedEndIndex = startIndex;
1050
- if ((afterKeyword.startsWith("{") || afterKeyword.startsWith("[")) && !afterKeyword.includes(afterKeyword.startsWith("{") ? "}" : "]")) {
1051
- const closeChar = afterKeyword.startsWith("{") ? "}" : "]";
1052
- let joined = afterKeyword;
1053
- for (let j = startIndex + 1;j < lines.length; j++) {
1054
- joined += " " + lines[j].trim();
1075
+ if (afterKeyword.startsWith("{") || afterKeyword.startsWith("[")) {
1076
+ const openChar = afterKeyword[0], closeChar = openChar === "{" ? "}" : "]";
1077
+ let depth = countPatternDepth(afterKeyword, openChar, closeChar, 0), joined = afterKeyword;
1078
+ for (let j = startIndex + 1;j < lines.length && depth > 0; j++) {
1079
+ joined += ` ${lines[j].trim()}`;
1055
1080
  joinedEndIndex = j;
1056
- if (lines[j].includes(closeChar))
1057
- break;
1081
+ depth = countPatternDepth(lines[j], openChar, closeChar, depth);
1082
+ }
1083
+ if (depth > 0) {
1084
+ joined = afterKeyword;
1085
+ joinedEndIndex = startIndex;
1058
1086
  }
1059
1087
  afterKeyword = joined;
1060
1088
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.163",
4
+ "version": "0.2.165",
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.163",
121
- "@stacksjs/sanitizer": "0.2.163",
120
+ "@stacksjs/desktop": "0.2.165",
121
+ "@stacksjs/sanitizer": "0.2.165",
122
122
  "@stacksjs/ts-i18n": "^0.1.11",
123
- "bun-plugin-stx": "0.2.163",
123
+ "bun-plugin-stx": "0.2.165",
124
124
  "bunfig": "^0.15.17",
125
- "stx-router": "0.2.163",
125
+ "stx-router": "0.2.165",
126
126
  "ts-broadcasting": "^0.0.9",
127
127
  "ts-images": "^0.1.9",
128
128
  "ts-syntax-highlighter": "^0.2.1"