@marko/language-tools 2.5.51 → 2.5.52

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.
package/dist/index.js CHANGED
@@ -2528,6 +2528,8 @@ scope: ${scopeExpr}
2528
2528
  const def = tagName ? this.#lookup.getTag(tagName) : void 0;
2529
2529
  const importPath = resolveTagImport(this.#filename, def);
2530
2530
  const isHTML = !importPath && (def == null ? void 0 : def.html);
2531
+ const needsHoist = hasHoists(tag);
2532
+ const mutatedVars = tag.var && !isHTML && getMutatedVars(tag);
2531
2533
  let isTemplate = false;
2532
2534
  let renderVar;
2533
2535
  let templateVar;
@@ -2564,8 +2566,22 @@ scope: ${scopeExpr}
2564
2566
  this.#extractor.write(";\n");
2565
2567
  }
2566
2568
  }
2567
- if (!isHTML && tag.var || hasHoists(tag)) {
2569
+ if (needsHoist || tag.var) {
2568
2570
  renderVar = this.#getRenderVar(tag, true);
2571
+ if (tag.var) {
2572
+ this.#closeBrackets[this.#closeBrackets.length - 1]++;
2573
+ this.#extractor.write("{const ");
2574
+ if (isHTML) {
2575
+ this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
2576
+ `);
2577
+ } else {
2578
+ this.#copyWithMutationsReplaced(tag.var.value);
2579
+ this.#extractor.write(
2580
+ ` = ${varShared("returned")}(() => ${renderVar});
2581
+ `
2582
+ );
2583
+ }
2584
+ }
2569
2585
  this.#extractor.write(`const ${renderVar} = `);
2570
2586
  }
2571
2587
  if (isHTML) {
@@ -2586,25 +2602,12 @@ scope: ${scopeExpr}
2586
2602
  }
2587
2603
  this.#writeTagInputObject(tag);
2588
2604
  this.#extractor.write(");\n");
2589
- if (tag.var) {
2590
- this.#extractor.write(`{const `);
2591
- this.#closeBrackets[this.#closeBrackets.length - 1]++;
2592
- if (renderVar) {
2593
- const mutatedVars = getMutatedVars(tag);
2594
- this.#copyWithMutationsReplaced(tag.var.value);
2595
- this.#extractor.write(` = ${renderVar}.return.${ATTR_UNAMED2};
2596
- `);
2597
- if (mutatedVars) {
2598
- for (const binding of mutatedVars) {
2599
- this.#extractor.write(
2600
- `const ${varLocal(`change__${binding.name}`)} = ${varShared("change")}(${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${renderVar}.return${binding.objectPath || ""});
2605
+ if (mutatedVars) {
2606
+ for (const binding of mutatedVars) {
2607
+ this.#extractor.write(
2608
+ `const ${varLocal(`change__${binding.name}`)} = ${varShared("change")}(${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${renderVar}.return${binding.objectPath || ""});
2601
2609
  `
2602
- );
2603
- }
2604
- }
2605
- } else if (isHTML) {
2606
- this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
2607
- `);
2610
+ );
2608
2611
  }
2609
2612
  }
2610
2613
  }
package/dist/index.mjs CHANGED
@@ -2491,6 +2491,8 @@ scope: ${scopeExpr}
2491
2491
  const def = tagName ? this.#lookup.getTag(tagName) : void 0;
2492
2492
  const importPath = resolveTagImport(this.#filename, def);
2493
2493
  const isHTML = !importPath && (def == null ? void 0 : def.html);
2494
+ const needsHoist = hasHoists(tag);
2495
+ const mutatedVars = tag.var && !isHTML && getMutatedVars(tag);
2494
2496
  let isTemplate = false;
2495
2497
  let renderVar;
2496
2498
  let templateVar;
@@ -2527,8 +2529,22 @@ scope: ${scopeExpr}
2527
2529
  this.#extractor.write(";\n");
2528
2530
  }
2529
2531
  }
2530
- if (!isHTML && tag.var || hasHoists(tag)) {
2532
+ if (needsHoist || tag.var) {
2531
2533
  renderVar = this.#getRenderVar(tag, true);
2534
+ if (tag.var) {
2535
+ this.#closeBrackets[this.#closeBrackets.length - 1]++;
2536
+ this.#extractor.write("{const ");
2537
+ if (isHTML) {
2538
+ this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
2539
+ `);
2540
+ } else {
2541
+ this.#copyWithMutationsReplaced(tag.var.value);
2542
+ this.#extractor.write(
2543
+ ` = ${varShared("returned")}(() => ${renderVar});
2544
+ `
2545
+ );
2546
+ }
2547
+ }
2532
2548
  this.#extractor.write(`const ${renderVar} = `);
2533
2549
  }
2534
2550
  if (isHTML) {
@@ -2549,25 +2565,12 @@ scope: ${scopeExpr}
2549
2565
  }
2550
2566
  this.#writeTagInputObject(tag);
2551
2567
  this.#extractor.write(");\n");
2552
- if (tag.var) {
2553
- this.#extractor.write(`{const `);
2554
- this.#closeBrackets[this.#closeBrackets.length - 1]++;
2555
- if (renderVar) {
2556
- const mutatedVars = getMutatedVars(tag);
2557
- this.#copyWithMutationsReplaced(tag.var.value);
2558
- this.#extractor.write(` = ${renderVar}.return.${ATTR_UNAMED2};
2559
- `);
2560
- if (mutatedVars) {
2561
- for (const binding of mutatedVars) {
2562
- this.#extractor.write(
2563
- `const ${varLocal(`change__${binding.name}`)} = ${varShared("change")}(${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${renderVar}.return${binding.objectPath || ""});
2568
+ if (mutatedVars) {
2569
+ for (const binding of mutatedVars) {
2570
+ this.#extractor.write(
2571
+ `const ${varLocal(`change__${binding.name}`)} = ${varShared("change")}(${JSON.stringify(binding.name) + (binding.sourceName && binding.sourceName !== binding.name ? `, ${JSON.stringify(binding.sourceName)}` : "")}, ${renderVar}.return${binding.objectPath || ""});
2564
2572
  `
2565
- );
2566
- }
2567
- }
2568
- } else if (isHTML) {
2569
- this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
2570
- `);
2573
+ );
2571
2574
  }
2572
2575
  }
2573
2576
  }
@@ -24,6 +24,10 @@ declare global {
24
24
  override: Override,
25
25
  ): [0] extends [1 & Override] ? Marko.Global : Override;
26
26
 
27
+ export function returned<T>(
28
+ rendered: () => T,
29
+ ): T extends { return: { value: infer Returned } } ? Returned : never;
30
+
27
31
  export function hoist<T>(
28
32
  value: () => T,
29
33
  ): T extends () => infer R ? T & Iterable<R> : never;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/language-tools",
3
3
  "description": "Marko Language Tools",
4
- "version": "2.5.51",
4
+ "version": "2.5.52",
5
5
  "bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
6
6
  "peerDependencies": {
7
7
  "@marko/compiler": "^5.28.4"