@marko/language-tools 2.5.49 → 2.5.50

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.
Files changed (2) hide show
  1. package/marko.internal.d.ts +45 -18
  2. package/package.json +1 -1
@@ -37,7 +37,7 @@ declare global {
37
37
 
38
38
  export function attrTagNames<Tag>(
39
39
  tag: Tag,
40
- fn: (input: AttrTagNames<Marko.Input<Tag>>) => void,
40
+ fn: (input: AttrTagNames<InputFor<Tag>>) => void,
41
41
  ): void;
42
42
  export function nestedAttrTagNames<Input>(
43
43
  input: Input,
@@ -50,17 +50,7 @@ declare global {
50
50
  name: Name,
51
51
  ): Marko.NativeTags[Name]["return"]["value"];
52
52
 
53
- export function contentFor<Name>(
54
- tag: Name,
55
- ): [0] extends [1 & Name]
56
- ? DefaultBodyContentKey
57
- : Name extends { api: infer API }
58
- ? API extends "tags"
59
- ? "content"
60
- : API extends "class"
61
- ? "renderBody"
62
- : DefaultBodyContentKey
63
- : DefaultBodyContentKey;
53
+ export function contentFor<Name>(tag: Name): ContentFor<Name>;
64
54
 
65
55
  export const Template: new <Overrides = unknown>() => {
66
56
  [K in Exclude<
@@ -184,7 +174,7 @@ declare global {
184
174
  tag: Tag,
185
175
  fallback: Promise<{ default: Template }>,
186
176
  ): [0] extends [1 & Tag] ? Template : Tag;
187
- export function input<Name>(tag: Name): Marko.Input<Name>;
177
+ export function input<Name>(tag: Name): InputFor<Name>;
188
178
  export function renderDynamicTag<Name>(tag: Name): DynamicRenderer<Name>;
189
179
 
190
180
  export function returnTag<
@@ -408,16 +398,16 @@ declare global {
408
398
  ...path: Path
409
399
  ): <
410
400
  Name extends string,
411
- AttrTags extends [0] extends [1 & Tag]
401
+ AttrTags extends readonly ([0] extends [1 & Tag]
412
402
  ? Record<Name, Marko.AttrTag<unknown>>
413
403
  : Record<
414
404
  Name,
415
- Tag extends Marko.Input<infer Input>
405
+ Tag extends InputFor<infer Input>
416
406
  ? [0] extends [1 & Input]
417
407
  ? Marko.AttrTag<unknown>
418
408
  : AttrTagValue<Input, Path>
419
409
  : Marko.AttrTag<unknown>
420
- >[],
410
+ >)[],
421
411
  >(
422
412
  name: Name,
423
413
  ...attrTags: AttrTags
@@ -471,8 +461,8 @@ declare global {
471
461
  ...args: BodyParamsWithDefault<Body> &
472
462
  Relate<__marko_internal_input, BodyParamsWithDefault<Body>>
473
463
  ) => ReturnAndScope<
474
- Scopes<__marko_internal_input>,
475
- BodyReturnType<Body>
464
+ Scopes<__marko_internal_input extends [infer Input] ? Input : never>,
465
+ Body extends Marko.Body<any, infer Return> ? Return : never
476
466
  >;
477
467
  }
478
468
 
@@ -674,4 +664,41 @@ type DefaultBodyContentKey = keyof Exclude<
674
664
  Marko.Template<any, any> | Marko.Body<any, any> | string
675
665
  >;
676
666
 
667
+ type ContentFor<Name> = [0] extends [1 & Name]
668
+ ? DefaultBodyContentKey
669
+ : Name extends { api: infer API }
670
+ ? API extends "tags"
671
+ ? "content"
672
+ : API extends "class"
673
+ ? "renderBody"
674
+ : DefaultBodyContentKey
675
+ : DefaultBodyContentKey;
676
+
677
+ type InputFor<Name> = 0 extends 1 & Name
678
+ ? any
679
+ : Name extends string
680
+ ? Name extends keyof Marko.NativeTags
681
+ ? Marko.NativeTags[Name]["input"]
682
+ : Record<string, unknown>
683
+ : Name extends
684
+ | Marko.Template<infer Input, any>
685
+ | { _(): () => (input: infer Input) => any }
686
+ ? Input
687
+ : Name extends
688
+ | Marko.Body<infer Args, any>
689
+ | Record<
690
+ DefaultBodyContentKey,
691
+ undefined | null | false | Marko.Body<infer Args, any>
692
+ >
693
+ ? Args extends {
694
+ length: infer Length;
695
+ }
696
+ ? number extends Length
697
+ ? Args[0] | undefined
698
+ : 0 extends Length
699
+ ? undefined
700
+ : Args[0]
701
+ : never
702
+ : never;
703
+
677
704
  export {};
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.49",
4
+ "version": "2.5.50",
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"