@marko/language-tools 2.5.51 → 2.5.53

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,9 +2566,25 @@ 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);
2569
- this.#extractor.write(`const ${renderVar} = `);
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
+ }
2585
+ if (needsHoist || !isHTML) {
2586
+ this.#extractor.write(`const ${renderVar} = `);
2587
+ }
2570
2588
  }
2571
2589
  if (isHTML) {
2572
2590
  this.#extractor.write(`${varShared("renderNativeTag")}("`).copy(isEmptyRange2(tag.name) ? tagName : tag.name).write('")');
@@ -2586,25 +2604,12 @@ scope: ${scopeExpr}
2586
2604
  }
2587
2605
  this.#writeTagInputObject(tag);
2588
2606
  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 || ""});
2607
+ if (mutatedVars) {
2608
+ for (const binding of mutatedVars) {
2609
+ this.#extractor.write(
2610
+ `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
2611
  `
2602
- );
2603
- }
2604
- }
2605
- } else if (isHTML) {
2606
- this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
2607
- `);
2612
+ );
2608
2613
  }
2609
2614
  }
2610
2615
  }
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,9 +2529,25 @@ 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);
2532
- this.#extractor.write(`const ${renderVar} = `);
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
+ }
2548
+ if (needsHoist || !isHTML) {
2549
+ this.#extractor.write(`const ${renderVar} = `);
2550
+ }
2533
2551
  }
2534
2552
  if (isHTML) {
2535
2553
  this.#extractor.write(`${varShared("renderNativeTag")}("`).copy(isEmptyRange2(tag.name) ? tagName : tag.name).write('")');
@@ -2549,25 +2567,12 @@ scope: ${scopeExpr}
2549
2567
  }
2550
2568
  this.#writeTagInputObject(tag);
2551
2569
  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 || ""});
2570
+ if (mutatedVars) {
2571
+ for (const binding of mutatedVars) {
2572
+ this.#extractor.write(
2573
+ `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
2574
  `
2565
- );
2566
- }
2567
- }
2568
- } else if (isHTML) {
2569
- this.#extractor.copy(tag.var.value).write(` = ${varShared("el")}(${JSON.stringify(def.name)});
2570
- `);
2575
+ );
2571
2576
  }
2572
2577
  }
2573
2578
  }
@@ -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.53",
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"