@stacksjs/stx 0.2.128 → 0.2.130

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.
@@ -26,6 +26,28 @@ export declare function extractVariables(scriptContent: string, context: Record<
26
26
  */
27
27
  export declare function isCompleteImport(statement: string): boolean;
28
28
  export declare function convertToCommonJS(scriptContent: string, filePath?: string): string;
29
+ /**
30
+ * Parse variable declarations (including multi-line objects and arrays)
31
+ */
32
+ /**
33
+ * Split `const name: Type = value` into its parts.
34
+ *
35
+ * The pattern this supports used to require the `=` to follow the name
36
+ * directly, so any TypeScript annotation made the declaration unparseable. That
37
+ * is not a small failure: an unparseable declaration throws out of
38
+ * `convertToCommonJS`, the whole server script falls back to static
39
+ * extraction, and the page renders with every variable undefined and no error.
40
+ * A single `const rows: any = await db...` was enough to blank a page.
41
+ *
42
+ * The annotation is erased at runtime, so it only has to be skipped. It is
43
+ * scanned rather than matched because it can contain almost anything: `=` in a
44
+ * generic default, braces in an object type, commas and angle brackets in a
45
+ * generic argument list.
46
+ *
47
+ * Returns null when the line is not a simple declaration, which leaves the
48
+ * destructuring and multi-line paths below to handle it as before.
49
+ */
50
+ export declare function splitDeclaration(line: string): { type: string, name: string, value: string } | null;
29
51
  /**
30
52
  * Extract script content from an HTML template
31
53
  *
@@ -877,8 +877,61 @@ function extractDestructuredNames(pattern) {
877
877
  names.push(currentName.trim());
878
878
  return names;
879
879
  }
880
+ export function splitDeclaration(line) {
881
+ const head = /^(?:export\s+)?(const|let|var)\s+([A-Za-z_$][\w$]*)/.exec(line);
882
+ if (!head)
883
+ return null;
884
+ let index = head[0].length;
885
+ const isSpace = (character) => character === " " || character === "\t";
886
+ while (index < line.length && isSpace(line[index]))
887
+ index++;
888
+ if (line[index] === ":") {
889
+ let depth = 0, quote = null;
890
+ index++;
891
+ for (;index < line.length; index++) {
892
+ const character = line[index];
893
+ if (quote) {
894
+ if (character === "\\") {
895
+ index++;
896
+ continue;
897
+ }
898
+ if (character === quote)
899
+ quote = null;
900
+ continue;
901
+ }
902
+ if (character === "'" || character === '"' || character === "`") {
903
+ quote = character;
904
+ continue;
905
+ }
906
+ if (character === "(" || character === "[" || character === "{" || character === "<") {
907
+ depth++;
908
+ continue;
909
+ }
910
+ if (character === ")" || character === "]" || character === "}" || character === ">") {
911
+ depth--;
912
+ continue;
913
+ }
914
+ if (character === "=" && depth <= 0) {
915
+ const next = line[index + 1], previous = line[index - 1];
916
+ if (next !== "=" && next !== ">" && previous !== "=" && previous !== "!" && previous !== "<" && previous !== ">")
917
+ break;
918
+ }
919
+ }
920
+ if (line[index] !== "=")
921
+ return null;
922
+ }
923
+ while (index < line.length && isSpace(line[index]))
924
+ index++;
925
+ if (line[index] !== "=")
926
+ return null;
927
+ return {
928
+ type: head[1],
929
+ name: head[2],
930
+ value: line.slice(index + 1).trim()
931
+ };
932
+ }
880
933
  function parseVariableDeclaration(lines, startIndex) {
881
- const firstLine = lines[startIndex].trim(), match = firstLine.match(/^(?:export\s+)?(const|let|var)\s+(\w+)\s*=\s*(.*)$/);
934
+ const firstLine = lines[startIndex].trim(), split = splitDeclaration(firstLine), match = split ? [firstLine, split.type, split.name, split.value] : null;
882
935
  if (!match) {
883
936
  const destructuringPrefix = firstLine.match(/^(?:export\s+)?(const|let|var)\s+/);
884
937
  if (destructuringPrefix) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.128",
4
+ "version": "0.2.130",
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.12",
119
119
  "@stacksjs/clapp": "^0.2.0",
120
- "@stacksjs/desktop": "0.2.128",
121
- "@stacksjs/sanitizer": "0.2.128",
120
+ "@stacksjs/desktop": "0.2.130",
121
+ "@stacksjs/sanitizer": "0.2.130",
122
122
  "@stacksjs/ts-i18n": "^0.1.11",
123
- "bun-plugin-stx": "0.2.128",
123
+ "bun-plugin-stx": "0.2.130",
124
124
  "bunfig": "^0.15.15",
125
- "stx-router": "0.2.128",
125
+ "stx-router": "0.2.130",
126
126
  "ts-broadcasting": "^0.0.9",
127
127
  "ts-images": "^0.1.9",
128
128
  "ts-syntax-highlighter": "^0.2.1"