@marko/language-tools 2.5.4 → 2.5.6

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.
@@ -40,6 +40,19 @@ declare global {
40
40
  returns: Record<number, never>;
41
41
  };
42
42
 
43
+ export const tags: Record<number, unknown>;
44
+ export const content: DefaultBodyContentKey;
45
+
46
+ export function contentFor<Name>(
47
+ tag: Name,
48
+ ): Name extends { api: infer API }
49
+ ? API extends "tags"
50
+ ? "content"
51
+ : API extends "class"
52
+ ? "renderBody"
53
+ : DefaultBodyContentKey
54
+ : DefaultBodyContentKey;
55
+
43
56
  export const Template: new <Overrides = unknown>() => {
44
57
  [K in Exclude<
45
58
  keyof Marko.Template,
@@ -82,6 +95,12 @@ declare global {
82
95
  > &
83
96
  Record<any, never>;
84
97
 
98
+ export function assertTag<Index extends number, Tags, Tag>(
99
+ tags: Tags,
100
+ index: Index,
101
+ tag: Tag,
102
+ ): asserts tags is Tags & Record<Index, Tag>;
103
+
85
104
  export function assertRendered<Index extends number, Rendered, Result>(
86
105
  rendered: Rendered,
87
106
  index: Index,
@@ -134,65 +153,75 @@ declare global {
134
153
  : (...args: any) => any; // If typescript ever actually supports partial application maybe we do this.
135
154
 
136
155
  export function renderTemplate<Name extends Marko.Template>(
137
- imported: Promise<{ default: Name }>,
156
+ template: Name,
138
157
  ): TemplateRenderer<Name>;
139
158
  export function renderNativeTag<Name extends string>(
140
159
  tag: Name,
141
160
  ): NativeTagRenderer<Name>;
142
161
  export const missingTag: DefaultRenderer;
143
- export function renderPreferLocal<Name, Fallback>(
144
- name: Name,
145
- fallback: Fallback,
146
- ): [0] extends [1 & Name] ? Fallback : DynamicRenderer<Name>;
162
+ export function resolveTemplate<Template>(
163
+ imported: Promise<{ default: Template }>,
164
+ ): Template;
165
+ export function fallbackTemplate<Tag, Template>(
166
+ tag: Tag,
167
+ fallback: Promise<{ default: Template }>,
168
+ ): [0] extends [1 & Tag] ? Template : Tag;
169
+ export function input<Name>(tag: Name): Marko.Input<Name>;
147
170
  export function renderDynamicTag<Name>(tag: Name): DynamicRenderer<Name>;
148
171
 
149
172
  export function returnTag<
150
173
  Input extends { value: unknown; valueChange?: (value: any) => void },
151
174
  >(input: Input): Input;
152
175
 
153
- export function forTag<
176
+ export function forOfTag<
154
177
  Value,
155
178
  Item extends Value extends
156
179
  | readonly (infer Item)[]
157
180
  | Iterable<infer Item>
158
181
  ? Item
159
182
  : unknown,
160
- RenderBody extends Marko.Body<
183
+ BodyContent extends Marko.Body<
161
184
  [item: Item, index: number, all: Value],
162
185
  void
163
186
  >,
164
- >(input: {
165
- of: Value;
166
- renderBody: RenderBody;
167
- by?: (item: Item, index: number) => string;
168
- }): ReturnAndScope<RenderBodyScope<RenderBody>, void>;
187
+ >(
188
+ input: {
189
+ of: Value | false | void | null;
190
+ by?: (item: Item, index: number) => string;
191
+ },
192
+ content: BodyContent,
193
+ ): ReturnAndScope<BodyContentScope<BodyContent>, void>;
169
194
 
170
- export function forTag<
195
+ export function forInTag<
171
196
  Value,
172
- RenderBody extends Marko.Body<
197
+ BodyContent extends Marko.Body<
173
198
  [key: keyof Value, value: Value[keyof Value]],
174
199
  void
175
200
  >,
176
- >(input: {
177
- in: Value;
178
- renderBody: RenderBody;
179
- by?: (value: Value[keyof Value], key: keyof Value) => string;
180
- }): ReturnAndScope<RenderBodyScope<RenderBody>, void>;
201
+ >(
202
+ input: {
203
+ in: Value | false | void | null;
204
+ by?: (value: Value[keyof Value], key: keyof Value) => string;
205
+ },
206
+ content: BodyContent,
207
+ ): ReturnAndScope<BodyContentScope<BodyContent>, void>;
181
208
 
182
- export function forTag<
209
+ export function forToTag<
183
210
  From extends void | number,
184
211
  To extends number,
185
212
  Step extends void | number,
186
- RenderBody extends Marko.Body<[index: number], void>,
187
- >(input: {
188
- from?: From;
189
- to: To;
190
- step?: Step;
191
- renderBody: RenderBody;
192
- by?: (index: number) => string;
193
- }): ReturnAndScope<RenderBodyScope<RenderBody>, void>;
194
-
195
- export function forTag<RenderBody extends AnyMarkoBody>(
213
+ BodyContent extends Marko.Body<[index: number], void>,
214
+ >(
215
+ input: {
216
+ from?: From;
217
+ to: To;
218
+ step?: Step;
219
+ by?: (index: number) => string;
220
+ },
221
+ content: BodyContent,
222
+ ): ReturnAndScope<BodyContentScope<BodyContent>, void>;
223
+
224
+ export function forTag<BodyContent extends AnyMarkoBody>(
196
225
  input: (
197
226
  | {
198
227
  from?: number;
@@ -200,22 +229,23 @@ declare global {
200
229
  step?: number;
201
230
  }
202
231
  | {
203
- in: unknown;
232
+ in: object | false | void | null;
204
233
  }
205
234
  | {
206
- of: readonly unknown[] | Iterable<unknown>;
235
+ of: Iterable<unknown> | readonly unknown[] | false | void | null;
207
236
  }
208
- ) & { renderBody?: RenderBody; by?: (...args: unknown[]) => string },
209
- ): ReturnAndScope<RenderBodyScope<RenderBody>, void>;
237
+ ) & { by?: (...args: unknown[]) => string },
238
+ content: BodyContent,
239
+ ): ReturnAndScope<BodyContentScope<BodyContent>, void>;
210
240
 
211
- export function forAttrTag<
241
+ export function forOfAttrTag<
212
242
  Value extends Iterable<any> | readonly any[],
213
243
  const Return,
214
244
  >(
215
245
  input: {
216
- of: Value;
246
+ of: Value | false | void | null;
217
247
  },
218
- renderBody: (
248
+ content: (
219
249
  value: Value extends readonly (infer Item)[] | Iterable<infer Item>
220
250
  ? Item
221
251
  : unknown,
@@ -230,11 +260,11 @@ declare global {
230
260
  : never;
231
261
  };
232
262
 
233
- export function forAttrTag<Value extends object, const Return>(
263
+ export function forInAttrTag<Value extends object, const Return>(
234
264
  input: {
235
- in: Value;
265
+ in: Value | false | void | null;
236
266
  },
237
- renderBody: (key: keyof Value, value: Value[keyof Value]) => Return,
267
+ content: (key: keyof Value, value: Value[keyof Value]) => Return,
238
268
  ): {
239
269
  [Key in keyof Return]: Return[Key] extends
240
270
  | readonly (infer Item)[]
@@ -243,7 +273,7 @@ declare global {
243
273
  : never;
244
274
  };
245
275
 
246
- export function forAttrTag<
276
+ export function forToAttrTag<
247
277
  From extends void | number,
248
278
  To extends number,
249
279
  Step extends void | number,
@@ -254,7 +284,7 @@ declare global {
254
284
  to: To;
255
285
  step?: Step;
256
286
  },
257
- renderBody: (index: number) => Return,
287
+ content: (index: number) => Return,
258
288
  ): {
259
289
  [Key in keyof Return]: Return[Key] extends
260
290
  | readonly (infer Item)[]
@@ -269,21 +299,21 @@ declare global {
269
299
  : never;
270
300
  };
271
301
 
272
- export function forAttrTag<const Return>(attrs: {
302
+ export function forAttrTag<const Return>(
273
303
  input:
274
304
  | {
275
- of: any;
305
+ of: Iterable<unknown> | readonly unknown[] | false | void | null;
276
306
  }
277
307
  | {
278
- in: any;
308
+ in: object;
279
309
  }
280
310
  | {
281
- from?: any;
282
- to: any;
283
- step?: any;
284
- };
285
- renderBody: (index: number) => Return;
286
- }): {
311
+ from?: number;
312
+ to: number;
313
+ step?: number;
314
+ },
315
+ content: (...args: unknown[]) => Return,
316
+ ): {
287
317
  [Key in keyof Return]: Return[Key] extends
288
318
  | readonly (infer Item)[]
289
319
  | (infer Item extends Record<PropertyKey, any>)
@@ -294,10 +324,18 @@ declare global {
294
324
  export function mergeAttrTags<Attrs extends readonly any[]>(
295
325
  ...attrs: Attrs
296
326
  ): MergeAttrTags<Attrs>;
297
-
298
- export function repeatedAttrTag<AttrTag>(
299
- ...attrTags: Marko.AttrTag<AttrTag>[]
300
- ): AttrTag;
327
+ export function attrTags<T>(
328
+ type?: T,
329
+ ): <AttrTag>(
330
+ attrTags: Relate<
331
+ AttrTag,
332
+ [0] extends [1 & T]
333
+ ? Marko.AttrTag<unknown>
334
+ : T extends Marko.AttrTag<infer Type>
335
+ ? Marko.AttrTag<Type>
336
+ : Marko.AttrTag<unknown>
337
+ >[],
338
+ ) => AttrTag;
301
339
 
302
340
  // TODO: this could be improved.
303
341
  // currently falls back to DefaultRenderer too eagerly.
@@ -309,12 +347,14 @@ declare global {
309
347
  ? NativeTagRenderer<Name>
310
348
  : [Name] extends [AnyMarkoBody]
311
349
  ? BodyRenderer<Name>
312
- : [Name] extends [{ renderBody?: AnyMarkoBody }]
313
- ? [Name["renderBody"]] extends [AnyMarkoBody]
314
- ? BodyRenderer<Name["renderBody"]>
350
+ : [Name] extends [{ [BodyContentKey]?: AnyMarkoBody }]
351
+ ? [Name[DefaultBodyContentKey]] extends [AnyMarkoBody]
352
+ ? BodyRenderer<Name[DefaultBodyContentKey]>
315
353
  : BaseRenderer<
316
- RenderBodyInput<
317
- BodyParameters<Exclude<Name["renderBody"], void>>
354
+ BodyContentInput<
355
+ BodyParameters<
356
+ Exclude<Name[DefaultBodyContentKey], void>
357
+ >
318
358
  >
319
359
  >
320
360
  : DefaultRenderer;
@@ -349,10 +389,10 @@ declare global {
349
389
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
350
390
  (): () => <__marko_internal_input extends unknown>(
351
391
  input: Marko.Directives &
352
- RenderBodyInput<BodyParameters<Body>> &
392
+ BodyContentInput<BodyParameters<Body>> &
353
393
  Relate<
354
394
  __marko_internal_input,
355
- Marko.Directives & RenderBodyInput<BodyParameters<Body>>
395
+ Marko.Directives & BodyContentInput<BodyParameters<Body>>
356
396
  >,
357
397
  ) => ReturnAndScope<
358
398
  Scopes<__marko_internal_input>,
@@ -389,7 +429,7 @@ declare abstract class MarkoReturn<Return> {
389
429
 
390
430
  type AnyMarkoBody = Marko.Body<any, any>;
391
431
 
392
- type RenderBodyScope<RenderBody> = RenderBody extends (...params: any) => {
432
+ type BodyContentScope<BodyContent> = BodyContent extends (...params: any) => {
393
433
  [Marko._.scope]: infer Scope;
394
434
  }
395
435
  ? Scope
@@ -400,7 +440,7 @@ type ReturnAndScope<Scope, Return> = {
400
440
  scope: Scope;
401
441
  };
402
442
 
403
- type RenderBodyInput<Args extends readonly unknown[]> = Args extends {
443
+ type BodyContentInput<Args extends readonly unknown[]> = Args extends {
404
444
  length: infer Length;
405
445
  }
406
446
  ? number extends Length
@@ -528,4 +568,9 @@ type UnionToIntersection<T> = (T extends any ? (_: T) => any : never) extends (
528
568
  ? U
529
569
  : never;
530
570
 
571
+ type DefaultBodyContentKey = keyof Exclude<
572
+ Marko.Renderable,
573
+ Marko.Template<any, any> | Marko.Body<any, any> | string
574
+ >;
575
+
531
576
  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.4",
4
+ "version": "2.5.6",
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"
@@ -14,10 +14,10 @@
14
14
  },
15
15
  "devDependencies": {
16
16
  "@babel/code-frame": "^7.26.2",
17
- "@marko/compiler": "^5.39.4",
17
+ "@marko/compiler": "^5.39.6",
18
18
  "@types/babel__code-frame": "^7.0.6",
19
19
  "@typescript/vfs": "^1.6.0",
20
- "marko": "^5.37.4",
20
+ "marko": "^5.37.7",
21
21
  "mitata": "^1.0.21",
22
22
  "tsx": "^4.19.2"
23
23
  },