@alloy-js/typescript 0.15.0 → 0.17.0

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 (136) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/src/builtins/node.d.ts +9 -41
  3. package/dist/src/builtins/node.d.ts.map +1 -1
  4. package/dist/src/components/ArrowFunction.d.ts +3 -3
  5. package/dist/src/components/BarrelFile.d.ts +1 -1
  6. package/dist/src/components/BarrelFile.d.ts.map +1 -1
  7. package/dist/src/components/BlockScope.d.ts +1 -1
  8. package/dist/src/components/BlockScope.d.ts.map +1 -1
  9. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  10. package/dist/src/components/ClassDeclaration.js +5 -7
  11. package/dist/src/components/Declaration.d.ts.map +1 -1
  12. package/dist/src/components/Declaration.js +3 -4
  13. package/dist/src/components/EnumDeclaration.d.ts +1 -1
  14. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  15. package/dist/src/components/EnumDeclaration.js +3 -4
  16. package/dist/src/components/EnumMember.d.ts.map +1 -1
  17. package/dist/src/components/EnumMember.js +3 -4
  18. package/dist/src/components/FunctionBase.d.ts +4 -4
  19. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  20. package/dist/src/components/FunctionBase.js +15 -10
  21. package/dist/src/components/FunctionDeclaration.d.ts +3 -3
  22. package/dist/src/components/FunctionExpression.d.ts +3 -3
  23. package/dist/src/components/FunctionType.d.ts +2 -2
  24. package/dist/src/components/ImportStatement.d.ts +1 -1
  25. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  26. package/dist/src/components/Interface.js +1 -1
  27. package/dist/src/components/InterfaceMethod.d.ts +2 -2
  28. package/dist/src/components/MemberDeclaration.d.ts +1 -1
  29. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  30. package/dist/src/components/MemberDeclaration.js +4 -4
  31. package/dist/src/components/MemberExpression.d.ts +27 -5
  32. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  33. package/dist/src/components/MemberExpression.js +327 -89
  34. package/dist/src/components/NewExpression.d.ts +5 -0
  35. package/dist/src/components/NewExpression.d.ts.map +1 -0
  36. package/dist/src/components/NewExpression.js +12 -0
  37. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  38. package/dist/src/components/ObjectExpression.js +14 -15
  39. package/dist/src/components/PackageDirectory.d.ts.map +1 -1
  40. package/dist/src/components/PackageDirectory.js +3 -3
  41. package/dist/src/components/PackageJson.d.ts +1 -1
  42. package/dist/src/components/PackageJson.d.ts.map +1 -1
  43. package/dist/src/components/PropertyName.d.ts +1 -1
  44. package/dist/src/components/PropertyName.d.ts.map +1 -1
  45. package/dist/src/components/Reference.d.ts +1 -1
  46. package/dist/src/components/Reference.d.ts.map +1 -1
  47. package/dist/src/components/Reference.js +5 -1
  48. package/dist/src/components/SourceFile.d.ts.map +1 -1
  49. package/dist/src/components/SourceFile.js +3 -3
  50. package/dist/src/components/TsConfigJson.d.ts +1 -1
  51. package/dist/src/components/TsConfigJson.d.ts.map +1 -1
  52. package/dist/src/components/TypeDeclaration.d.ts +1 -1
  53. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  54. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  55. package/dist/src/components/VarDeclaration.js +30 -10
  56. package/dist/src/components/index.d.ts +1 -1
  57. package/dist/src/components/index.d.ts.map +1 -1
  58. package/dist/src/components/index.js +1 -1
  59. package/dist/src/components/stc/index.d.ts +45 -44
  60. package/dist/src/components/stc/index.d.ts.map +1 -1
  61. package/dist/src/components/stc/index.js +46 -45
  62. package/dist/src/create-package.d.ts +62 -18
  63. package/dist/src/create-package.d.ts.map +1 -1
  64. package/dist/src/create-package.js +153 -15
  65. package/dist/src/source-directory-data.d.ts.map +1 -1
  66. package/dist/src/source-directory-data.js +2 -2
  67. package/dist/src/symbols/reference.d.ts +2 -1
  68. package/dist/src/symbols/reference.d.ts.map +1 -1
  69. package/dist/src/symbols/reference.js +3 -4
  70. package/dist/src/symbols/scopes.d.ts +1 -4
  71. package/dist/src/symbols/scopes.d.ts.map +1 -1
  72. package/dist/src/symbols/ts-member-scope.d.ts +4 -6
  73. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
  74. package/dist/src/symbols/ts-member-scope.js +8 -10
  75. package/dist/src/symbols/ts-module-scope.d.ts +8 -11
  76. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
  77. package/dist/src/symbols/ts-module-scope.js +47 -40
  78. package/dist/src/symbols/ts-output-symbol.d.ts +23 -16
  79. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  80. package/dist/src/symbols/ts-output-symbol.js +88 -27
  81. package/dist/src/symbols/ts-package-scope.d.ts +18 -14
  82. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
  83. package/dist/src/symbols/ts-package-scope.js +78 -27
  84. package/dist/test/class.test.js +2 -1
  85. package/dist/test/externals.test.js +87 -2
  86. package/dist/test/function-declaration.test.js +74 -3
  87. package/dist/test/member-expression.test.js +391 -5
  88. package/dist/test/new-expression.test.d.ts +2 -0
  89. package/dist/test/new-expression.test.d.ts.map +1 -0
  90. package/dist/test/new-expression.test.js +62 -0
  91. package/dist/test/var-declaration.test.d.ts.map +1 -1
  92. package/dist/test/var-declaration.test.js +145 -2
  93. package/dist/tsconfig.tsbuildinfo +1 -1
  94. package/package.json +4 -4
  95. package/src/components/ClassDeclaration.tsx +5 -7
  96. package/src/components/Declaration.tsx +3 -8
  97. package/src/components/EnumDeclaration.tsx +3 -4
  98. package/src/components/EnumMember.tsx +3 -4
  99. package/src/components/FunctionBase.tsx +25 -18
  100. package/src/components/ImportStatement.tsx +0 -1
  101. package/src/components/Interface.tsx +1 -1
  102. package/src/components/MemberDeclaration.tsx +5 -8
  103. package/src/components/MemberExpression.tsx +416 -103
  104. package/src/components/NewExpression.tsx +25 -0
  105. package/src/components/ObjectExpression.tsx +18 -16
  106. package/src/components/PackageDirectory.tsx +2 -10
  107. package/src/components/Reference.tsx +4 -2
  108. package/src/components/SourceFile.tsx +2 -5
  109. package/src/components/VarDeclaration.tsx +34 -11
  110. package/src/components/index.ts +1 -1
  111. package/src/components/stc/index.ts +46 -45
  112. package/src/create-package.ts +274 -35
  113. package/src/source-directory-data.ts +2 -2
  114. package/src/symbols/reference.ts +10 -5
  115. package/src/symbols/scopes.ts +1 -6
  116. package/src/symbols/ts-member-scope.ts +8 -23
  117. package/src/symbols/ts-module-scope.ts +58 -62
  118. package/src/symbols/ts-output-symbol.ts +108 -50
  119. package/src/symbols/ts-package-scope.ts +71 -53
  120. package/temp/api.json +1665 -1733
  121. package/test/class.test.tsx +2 -1
  122. package/test/externals.test.tsx +99 -1
  123. package/test/function-declaration.test.tsx +75 -2
  124. package/test/member-expression.test.tsx +312 -8
  125. package/test/new-expression.test.tsx +42 -0
  126. package/test/values.test.tsx +1 -0
  127. package/test/var-declaration.test.tsx +101 -1
  128. package/tsdoc-metadata.json +1 -1
  129. package/dist/src/components/MemberChainExpression.d.ts +0 -11
  130. package/dist/src/components/MemberChainExpression.d.ts.map +0 -1
  131. package/dist/src/components/MemberChainExpression.js +0 -98
  132. package/dist/test/member-chain.test.d.ts +0 -2
  133. package/dist/test/member-chain.test.d.ts.map +0 -1
  134. package/dist/test/member-chain.test.js +0 -141
  135. package/src/components/MemberChainExpression.tsx +0 -91
  136. package/test/member-chain.test.tsx +0 -124
@@ -1,4 +1,10 @@
1
- import { Output, refkey, render } from "@alloy-js/core";
1
+ import {
2
+ memberRefkey,
3
+ Output,
4
+ refkey,
5
+ render,
6
+ StatementList,
7
+ } from "@alloy-js/core";
2
8
  import "@alloy-js/core/testing";
3
9
  import { expect, it } from "vitest";
4
10
  import * as ts from "../src/index.js";
@@ -49,3 +55,97 @@ it("works end-to-end", () => {
49
55
  `,
50
56
  });
51
57
  });
58
+
59
+ it("instantiates symbols from its type", () => {
60
+ const ifaceRk = refkey();
61
+ const ifaceMemberRk = refkey();
62
+ const classRk = refkey();
63
+ const classMemberRk = refkey();
64
+ const v1Rk = refkey();
65
+ const v2Rk = refkey();
66
+
67
+ const res = render(
68
+ <Output>
69
+ <ts.SourceFile path="inst.ts">
70
+ <StatementList>
71
+ <ts.VarDeclaration export name="one" refkey={v1Rk} type={classRk}>
72
+ "test"
73
+ </ts.VarDeclaration>
74
+ <>{memberRefkey(v1Rk, classMemberRk)}</>
75
+ <ts.VarDeclaration export name="two" refkey={v2Rk} type={ifaceRk}>
76
+ "test"
77
+ </ts.VarDeclaration>
78
+ <>{memberRefkey(v2Rk, ifaceMemberRk)}</>
79
+ </StatementList>
80
+ </ts.SourceFile>
81
+ <ts.SourceFile path="decl.ts">
82
+ <ts.InterfaceDeclaration name="Foo" refkey={ifaceRk}>
83
+ <StatementList>
84
+ <ts.InterfaceMember name="instanceProp" refkey={ifaceMemberRk}>
85
+ 42
86
+ </ts.InterfaceMember>
87
+ </StatementList>
88
+ </ts.InterfaceDeclaration>
89
+ <ts.ClassDeclaration name="Bar" refkey={classRk}>
90
+ <StatementList>
91
+ <ts.ClassField name="instanceProp" refkey={classMemberRk}>
92
+ 42
93
+ </ts.ClassField>
94
+ </StatementList>
95
+ </ts.ClassDeclaration>
96
+ </ts.SourceFile>
97
+ </Output>,
98
+ );
99
+
100
+ assertFileContents(res, {
101
+ "inst.ts": `
102
+ import type { Bar, Foo } from "./decl.js";
103
+
104
+ export const one: Bar = "test";
105
+ one.instanceProp;
106
+ export const two: Foo = "test";
107
+ two.instanceProp;
108
+ `,
109
+ });
110
+ });
111
+
112
+ it("instantiates symbols from type even when an expression is passed", () => {
113
+ const classRk = refkey();
114
+ const classMemberRk = refkey();
115
+ const v1Rk = refkey();
116
+
117
+ const res = render(
118
+ <Output>
119
+ <ts.SourceFile path="inst.ts">
120
+ <StatementList>
121
+ <ts.VarDeclaration export name="one" refkey={v1Rk} type={classRk}>
122
+ <ts.ObjectExpression>
123
+ <ts.ObjectProperty name="noProp" refkey={refkey()} value="1" />
124
+ </ts.ObjectExpression>
125
+ </ts.VarDeclaration>
126
+ <>{memberRefkey(v1Rk, classMemberRk)}</>
127
+ </StatementList>
128
+ </ts.SourceFile>
129
+ <ts.SourceFile path="decl.ts">
130
+ <ts.ClassDeclaration name="Bar" refkey={classRk}>
131
+ <StatementList>
132
+ <ts.ClassField name="instanceProp" refkey={classMemberRk}>
133
+ 42
134
+ </ts.ClassField>
135
+ </StatementList>
136
+ </ts.ClassDeclaration>
137
+ </ts.SourceFile>
138
+ </Output>,
139
+ );
140
+
141
+ assertFileContents(res, {
142
+ "inst.ts": `
143
+ import type { Bar } from "./decl.js";
144
+
145
+ export const one: Bar = {
146
+ noProp: 1
147
+ };
148
+ one.instanceProp;
149
+ `,
150
+ });
151
+ });
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.47.12"
8
+ "packageVersion": "7.52.8"
9
9
  }
10
10
  ]
11
11
  }
@@ -1,11 +0,0 @@
1
- import { Children } from "@alloy-js/core/jsx-runtime";
2
- export interface MemberChainExpressionProps {
3
- children: Children;
4
- }
5
- /**
6
- * Create a member chain expression, which is a member expression comprised of
7
- * either children, {@link FunctionCallExpression} components, or nested member
8
- * chain expression components. Other component types are ignored.
9
- */
10
- export declare function MemberChainExpression(props: MemberChainExpressionProps): Children;
11
- //# sourceMappingURL=MemberChainExpression.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MemberChainExpression.d.ts","sourceRoot":"","sources":["../../../src/components/MemberChainExpression.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAsB,MAAM,4BAA4B,CAAC;AAG1E,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,YA6DtE"}
@@ -1,98 +0,0 @@
1
- import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
- import { childrenArray, computed, For, List, Show } from "@alloy-js/core";
3
- import { isComponentCreator } from "@alloy-js/core/jsx-runtime";
4
- import { FunctionCallExpression } from "./FunctionCallExpression.js";
5
- /**
6
- * Create a member chain expression, which is a member expression comprised of
7
- * either children, {@link FunctionCallExpression} components, or nested member
8
- * chain expression components. Other component types are ignored.
9
- */
10
- export function MemberChainExpression(props) {
11
- // chunks are constructed by consuming as many non-call expressions as
12
- // possible, then placing an indent and soft line break before and after the
13
- // any subsequent call expressions
14
-
15
- const chunks = computed(() => {
16
- const children = flattenCallChains(childrenArray(() => props.children));
17
- const chunks = [];
18
- let currentChunk = [];
19
- for (const child of children) {
20
- if (isComponentCreator(child) && child.component === FunctionCallExpression) {
21
- if (currentChunk.length > 0) {
22
- chunks.push(currentChunk);
23
- currentChunk = [];
24
- }
25
- chunks.push([child]);
26
- } else {
27
- currentChunk.push(child);
28
- }
29
- }
30
- if (currentChunk.length > 0) {
31
- chunks.push(currentChunk);
32
- }
33
- return [chunks[0], chunks.slice(1)];
34
- });
35
- const groupId = Symbol();
36
- return _$createIntrinsic("group", {
37
- get children() {
38
- return [_$createIntrinsic("group", {
39
- id: groupId,
40
- get children() {
41
- return _$createComponent(List, {
42
- joiner: ".",
43
- get children() {
44
- return chunks.value[0];
45
- }
46
- });
47
- }
48
- }), _$createComponent(Show, {
49
- get when() {
50
- return chunks.value[1].length === 1;
51
- },
52
- get children() {
53
- return _$createComponent(For, {
54
- get each() {
55
- return chunks.value[1];
56
- },
57
- softline: true,
58
- children: chunk => [".", _$createComponent(List, {
59
- joiner: ".",
60
- children: chunk
61
- })]
62
- });
63
- }
64
- }), _$createComponent(Show, {
65
- get when() {
66
- return chunks.value[1].length > 1;
67
- },
68
- get children() {
69
- return _$createIntrinsic("indent", {
70
- get children() {
71
- return _$createComponent(For, {
72
- get each() {
73
- return chunks.value[1];
74
- },
75
- softline: true,
76
- children: chunk => [".", _$createComponent(List, {
77
- joiner: ".",
78
- children: chunk
79
- })]
80
- });
81
- }
82
- });
83
- }
84
- })];
85
- }
86
- });
87
- }
88
- function flattenCallChains(children) {
89
- const flatChildren = [];
90
- for (const child of children) {
91
- if (isComponentCreator(child) && child.component === MemberChainExpression) {
92
- flatChildren.push(...flattenCallChains(child.props.children));
93
- } else {
94
- flatChildren.push(child);
95
- }
96
- }
97
- return flatChildren;
98
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=member-chain.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"member-chain.test.d.ts","sourceRoot":"","sources":["../../test/member-chain.test.tsx"],"names":[],"mappings":""}
@@ -1,141 +0,0 @@
1
- import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
- import { d } from "@alloy-js/core/testing";
3
- import { expect, it } from "vitest";
4
- import { MemberChainExpression } from "../src/components/MemberChainExpression.js";
5
- import { FunctionCallExpression, ValueExpression } from "../src/index.js";
6
- import { toSourceText } from "./utils.js";
7
- it("works", () => {
8
- expect(toSourceText(_$createComponent(MemberChainExpression, {
9
- get children() {
10
- return [["z"], _$createComponent(FunctionCallExpression, {
11
- target: "string"
12
- }), _$createComponent(FunctionCallExpression, {
13
- target: "array"
14
- }), _$createComponent(FunctionCallExpression, {
15
- target: "min",
16
- args: [5]
17
- }), _$createComponent(FunctionCallExpression, {
18
- target: "max",
19
- args: [10]
20
- })];
21
- }
22
- }), {
23
- printWidth: 10
24
- })).toBe(d`
25
- z.string()
26
- .array()
27
- .min(5)
28
- .max(10)
29
- `);
30
- });
31
- it("works with args which break", () => {
32
- expect(toSourceText(_$createComponent(MemberChainExpression, {
33
- get children() {
34
- return [["z"], _$createComponent(FunctionCallExpression, {
35
- target: "object",
36
- get args() {
37
- return [_$createComponent(ValueExpression, {
38
- jsValue: {
39
- a: 1,
40
- b: 2
41
- }
42
- })];
43
- }
44
- }), _$createComponent(FunctionCallExpression, {
45
- target: "array"
46
- })];
47
- }
48
- }), {
49
- printWidth: 10
50
- })).toBe(d`
51
- z.object({
52
- a: 1,
53
- b: 2,
54
- })
55
- .array()
56
- `);
57
- });
58
- it("works with args when it doesn't break", () => {
59
- expect(toSourceText(_$createComponent(MemberChainExpression, {
60
- get children() {
61
- return [["z"], _$createComponent(FunctionCallExpression, {
62
- target: "object",
63
- get args() {
64
- return [_$createComponent(ValueExpression, {
65
- jsValue: {
66
- a: 1,
67
- b: 2
68
- }
69
- })];
70
- }
71
- })];
72
- }
73
- }))).toBe(d`
74
- z.object({
75
- a: 1,
76
- b: 2,
77
- })
78
- `);
79
- expect(toSourceText(_$createComponent(MemberChainExpression, {
80
- get children() {
81
- return [["z"], ["z2"], ["z3"], _$createComponent(FunctionCallExpression, {
82
- target: "object",
83
- get args() {
84
- return [_$createComponent(ValueExpression, {
85
- jsValue: {
86
- a: 1,
87
- b: 2
88
- }
89
- })];
90
- }
91
- })];
92
- }
93
- }))).toBe(d`
94
- z.z2.z3.object({
95
- a: 1,
96
- b: 2,
97
- })
98
- `);
99
- });
100
- it("works with nested call member chains", () => {
101
- expect(toSourceText(_$createComponent(MemberChainExpression, {
102
- get children() {
103
- return [["z"], _$createComponent(FunctionCallExpression, {
104
- target: "string"
105
- }), _$createComponent(FunctionCallExpression, {
106
- target: "array"
107
- }), _$createComponent(MemberChainExpression, {
108
- get children() {
109
- return [_$createComponent(FunctionCallExpression, {
110
- target: "min",
111
- args: [5]
112
- }), _$createComponent(FunctionCallExpression, {
113
- target: "max",
114
- args: [10]
115
- })];
116
- }
117
- }), _$createComponent(FunctionCallExpression, {
118
- target: "array"
119
- })];
120
- }
121
- }), {
122
- printWidth: 10
123
- })).toBe(d`
124
- z.string()
125
- .array()
126
- .min(5)
127
- .max(10)
128
- .array()
129
- `);
130
- });
131
- it("works without function call expressions", () => {
132
- expect(toSourceText(_$createComponent(MemberChainExpression, {
133
- get children() {
134
- return [["z"], ["string"], ["min"]];
135
- }
136
- }), {
137
- printWidth: 5
138
- })).toBe(d`
139
- z.string.min
140
- `);
141
- });
@@ -1,91 +0,0 @@
1
- import { childrenArray, computed, For, List, Show } from "@alloy-js/core";
2
- import { Children, isComponentCreator } from "@alloy-js/core/jsx-runtime";
3
- import { FunctionCallExpression } from "./FunctionCallExpression.jsx";
4
-
5
- export interface MemberChainExpressionProps {
6
- children: Children;
7
- }
8
-
9
- /**
10
- * Create a member chain expression, which is a member expression comprised of
11
- * either children, {@link FunctionCallExpression} components, or nested member
12
- * chain expression components. Other component types are ignored.
13
- */
14
- export function MemberChainExpression(props: MemberChainExpressionProps) {
15
- // chunks are constructed by consuming as many non-call expressions as
16
- // possible, then placing an indent and soft line break before and after the
17
- // any subsequent call expressions
18
-
19
- const chunks = computed(() => {
20
- const children = flattenCallChains(childrenArray(() => props.children));
21
- const chunks: Children[][] = [];
22
-
23
- let currentChunk: Children[] = [];
24
-
25
- for (const child of children) {
26
- if (
27
- isComponentCreator(child) &&
28
- child.component === FunctionCallExpression
29
- ) {
30
- if (currentChunk.length > 0) {
31
- chunks.push(currentChunk);
32
- currentChunk = [];
33
- }
34
- chunks.push([child]);
35
- } else {
36
- currentChunk.push(child);
37
- }
38
- }
39
-
40
- if (currentChunk.length > 0) {
41
- chunks.push(currentChunk);
42
- }
43
-
44
- return [chunks[0], chunks.slice(1)];
45
- });
46
- const groupId = Symbol();
47
-
48
- return (
49
- <group>
50
- <group id={groupId}>
51
- <List joiner="." children={chunks.value[0]} />
52
- </group>
53
- <Show when={chunks.value[1].length === 1}>
54
- <For each={chunks.value[1]} softline>
55
- {(chunk) => (
56
- <>
57
- .<List joiner="." children={chunk} />
58
- </>
59
- )}
60
- </For>
61
- </Show>
62
- <Show when={chunks.value[1].length > 1}>
63
- <indent>
64
- <For each={chunks.value[1]} softline>
65
- {(chunk) => (
66
- <>
67
- .<List joiner="." children={chunk} />
68
- </>
69
- )}
70
- </For>
71
- </indent>
72
- </Show>
73
- </group>
74
- );
75
- }
76
-
77
- function flattenCallChains(children: Children[]): Children[] {
78
- const flatChildren = [];
79
- for (const child of children) {
80
- if (
81
- isComponentCreator(child) &&
82
- child.component === MemberChainExpression
83
- ) {
84
- flatChildren.push(...flattenCallChains(child.props.children));
85
- } else {
86
- flatChildren.push(child);
87
- }
88
- }
89
-
90
- return flatChildren;
91
- }
@@ -1,124 +0,0 @@
1
- import { d } from "@alloy-js/core/testing";
2
- import { expect, it } from "vitest";
3
- import { MemberChainExpression } from "../src/components/MemberChainExpression.jsx";
4
- import { FunctionCallExpression, ValueExpression } from "../src/index.js";
5
- import { toSourceText } from "./utils.js";
6
-
7
- it("works", () => {
8
- expect(
9
- toSourceText(
10
- <MemberChainExpression>
11
- <>z</>
12
- <FunctionCallExpression target="string" />
13
- <FunctionCallExpression target="array" />
14
- <FunctionCallExpression target="min" args={[5]} />
15
- <FunctionCallExpression target="max" args={[10]} />
16
- </MemberChainExpression>,
17
- { printWidth: 10 },
18
- ),
19
- ).toBe(d`
20
- z.string()
21
- .array()
22
- .min(5)
23
- .max(10)
24
- `);
25
- });
26
-
27
- it("works with args which break", () => {
28
- expect(
29
- toSourceText(
30
- <MemberChainExpression>
31
- <>z</>
32
- <FunctionCallExpression
33
- target="object"
34
- args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
35
- />
36
- <FunctionCallExpression target="array" />
37
- </MemberChainExpression>,
38
- { printWidth: 10 },
39
- ),
40
- ).toBe(d`
41
- z.object({
42
- a: 1,
43
- b: 2,
44
- })
45
- .array()
46
- `);
47
- });
48
-
49
- it("works with args when it doesn't break", () => {
50
- expect(
51
- toSourceText(
52
- <MemberChainExpression>
53
- <>z</>
54
- <FunctionCallExpression
55
- target="object"
56
- args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
57
- />
58
- </MemberChainExpression>,
59
- ),
60
- ).toBe(d`
61
- z.object({
62
- a: 1,
63
- b: 2,
64
- })
65
- `);
66
-
67
- expect(
68
- toSourceText(
69
- <MemberChainExpression>
70
- <>z</>
71
- <>z2</>
72
- <>z3</>
73
- <FunctionCallExpression
74
- target="object"
75
- args={[<ValueExpression jsValue={{ a: 1, b: 2 }} />]}
76
- />
77
- </MemberChainExpression>,
78
- ),
79
- ).toBe(d`
80
- z.z2.z3.object({
81
- a: 1,
82
- b: 2,
83
- })
84
- `);
85
- });
86
-
87
- it("works with nested call member chains", () => {
88
- expect(
89
- toSourceText(
90
- <MemberChainExpression>
91
- <>z</>
92
- <FunctionCallExpression target="string" />
93
- <FunctionCallExpression target="array" />
94
- <MemberChainExpression>
95
- <FunctionCallExpression target="min" args={[5]} />
96
- <FunctionCallExpression target="max" args={[10]} />
97
- </MemberChainExpression>
98
- <FunctionCallExpression target="array" />
99
- </MemberChainExpression>,
100
- { printWidth: 10 },
101
- ),
102
- ).toBe(d`
103
- z.string()
104
- .array()
105
- .min(5)
106
- .max(10)
107
- .array()
108
- `);
109
- });
110
-
111
- it("works without function call expressions", () => {
112
- expect(
113
- toSourceText(
114
- <MemberChainExpression>
115
- <>z</>
116
- <>string</>
117
- <>min</>
118
- </MemberChainExpression>,
119
- { printWidth: 5 },
120
- ),
121
- ).toBe(d`
122
- z.string.min
123
- `);
124
- });