@marko/language-tools 2.4.0 → 2.4.2

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
@@ -1964,7 +1964,7 @@ constructor(_?: Return) {}
1964
1964
  this.#extractor.copy(returned);
1965
1965
  this.#extractor.write(");\n");
1966
1966
  }
1967
- #writeChildren(parent, children) {
1967
+ #writeChildren(parent, children, skipRenderId = false) {
1968
1968
  var _a, _b;
1969
1969
  const last = children.length - 1;
1970
1970
  let returnTag;
@@ -1979,27 +1979,31 @@ constructor(_?: Return) {}
1979
1979
  break;
1980
1980
  case "if": {
1981
1981
  const alternates = IF_TAG_ALTERNATES.get(child);
1982
- let renderId = this.#getRenderId(child);
1983
- if (!renderId && alternates) {
1984
- for (const { node } of alternates) {
1985
- if (renderId = this.#getRenderId(node)) break;
1982
+ let renderId;
1983
+ if (!skipRenderId) {
1984
+ renderId = this.#getRenderId(child);
1985
+ if (!renderId && alternates) {
1986
+ for (const { node } of alternates) {
1987
+ if (renderId = this.#getRenderId(node)) break;
1988
+ }
1986
1989
  }
1987
- }
1988
- if (renderId) {
1989
- this.#extractor.write(
1990
- `${varShared("assertRendered")}(${varShared(
1991
- "rendered"
1992
- )}, ${renderId}, (() => {
1990
+ if (renderId) {
1991
+ this.#extractor.write(
1992
+ `${varShared("assertRendered")}(${varShared(
1993
+ "rendered"
1994
+ )}, ${renderId}, (() => {
1993
1995
  `
1994
- );
1996
+ );
1997
+ }
1995
1998
  }
1996
1999
  this.#writeComments(child);
1997
2000
  this.#extractor.write("if (").copy(
1998
2001
  this.#getRangeWithoutTrailingComma((_a = child.args) == null ? void 0 : _a.value) || this.#getAttrValue(child, ATTR_UNAMED2) || "undefined"
1999
2002
  ).write(") {\n");
2000
- if (child.body) {
2003
+ const ifBody = this.#processBody(child);
2004
+ if (ifBody == null ? void 0 : ifBody.renderBody) {
2001
2005
  const localBindings = getHoistSources(child);
2002
- this.#writeChildren(child, child.body);
2006
+ this.#writeChildren(child, ifBody.renderBody, true);
2003
2007
  if (localBindings) {
2004
2008
  this.#extractor.write("return {\nscope:");
2005
2009
  this.#writeObjectKeys(localBindings);
@@ -2018,9 +2022,10 @@ constructor(_?: Return) {}
2018
2022
  } else {
2019
2023
  this.#extractor.write("\n} else if (undefined) {\n");
2020
2024
  }
2021
- if (node.body) {
2025
+ const alternateBody = this.#processBody(node);
2026
+ if (alternateBody == null ? void 0 : alternateBody.renderBody) {
2022
2027
  const localBindings = getHoistSources(node);
2023
- this.#writeChildren(node, node.body);
2028
+ this.#writeChildren(node, alternateBody.renderBody, true);
2024
2029
  if (localBindings) {
2025
2030
  this.#extractor.write("return {\nscope:");
2026
2031
  this.#writeObjectKeys(localBindings);
@@ -2487,23 +2492,22 @@ const attrTags = ${varShared(
2487
2492
  }
2488
2493
  #writeTagInputObject(tag) {
2489
2494
  if (!tag.params) this.#writeComments(tag);
2490
- const body = this.#processBody(tag);
2491
- let writeInputObj = true;
2492
2495
  let hasInput = false;
2496
+ this.#extractor.write("{\n");
2493
2497
  if (tag.args) {
2494
2498
  hasInput = true;
2495
- this.#extractor.copy(tag.args.value);
2496
- if (body || tag.attrs || tag.shorthandId || tag.shorthandClassNames) {
2497
- this.#extractor.write(",\n{\n");
2498
- } else {
2499
- writeInputObj = false;
2500
- }
2501
- } else {
2502
- this.#extractor.write("{\n");
2499
+ this.#extractor.write("[").copy({
2500
+ start: tag.args.start,
2501
+ end: tag.args.start + 1
2502
+ }).write('"value"').copy({
2503
+ start: tag.args.end - 1,
2504
+ end: tag.args.end
2505
+ }).write(`]: ${varShared("tuple")}(`).copy(tag.args.value).write(")").write(",\n");
2503
2506
  }
2504
2507
  if (this.#writeAttrs(tag)) {
2505
2508
  hasInput = true;
2506
2509
  }
2510
+ const body = this.#processBody(tag);
2507
2511
  let hasRenderBody = false;
2508
2512
  if (body) {
2509
2513
  hasInput = true;
@@ -2549,9 +2553,7 @@ const attrTags = ${varShared(
2549
2553
  if (!hasInput) {
2550
2554
  this.#writeTagNameComment(tag);
2551
2555
  }
2552
- if (writeInputObj) {
2553
- this.#extractor.write("\n}");
2554
- }
2556
+ this.#extractor.write("\n}");
2555
2557
  }
2556
2558
  #writeObjectKeys(keys) {
2557
2559
  this.#extractor.write("{");
package/dist/index.mjs CHANGED
@@ -1928,7 +1928,7 @@ constructor(_?: Return) {}
1928
1928
  this.#extractor.copy(returned);
1929
1929
  this.#extractor.write(");\n");
1930
1930
  }
1931
- #writeChildren(parent, children) {
1931
+ #writeChildren(parent, children, skipRenderId = false) {
1932
1932
  var _a, _b;
1933
1933
  const last = children.length - 1;
1934
1934
  let returnTag;
@@ -1943,27 +1943,31 @@ constructor(_?: Return) {}
1943
1943
  break;
1944
1944
  case "if": {
1945
1945
  const alternates = IF_TAG_ALTERNATES.get(child);
1946
- let renderId = this.#getRenderId(child);
1947
- if (!renderId && alternates) {
1948
- for (const { node } of alternates) {
1949
- if (renderId = this.#getRenderId(node)) break;
1946
+ let renderId;
1947
+ if (!skipRenderId) {
1948
+ renderId = this.#getRenderId(child);
1949
+ if (!renderId && alternates) {
1950
+ for (const { node } of alternates) {
1951
+ if (renderId = this.#getRenderId(node)) break;
1952
+ }
1950
1953
  }
1951
- }
1952
- if (renderId) {
1953
- this.#extractor.write(
1954
- `${varShared("assertRendered")}(${varShared(
1955
- "rendered"
1956
- )}, ${renderId}, (() => {
1954
+ if (renderId) {
1955
+ this.#extractor.write(
1956
+ `${varShared("assertRendered")}(${varShared(
1957
+ "rendered"
1958
+ )}, ${renderId}, (() => {
1957
1959
  `
1958
- );
1960
+ );
1961
+ }
1959
1962
  }
1960
1963
  this.#writeComments(child);
1961
1964
  this.#extractor.write("if (").copy(
1962
1965
  this.#getRangeWithoutTrailingComma((_a = child.args) == null ? void 0 : _a.value) || this.#getAttrValue(child, ATTR_UNAMED2) || "undefined"
1963
1966
  ).write(") {\n");
1964
- if (child.body) {
1967
+ const ifBody = this.#processBody(child);
1968
+ if (ifBody == null ? void 0 : ifBody.renderBody) {
1965
1969
  const localBindings = getHoistSources(child);
1966
- this.#writeChildren(child, child.body);
1970
+ this.#writeChildren(child, ifBody.renderBody, true);
1967
1971
  if (localBindings) {
1968
1972
  this.#extractor.write("return {\nscope:");
1969
1973
  this.#writeObjectKeys(localBindings);
@@ -1982,9 +1986,10 @@ constructor(_?: Return) {}
1982
1986
  } else {
1983
1987
  this.#extractor.write("\n} else if (undefined) {\n");
1984
1988
  }
1985
- if (node.body) {
1989
+ const alternateBody = this.#processBody(node);
1990
+ if (alternateBody == null ? void 0 : alternateBody.renderBody) {
1986
1991
  const localBindings = getHoistSources(node);
1987
- this.#writeChildren(node, node.body);
1992
+ this.#writeChildren(node, alternateBody.renderBody, true);
1988
1993
  if (localBindings) {
1989
1994
  this.#extractor.write("return {\nscope:");
1990
1995
  this.#writeObjectKeys(localBindings);
@@ -2451,23 +2456,22 @@ const attrTags = ${varShared(
2451
2456
  }
2452
2457
  #writeTagInputObject(tag) {
2453
2458
  if (!tag.params) this.#writeComments(tag);
2454
- const body = this.#processBody(tag);
2455
- let writeInputObj = true;
2456
2459
  let hasInput = false;
2460
+ this.#extractor.write("{\n");
2457
2461
  if (tag.args) {
2458
2462
  hasInput = true;
2459
- this.#extractor.copy(tag.args.value);
2460
- if (body || tag.attrs || tag.shorthandId || tag.shorthandClassNames) {
2461
- this.#extractor.write(",\n{\n");
2462
- } else {
2463
- writeInputObj = false;
2464
- }
2465
- } else {
2466
- this.#extractor.write("{\n");
2463
+ this.#extractor.write("[").copy({
2464
+ start: tag.args.start,
2465
+ end: tag.args.start + 1
2466
+ }).write('"value"').copy({
2467
+ start: tag.args.end - 1,
2468
+ end: tag.args.end
2469
+ }).write(`]: ${varShared("tuple")}(`).copy(tag.args.value).write(")").write(",\n");
2467
2470
  }
2468
2471
  if (this.#writeAttrs(tag)) {
2469
2472
  hasInput = true;
2470
2473
  }
2474
+ const body = this.#processBody(tag);
2471
2475
  let hasRenderBody = false;
2472
2476
  if (body) {
2473
2477
  hasInput = true;
@@ -2513,9 +2517,7 @@ const attrTags = ${varShared(
2513
2517
  if (!hasInput) {
2514
2518
  this.#writeTagNameComment(tag);
2515
2519
  }
2516
- if (writeInputObj) {
2517
- this.#extractor.write("\n}");
2518
- }
2520
+ this.#extractor.write("\n}");
2519
2521
  }
2520
2522
  #writeObjectKeys(keys) {
2521
2523
  this.#extractor.write("{");
@@ -310,10 +310,14 @@ declare global {
310
310
  ? NativeTagRenderer<Name>
311
311
  : [Name] extends [AnyMarkoBody]
312
312
  ? BodyRenderer<Name>
313
- : [Name] extends [
314
- { renderBody?: infer Name extends AnyMarkoBody },
315
- ]
316
- ? BodyRenderer<Name>
313
+ : [Name] extends [{ renderBody?: AnyMarkoBody }]
314
+ ? [Name["renderBody"]] extends [AnyMarkoBody]
315
+ ? BodyRenderer<Name["renderBody"]>
316
+ : BaseRenderer<
317
+ RenderBodyInput<
318
+ BodyParameters<Exclude<Name["renderBody"], void>>
319
+ >
320
+ >
317
321
  : DefaultRenderer;
318
322
 
319
323
  export type TemplateRenderer<Template> = Template extends {
@@ -345,8 +349,12 @@ declare global {
345
349
  export interface BodyRenderer<Body extends AnyMarkoBody> {
346
350
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
347
351
  (): () => <__marko_internal_input extends unknown>(
348
- ...args: BodyParamsWithDefault<Body> &
349
- Relate<__marko_internal_input, BodyParamsWithDefault<Body>>
352
+ input: Marko.Directives &
353
+ RenderBodyInput<BodyParameters<Body>> &
354
+ Relate<
355
+ __marko_internal_input,
356
+ Marko.Directives & RenderBodyInput<BodyParameters<Body>>
357
+ >,
350
358
  ) => ReturnAndScope<
351
359
  Scopes<__marko_internal_input>,
352
360
  BodyReturnType<Body>
@@ -393,12 +401,15 @@ type ReturnAndScope<Scope, Return> = {
393
401
  scope: Scope;
394
402
  };
395
403
 
396
- type BodyParamsWithDefault<Body extends AnyMarkoBody> =
397
- Body extends Marko.Body<infer Params, any>
398
- ? Params extends []
399
- ? [input?: Record<string, never>]
400
- : Params
401
- : never;
404
+ type RenderBodyInput<Args extends readonly unknown[]> = Args extends {
405
+ length: infer Length;
406
+ }
407
+ ? number extends Length
408
+ ? { value?: Args }
409
+ : 0 extends Length
410
+ ? { value?: [] }
411
+ : { value: Args }
412
+ : never;
402
413
 
403
414
  type Scopes<Input> = [0] extends [1 & Input]
404
415
  ? 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.4.0",
4
+ "version": "2.4.2",
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"