@alloy-js/typescript 0.19.0-dev.1 → 0.19.0-dev.3

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.
@@ -55,7 +55,7 @@ export interface DeclarationProps extends Omit<BaseDeclarationProps, "name"> {
55
55
  /**
56
56
  * Create a TypeScript declaration. Generally, this component shouldn't be used
57
57
  * directly, and instead prefer components for specific declarations, e.g.
58
- * {@link EnumDeclaration}, {@link InterfaceDeclaration},
58
+ * {@link EnumDeclaration}, {@link (InterfaceDeclaration:function)},
59
59
  * {@link TypeDeclaration}, etc.
60
60
  *
61
61
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"Declaration.d.ts","sourceRoot":"","sources":["../../../src/components/Declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAGR,iBAAiB,EACjB,MAAM,EACP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAmB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAiB,MAAM,qBAAqB,CAAC;AAYpE,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE3B;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAE1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEnC;;OAEG;IACH,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,gBAAiB,SAAQ,IAA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E9B;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAwDlD"}
@@ -9,12 +9,10 @@ import { TSOutputSymbol, TSSymbolFlags } from "../symbols/index.js";
9
9
  import { PrivateScopeContext } from "../context/private-scope.js";
10
10
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
11
 
12
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
-
14
12
  /**
15
13
  * Create a TypeScript declaration. Generally, this component shouldn't be used
16
14
  * directly, and instead prefer components for specific declarations, e.g.
17
- * {@link EnumDeclaration}, {@link InterfaceDeclaration},
15
+ * {@link EnumDeclaration}, {@link (InterfaceDeclaration:function)},
18
16
  * {@link TypeDeclaration}, etc.
19
17
  *
20
18
  * @remarks
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionBase.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionBase.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAEV,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAQrE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,oCAAoC;AACpC,MAAM,WAAW,uBAAuB;IACtC,iBAAiB;IACjB,QAAQ,CAAC,UAAU,CAAC,EAAE,mBAAmB,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,mBAAmB;IACnB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,iEAAiE;AACjE,MAAM,WAAW,2BAA2B;IAC1C,iBAAiB;IACjB,QAAQ,CAAC,UAAU,CAAC,EAAE,mBAAmB,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,mBAAmB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GAAG,MAAM,EAAE,CAAC;IACvD,mBAAmB;IACnB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,iBAAiB;IACjB,UAAU,CAAC,EAAE,uBAAuB,EAAE,GAAG,MAAM,EAAE,CAAC;IAClD,mBAAmB;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,sIAKxB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,kJAuB9B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,0JAuBlC,CAAC;AA8GF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,0IAkC1B,CAAC;AAsBF,wBAAgB,aAAa,CAC3B,UAAU,EAAE,QAAQ,GAAG,SAAS,EAChC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAqB,YAKhD"}
@@ -127,6 +127,17 @@ function parameter(param) {
127
127
  }
128
128
  });
129
129
  }
130
+ }), _$createComponent(Show, {
131
+ get when() {
132
+ return !!param.default;
133
+ },
134
+ get children() {
135
+ return [" = ", _$createComponent(SymbolSlot, {
136
+ get children() {
137
+ return param.default;
138
+ }
139
+ })];
140
+ }
130
141
  })];
131
142
  }
132
143
  });
@@ -220,6 +231,17 @@ function typeParameter(param) {
220
231
  }
221
232
  })];
222
233
  }
234
+ }), _$createComponent(Show, {
235
+ get when() {
236
+ return !!param.default;
237
+ },
238
+ get children() {
239
+ return [" = ", _$createComponent(TypeRefContext, {
240
+ get children() {
241
+ return param.default;
242
+ }
243
+ })];
244
+ }
223
245
  })];
224
246
  }
225
247
  });
@@ -1,7 +1,12 @@
1
1
  import { Children, Refkey } from "@alloy-js/core";
2
2
  import { BaseDeclarationProps } from "./Declaration.js";
3
+ import { TypeParameterDescriptor } from "../parameter-descriptor.js";
3
4
  export interface InterfaceDeclarationProps extends BaseDeclarationProps {
4
5
  extends?: Children;
6
+ /**
7
+ * The generic type parameters of the interface.
8
+ */
9
+ typeParameters?: TypeParameterDescriptor[] | string[];
5
10
  }
6
11
  /**
7
12
  * Create a TypeScript interface declaration.
@@ -12,7 +17,10 @@ export interface InterfaceDeclarationProps extends BaseDeclarationProps {
12
17
  * `default` boolean props determine whether and how this symbol is exported
13
18
  * from the package.
14
19
  */
15
- export declare const InterfaceDeclaration: (props: InterfaceDeclarationProps) => Children;
20
+ export declare function InterfaceDeclaration(props: InterfaceDeclarationProps): Children;
21
+ export declare namespace InterfaceDeclaration {
22
+ var TypeParameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps>, "tag">>;
23
+ }
16
24
  export interface InterfaceExpressionProps {
17
25
  children?: Children;
18
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Interface.d.ts","sourceRoot":"","sources":["../../../src/components/Interface.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAOrE,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,gDAmBhC,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,mBAAmB,+CAmB/B,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OA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AC5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAkD1D"}
@@ -1,23 +1,23 @@
1
- import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
- import { Block, MemberScope, Name, OutputSymbolFlags, Show, useMemberDeclaration, useMemberScope, Wrap } from "@alloy-js/core";
1
+ import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
2
+ import { Block, childrenArray, findKeyedChild, findUnkeyedChildren, MemberScope, Name, OutputSymbolFlags, Show, useMemberDeclaration, useMemberScope, Wrap } from "@alloy-js/core";
3
3
  import { useTSNamePolicy } from "../name-policy.js";
4
4
  import { Declaration } from "./Declaration.js";
5
5
  import { JSDoc } from "./JSDoc.js";
6
+ import { TypeParameters } from "./FunctionBase.js";
6
7
  import { MemberDeclaration } from "./MemberDeclaration.js";
7
8
  import { PropertyName } from "./PropertyName.js";
8
9
  import { ensureTypeRefContext } from "./TypeRefContext.js";
9
- /**
10
- * Create a TypeScript interface declaration.
11
- *
12
- * @remarks
13
- *
14
- * This component will declare a symbol for this interface. The `export` and
15
- * `default` boolean props determine whether and how this symbol is exported
16
- * from the package.
17
- */
18
- export const InterfaceDeclaration = ensureTypeRefContext(props => {
10
+ const _InterfaceDeclaration = ensureTypeRefContext(props => {
11
+ const children = childrenArray(() => props.children);
12
+ const typeParametersChildren = findKeyedChild(children, TypeParameters.tag) ?? undefined;
13
+ const sTypeParameters = typeParametersChildren ? ["<", typeParametersChildren, ">"] : _$createComponent(TypeParameters, {
14
+ get parameters() {
15
+ return props.typeParameters;
16
+ }
17
+ });
19
18
  const extendsPart = props.extends ? [" extends ", _$memo(() => props.extends)] : "";
20
19
  const flags = OutputSymbolFlags.StaticMemberContainer;
20
+ const filteredChildren = findUnkeyedChildren(children);
21
21
  return [_$createComponent(Show, {
22
22
  get when() {
23
23
  return Boolean(props.doc);
@@ -34,14 +34,26 @@ export const InterfaceDeclaration = ensureTypeRefContext(props => {
34
34
  flags: flags,
35
35
  kind: "type",
36
36
  get children() {
37
- return ["interface ", _$createComponent(Name, {}), extendsPart, " ", _$createComponent(InterfaceExpression, {
38
- get children() {
39
- return props.children;
40
- }
37
+ return ["interface ", _$createComponent(Name, {}), sTypeParameters, extendsPart, " ", _$createComponent(InterfaceExpression, {
38
+ children: filteredChildren
41
39
  })];
42
40
  }
43
41
  }))];
44
42
  });
43
+
44
+ /**
45
+ * Create a TypeScript interface declaration.
46
+ *
47
+ * @remarks
48
+ *
49
+ * This component will declare a symbol for this interface. The `export` and
50
+ * `default` boolean props determine whether and how this symbol is exported
51
+ * from the package.
52
+ */
53
+ export function InterfaceDeclaration(props) {
54
+ return _InterfaceDeclaration(props);
55
+ }
56
+ InterfaceDeclaration.TypeParameters = TypeParameters;
45
57
  export const InterfaceExpression = ensureTypeRefContext(props => {
46
58
  const parentMemberSym = useMemberDeclaration();
47
59
  if (parentMemberSym) {
@@ -25,7 +25,7 @@ export function CaseClause(props) {
25
25
  get when() {
26
26
  return "default" in props && props.default;
27
27
  },
28
- children: "default "
28
+ children: "default"
29
29
  }), _$createComponent(Match, {
30
30
  "else": true,
31
31
  get children() {
@@ -253,6 +253,56 @@ describe("symbols", () => {
253
253
  }
254
254
  `);
255
255
  });
256
+ it("creates parameters with default values", () => {
257
+ const paramDesc = {
258
+ name: "foo",
259
+ refkey: refkey(),
260
+ type: "string",
261
+ default: '"bar"'
262
+ };
263
+ const decl = [_$createComponent(FunctionDeclaration, {
264
+ name: "foo",
265
+ parameters: [paramDesc],
266
+ children: "console.log(foo);"
267
+ })];
268
+ expect(toSourceText(decl)).toBe(d`
269
+ function foo(foo: string = "bar") {
270
+ console.log(foo);
271
+ }
272
+ `);
273
+ });
274
+ it("correctly renders mixed parameters", () => {
275
+ const params = [{
276
+ name: "a",
277
+ refkey: refkey(),
278
+ type: "string"
279
+ }, {
280
+ name: "b",
281
+ refkey: refkey(),
282
+ type: "number",
283
+ optional: true
284
+ }, {
285
+ name: "c",
286
+ refkey: refkey(),
287
+ type: "boolean",
288
+ default: "false"
289
+ }, {
290
+ name: "d",
291
+ refkey: refkey(),
292
+ type: "any[]",
293
+ rest: true
294
+ }];
295
+ const decl = _$createComponent(FunctionDeclaration, {
296
+ name: "foo",
297
+ parameters: params,
298
+ children: "console.log(a, b, c, d);"
299
+ });
300
+ expect(toSourceText(decl)).toBe(d`
301
+ function foo(a: string, b?: number, c: boolean = false, ...d: any[]) {
302
+ console.log(a, b, c, d);
303
+ }
304
+ `);
305
+ });
256
306
  it("adds symbols for members of parameters when a type is provided", () => {
257
307
  const ifaceRk = refkey();
258
308
  const ifaceMemberRk = refkey();
@@ -305,6 +305,108 @@ it("handles invalid identifier names", () => {
305
305
  }
306
306
  `);
307
307
  });
308
+ it("accepts type parameters by descriptors", () => {
309
+ const typeParams = [{
310
+ name: "T",
311
+ refkey: refkey()
312
+ }, {
313
+ name: "U",
314
+ extends: "number",
315
+ refkey: refkey()
316
+ }, {
317
+ name: "V",
318
+ default: "object",
319
+ refkey: refkey()
320
+ }, {
321
+ name: "W",
322
+ extends: "string",
323
+ default: '"test"',
324
+ refkey: refkey()
325
+ }];
326
+ const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
327
+ name: "Foo",
328
+ typeParameters: typeParams,
329
+ get children() {
330
+ return [_$createComponent(ts.InterfaceMember, {
331
+ name: "member",
332
+ get type() {
333
+ return typeParams[0].refkey;
334
+ }
335
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.InterfaceMember, {
336
+ name: "member2",
337
+ get type() {
338
+ return typeParams[1].refkey;
339
+ }
340
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.InterfaceMember, {
341
+ name: "member3",
342
+ get type() {
343
+ return typeParams[2].refkey;
344
+ }
345
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.InterfaceMember, {
346
+ name: "member4",
347
+ get type() {
348
+ return typeParams[3].refkey;
349
+ }
350
+ }), ";"];
351
+ }
352
+ }));
353
+ expect(res).toEqual(d`
354
+ interface Foo<T, U extends number, V = object, W extends string = "test"> {
355
+ member: T;
356
+ member2: U;
357
+ member3: V;
358
+ member4: W;
359
+ }
360
+ `);
361
+ });
362
+ it("accepts type parameters with extends", () => {
363
+ const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
364
+ name: "Foo",
365
+ typeParameters: ["T"],
366
+ "extends": "Bar",
367
+ get children() {
368
+ return [_$createComponent(ts.InterfaceMember, {
369
+ name: "member",
370
+ type: "T"
371
+ }), ";"];
372
+ }
373
+ }));
374
+ expect(res).toEqual(d`
375
+ interface Foo<T> extends Bar {
376
+ member: T;
377
+ }
378
+ `);
379
+ });
380
+ it("accepts type parameters children", () => {
381
+ const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
382
+ name: "Foo",
383
+ get children() {
384
+ return [_$createComponent(ts.InterfaceDeclaration.TypeParameters, {
385
+ children: "T, U extends number, V = object, W extends string = \"test\""
386
+ }), _$createComponent(ts.InterfaceMember, {
387
+ name: "member",
388
+ type: "T"
389
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.InterfaceMember, {
390
+ name: "member2",
391
+ type: "U"
392
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.InterfaceMember, {
393
+ name: "member3",
394
+ type: "V"
395
+ }), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.InterfaceMember, {
396
+ name: "member4",
397
+ type: "W"
398
+ }), ";"];
399
+ }
400
+ }));
401
+ expect(res).toEqual(d`
402
+ interface Foo<T, U extends number, V = object, W extends string = "test"> {
403
+ member: T;
404
+ member2: U;
405
+ member3: V;
406
+ member4: W;
407
+ }
408
+ `);
409
+ });
308
410
  describe("method members", () => {
309
411
  it("render basic", () => {
310
412
  expect(toSourceText(_$createComponent(ts.InterfaceDeclaration, {
@@ -54,7 +54,7 @@ it("handles various cases", () => {
54
54
  // block
55
55
  break;
56
56
  }
57
- default :
57
+ default:
58
58
  // default
59
59
  }
60
60
  `);