@marko/language-tools 2.5.50 → 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,16 +2566,32 @@ 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) {
2572
2588
  this.#extractor.write(`${varShared("renderNativeTag")}("`).copy(isEmptyRange2(tag.name) ? tagName : tag.name).write('")');
2573
2589
  } else if (templateVar) {
2574
2590
  this.#extractor.write(
2575
- `${varShared(isTemplate ? "renderTemplate" : "renderDynamicTag")}(${templateVar})`
2591
+ `${varShared(isTemplate ? "renderTemplate" : "renderDynamicTag")}(${templateVar}`
2576
2592
  );
2593
+ this.#writeTagNameComment(tag);
2594
+ this.#extractor.write(")");
2577
2595
  } else {
2578
2596
  this.#extractor.write(varShared("missingTag"));
2579
2597
  }
@@ -2584,25 +2602,12 @@ scope: ${scopeExpr}
2584
2602
  }
2585
2603
  this.#writeTagInputObject(tag);
2586
2604
  this.#extractor.write(");\n");
2587
- if (tag.var) {
2588
- this.#extractor.write(`{const `);
2589
- this.#closeBrackets[this.#closeBrackets.length - 1]++;
2590
- if (renderVar) {
2591
- const mutatedVars = getMutatedVars(tag);
2592
- this.#copyWithMutationsReplaced(tag.var.value);
2593
- this.#extractor.write(` = ${renderVar}.return.${ATTR_UNAMED2};
2594
- `);
2595
- if (mutatedVars) {
2596
- for (const binding of mutatedVars) {
2597
- this.#extractor.write(
2598
- `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 || ""});
2599
2609
  `
2600
- );
2601
- }
2602
- }
2603
- } else if (isHTML) {
2604
- this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
2605
- `);
2610
+ );
2606
2611
  }
2607
2612
  }
2608
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,16 +2529,32 @@ 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) {
2535
2551
  this.#extractor.write(`${varShared("renderNativeTag")}("`).copy(isEmptyRange2(tag.name) ? tagName : tag.name).write('")');
2536
2552
  } else if (templateVar) {
2537
2553
  this.#extractor.write(
2538
- `${varShared(isTemplate ? "renderTemplate" : "renderDynamicTag")}(${templateVar})`
2554
+ `${varShared(isTemplate ? "renderTemplate" : "renderDynamicTag")}(${templateVar}`
2539
2555
  );
2556
+ this.#writeTagNameComment(tag);
2557
+ this.#extractor.write(")");
2540
2558
  } else {
2541
2559
  this.#extractor.write(varShared("missingTag"));
2542
2560
  }
@@ -2547,25 +2565,12 @@ scope: ${scopeExpr}
2547
2565
  }
2548
2566
  this.#writeTagInputObject(tag);
2549
2567
  this.#extractor.write(");\n");
2550
- if (tag.var) {
2551
- this.#extractor.write(`{const `);
2552
- this.#closeBrackets[this.#closeBrackets.length - 1]++;
2553
- if (renderVar) {
2554
- const mutatedVars = getMutatedVars(tag);
2555
- this.#copyWithMutationsReplaced(tag.var.value);
2556
- this.#extractor.write(` = ${renderVar}.return.${ATTR_UNAMED2};
2557
- `);
2558
- if (mutatedVars) {
2559
- for (const binding of mutatedVars) {
2560
- this.#extractor.write(
2561
- `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 || ""});
2562
2572
  `
2563
- );
2564
- }
2565
- }
2566
- } else if (isHTML) {
2567
- this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
2568
- `);
2573
+ );
2569
2574
  }
2570
2575
  }
2571
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.50",
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"