@xaendar/compiler 0.5.2 → 0.5.4

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.
@@ -1,4 +1,4 @@
1
- import { Stack, indent } from "@xaendar/common";
1
+ import { Stack, assertIsValidElementName, indent } from "@xaendar/common";
2
2
  import ts from "typescript";
3
3
  //#region ../packages/compiler/src/lexer/types/lexer-state.enum.ts
4
4
  /**
@@ -2219,8 +2219,10 @@ function processConstDeclaration(node, _nodeName, _parentNode, context) {
2219
2219
  */
2220
2220
  function processElement(node, nodeName, parentNode, context) {
2221
2221
  const childrenContext = new Context([], context);
2222
+ const tagName = node.tagName;
2223
+ assertIsValidElementName(tagName);
2222
2224
  return [
2223
- `const ${nodeName} = document.createElement("${node.tagName}");`,
2225
+ `const ${nodeName} = document.createElement("${tagName}");`,
2224
2226
  ...node.attributes?.map((attr) => {
2225
2227
  const value = attr.value;
2226
2228
  return typeof value === "string" ? `${nodeName}.setAttribute('${attr.name}', ${value});` : `unwatchFns.push(effect(() => ${nodeName}.setAttribute('${attr.name}', ${resolveExpression(value.expression, context)})));`;
@@ -2296,7 +2298,7 @@ function processFor(node, nodeName, parentNode, parentContext) {
2296
2298
  ],
2297
2299
  args: [itemsName, counterName]
2298
2300
  });
2299
- mainBlock.push("(() => {", ...indent("let localUnwatchFns = [];", "const unwatch = () => {", ...indent("localUnwatchFns?.forEach(fn => fn());", "localUnwatchFns = [];", "unwatchFns = unwatchFns.filter(fn => !localUnwatchFns.includes(fn));"), "};", "unwatchFns.push(", ...indent("effect(() => {", ...indent("unwatch();", `const ${itemsName} = ${iterableExpr};`, "Signal.subtle.untrack(() => {", ...indent(`for (let ${counterName} = 0; ${counterName} < ${itemsName}.length; ${counterName}++) {`, ...indent(`localUnwatchFns.push(...this.for_${nodeName}(${itemsName}, ${counterName}));`, "unwatchFns.push(...localUnwatchFns);"), "}"), "});"), "})"), ");"), "})();");
2301
+ mainBlock.push("(() => {", ...indent("let localUnwatchFns = [];", "const unwatch = () => {", ...indent("unwatchFns = unwatchFns.filter(fn => !localUnwatchFns.includes(fn));", "localUnwatchFns?.forEach(fn => fn());", "localUnwatchFns = [];"), "};", "unwatchFns.push(", ...indent("effect(() => {", ...indent("unwatch();", `const ${itemsName} = ${iterableExpr};`, "Signal.subtle.untrack(() => {", ...indent(`for (let ${counterName} = 0; ${counterName} < ${itemsName}.length; ${counterName}++) {`, ...indent(`localUnwatchFns.push(...this.for_${nodeName}(${itemsName}, ${counterName}));`, "unwatchFns.push(...localUnwatchFns);"), "}"), "});"), "})"), ");"), "})();");
2300
2302
  return {
2301
2303
  mainBlock,
2302
2304
  fns: functionsToProcess
@@ -2356,7 +2358,7 @@ function processIf(node, nodeName, parentNode, context) {
2356
2358
  return {
2357
2359
  mainBlock: [
2358
2360
  "(() => {",
2359
- ...indent("let state;", "let localUnwatchFns = []", "const checkAndUpdateState = (newState, fn) => {", ...indent("if (state === newState) {", ...indent("return;"), "}", "state = newState;", "unwatch();", "localUnwatchFns = Signal.subtle.untrack(fn);", "unwatchFns.push(...localUnwatchFns);"), "};", "const unwatch = () => {", ...indent("localUnwatchFns?.forEach(fn => fn());", "unwatchFns = unwatchFns.filter(fn => !localUnwatchFns.includes(fn));", "localUnwatchFns = [];"), "}", "unwatchFns.push(", ...indent("effect(() => {", ...indent(...mainBlock), "})"), ");"),
2361
+ ...indent("let state;", "let localUnwatchFns = []", "const checkAndUpdateState = (newState, fn) => {", ...indent("if (state === newState) {", ...indent("return;"), "}", "state = newState;", "unwatch();", "localUnwatchFns = Signal.subtle.untrack(fn);", "unwatchFns.push(...localUnwatchFns);"), "};", "const unwatch = () => {", ...indent("unwatchFns = unwatchFns.filter(fn => !localUnwatchFns.includes(fn));", "localUnwatchFns?.forEach(fn => fn());", "localUnwatchFns = [];"), "}", "unwatchFns.push(", ...indent("effect(() => {", ...indent(...mainBlock), "})"), ");"),
2360
2362
  "})();"
2361
2363
  ],
2362
2364
  fns: functionsToProcess
@@ -2392,7 +2394,7 @@ function processSwitch(node, nodeName, parentNode, context) {
2392
2394
  return {
2393
2395
  mainBlock: [
2394
2396
  "(() => {",
2395
- ...indent("let localUnwatchFns = []", "const unwatch = () => {", ...indent("localUnwatchFns?.forEach(fn => fn());", "unwatchFns = unwatchFns.filter(fn => !localUnwatchFns.includes(fn));", "localUnwatchFns = [];"), "}", "unwatchFns.push(", ...indent("effect(() => {", ...indent("unwatch();", ...mainBlock), "})"), ");"),
2397
+ ...indent("let localUnwatchFns = []", "const unwatch = () => {", ...indent("unwatchFns = unwatchFns.filter(fn => !localUnwatchFns.includes(fn));", "localUnwatchFns?.forEach(fn => fn());", "localUnwatchFns = [];"), "}", "unwatchFns.push(", ...indent("effect(() => {", ...indent("unwatch();", ...mainBlock), "})"), ");"),
2396
2398
  "})();"
2397
2399
  ],
2398
2400
  fns: functionsToProcess
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/compiler",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "A library for transpiling Xaendar Templates into JavaScript code",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -16,8 +16,8 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@xaendar/common": "0.5.2",
20
- "@xaendar/types": "0.5.2",
19
+ "@xaendar/common": "0.5.4",
20
+ "@xaendar/types": "0.5.4",
21
21
  "typescript": "^6.0.3"
22
22
  }
23
23
  }