@xaendar/compiler 0.6.15 → 0.6.17

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.
@@ -1612,8 +1612,8 @@ function parseImplicitAliases(source, baseOffset, out) {
1612
1612
  const eqIndex = trimmed.indexOf("=");
1613
1613
  if (eqIndex === -1) throw new Error(`[Parser] Invalid alias declaration '${trimmed}'. Expected '$implicit = alias'.`);
1614
1614
  cursor += entry.length + 1;
1615
- const implicit = trimmed.slice(0, eqIndex).trim();
1616
- const alias = trimmed.slice(eqIndex + 1).trim();
1615
+ const alias = trimmed.slice(0, eqIndex).trim();
1616
+ const implicit = trimmed.slice(eqIndex + 1).trim();
1617
1617
  const isImplicitVariable = (value) => IMPLICIT_VARIABLES.has(value);
1618
1618
  if (!isImplicitVariable(implicit)) throw new Error(`[Parser] '${implicit}' is not a known implicit variable. Known variables: ${[...IMPLICIT_VARIABLES].join(", ")}.`);
1619
1619
  cursor += entry.length + 1;
@@ -1670,7 +1670,7 @@ function splitForSections(source) {
1670
1670
  }
1671
1671
  current += char;
1672
1672
  }
1673
- if (current.trim().length > 0) sections.push(current);
1673
+ if (current.trim().length) sections.push(current);
1674
1674
  return sections;
1675
1675
  }
1676
1676
  /**
@@ -2231,7 +2231,7 @@ function processElement(node, nodeName, parentNode, compilerContext) {
2231
2231
  "[",
2232
2232
  ...indent(events),
2233
2233
  "]"
2234
- ]), ")") : code[code.length - 1] = `${code[code.length - 1]} [])`;
2234
+ ]), ");") : code[code.length - 1] = `${code[code.length - 1]} []);`;
2235
2235
  code.push(...node.children.map((child, i) => processNode(child, i.toString(), nodeName, compilerContext)).flat());
2236
2236
  return code;
2237
2237
  }
@@ -2315,7 +2315,13 @@ function processFor(node, nodeName, parentNode, compilerContext) {
2315
2315
  ], compilerContext);
2316
2316
  const forKey = getBlockIdentifier(parentNode, nodeName, "for");
2317
2317
  functionsToProcess.set(forKey, {
2318
- code: [`const { ${node.itemAlias}, ${indexName}, ${firstName}, ${lastName}, ${evenName}, ${oddName} } = _iterationVariables(${itemsName}, ${counterName});`, ...node.children.flatMap((child, i) => processNode(child, `${nodeName}_${i}`, parentNode, forContext))],
2318
+ code: [`const { ${node.itemAlias}, ${indexName}, ${firstName}, ${lastName}, ${evenName}, ${oddName} } = _iterationVariables(${itemsName}, ${counterName}, '${node.itemAlias}', {
2319
+ $index: '${indexName}',
2320
+ $first: '${firstName}',
2321
+ $last: '${lastName}',
2322
+ $even: '${evenName}',
2323
+ $odd: '${oddName}'
2324
+ });`, ...node.children.flatMap((child, i) => processNode(child, `${nodeName}_${i}`, parentNode, forContext))],
2319
2325
  args: [
2320
2326
  parentNode,
2321
2327
  "parentContext",
@@ -2468,7 +2474,7 @@ function processSwitch(node, nodeName, parentNode, compilerContext) {
2468
2474
  * @returns Array of generated code lines.
2469
2475
  */
2470
2476
  function processTextAndInterpolation(node, parentNode, compilerContext) {
2471
- return [`${node.type === ASTNodeType.Text ? `_renderLiteralText(${parentNode}, context, '${node.value}')` : `_renderText(${parentNode}, context, () => ${resolveExpression(node.expression, compilerContext)})`}`];
2477
+ return [`${node.type === ASTNodeType.Text ? `_renderLiteralText(${parentNode}, context, '${node.value}');` : `_renderText(${parentNode}, context, () => ${resolveExpression(node.expression, compilerContext)});`}`];
2472
2478
  }
2473
2479
  //#endregion
2474
2480
  //#region ../packages/compiler/src/render-generator/render-generator.ts
@@ -2484,13 +2490,13 @@ var nodeToProcess = /* @__PURE__ */ new Map();
2484
2490
  function generateRenderFunction(ast, cssVariableName) {
2485
2491
  nodeToProcess.clear();
2486
2492
  const compilerContext = new CompilerContext();
2487
- const renderFunctions = ["_render() {", ...indent([`const ${ROOT_NODE} = this._root;`, "const context = new Context(this)"])];
2493
+ const renderFunctions = ["_render() {", ...indent([`const ${ROOT_NODE} = this._root;`, "const context = new Context(this);"])];
2488
2494
  if (cssVariableName) renderFunctions.push(indent(`${ROOT_NODE}.adoptedStyleSheets = [${cssVariableName}];`));
2489
2495
  renderFunctions.push(...indent([...ast.map((node, i) => [...processNode(node, i.toString(), ROOT_NODE, compilerContext)]).flat(), "return context;"]), "}");
2490
2496
  while (nodeToProcess.size) {
2491
2497
  const [key, fnData] = nodeToProcess.entries().next().value;
2492
- renderFunctions.push(`${key}(${fnData.args.join(", ")}) {`, ...indent([
2493
- "const context = new Context(this, parentContext)",
2498
+ renderFunctions.push(`\n${key}(${fnData.args.join(", ")}) {`, ...indent([
2499
+ "const context = new Context(this, parentContext);",
2494
2500
  ...fnData.fn(...fnData.args),
2495
2501
  "return context"
2496
2502
  ]), "}");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/compiler",
3
- "version": "0.6.15",
3
+ "version": "0.6.17",
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.6.15",
20
- "@xaendar/types": "0.6.15",
19
+ "@xaendar/common": "0.6.17",
20
+ "@xaendar/types": "0.6.17",
21
21
  "typescript": "^6.0.3"
22
22
  }
23
23
  }