@alloy-js/python 0.0.1

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 (206) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/LICENSE +7 -0
  3. package/api-extractor.json +4 -0
  4. package/dist/src/builtins/python.d.ts +9 -0
  5. package/dist/src/builtins/python.d.ts.map +1 -0
  6. package/dist/src/builtins/python.js +17 -0
  7. package/dist/src/components/Atom.d.ts +19 -0
  8. package/dist/src/components/Atom.d.ts.map +1 -0
  9. package/dist/src/components/Atom.js +82 -0
  10. package/dist/src/components/CallSignature.d.ts +79 -0
  11. package/dist/src/components/CallSignature.d.ts.map +1 -0
  12. package/dist/src/components/CallSignature.js +201 -0
  13. package/dist/src/components/ClassDeclaration.d.ts +37 -0
  14. package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
  15. package/dist/src/components/ClassDeclaration.js +83 -0
  16. package/dist/src/components/ClassInstantiation.d.ts +24 -0
  17. package/dist/src/components/ClassInstantiation.d.ts.map +1 -0
  18. package/dist/src/components/ClassInstantiation.js +35 -0
  19. package/dist/src/components/Declaration.d.ts +48 -0
  20. package/dist/src/components/Declaration.d.ts.map +1 -0
  21. package/dist/src/components/Declaration.js +37 -0
  22. package/dist/src/components/EnumDeclaration.d.ts +164 -0
  23. package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
  24. package/dist/src/components/EnumDeclaration.js +278 -0
  25. package/dist/src/components/EnumMember.d.ts +46 -0
  26. package/dist/src/components/EnumMember.d.ts.map +1 -0
  27. package/dist/src/components/EnumMember.js +67 -0
  28. package/dist/src/components/FunctionCallExpression.d.ts +19 -0
  29. package/dist/src/components/FunctionCallExpression.d.ts.map +1 -0
  30. package/dist/src/components/FunctionCallExpression.js +40 -0
  31. package/dist/src/components/FunctionDeclaration.d.ts +47 -0
  32. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -0
  33. package/dist/src/components/FunctionDeclaration.js +107 -0
  34. package/dist/src/components/ImportStatement.d.ts +39 -0
  35. package/dist/src/components/ImportStatement.d.ts.map +1 -0
  36. package/dist/src/components/ImportStatement.js +104 -0
  37. package/dist/src/components/MemberExpression.d.ts +97 -0
  38. package/dist/src/components/MemberExpression.d.ts.map +1 -0
  39. package/dist/src/components/MemberExpression.js +308 -0
  40. package/dist/src/components/NoNamePolicy.d.ts +23 -0
  41. package/dist/src/components/NoNamePolicy.d.ts.map +1 -0
  42. package/dist/src/components/NoNamePolicy.js +27 -0
  43. package/dist/src/components/PyDoc.d.ts +90 -0
  44. package/dist/src/components/PyDoc.d.ts.map +1 -0
  45. package/dist/src/components/PyDoc.js +280 -0
  46. package/dist/src/components/PythonBlock.d.ts +23 -0
  47. package/dist/src/components/PythonBlock.d.ts.map +1 -0
  48. package/dist/src/components/PythonBlock.js +31 -0
  49. package/dist/src/components/Reference.d.ts +13 -0
  50. package/dist/src/components/Reference.d.ts.map +1 -0
  51. package/dist/src/components/Reference.js +18 -0
  52. package/dist/src/components/SourceFile.d.ts +46 -0
  53. package/dist/src/components/SourceFile.d.ts.map +1 -0
  54. package/dist/src/components/SourceFile.js +75 -0
  55. package/dist/src/components/StatementList.d.ts +25 -0
  56. package/dist/src/components/StatementList.d.ts.map +1 -0
  57. package/dist/src/components/StatementList.js +29 -0
  58. package/dist/src/components/VariableDeclaration.d.ts +62 -0
  59. package/dist/src/components/VariableDeclaration.d.ts.map +1 -0
  60. package/dist/src/components/VariableDeclaration.js +131 -0
  61. package/dist/src/components/index.d.ts +19 -0
  62. package/dist/src/components/index.d.ts.map +1 -0
  63. package/dist/src/components/index.js +18 -0
  64. package/dist/src/create-module.d.ts +16 -0
  65. package/dist/src/create-module.d.ts.map +1 -0
  66. package/dist/src/create-module.js +64 -0
  67. package/dist/src/index.d.ts +8 -0
  68. package/dist/src/index.d.ts.map +1 -0
  69. package/dist/src/index.js +7 -0
  70. package/dist/src/name-policy.d.ts +5 -0
  71. package/dist/src/name-policy.d.ts.map +1 -0
  72. package/dist/src/name-policy.js +47 -0
  73. package/dist/src/parameter-descriptor.d.ts +31 -0
  74. package/dist/src/parameter-descriptor.d.ts.map +1 -0
  75. package/dist/src/parameter-descriptor.js +1 -0
  76. package/dist/src/symbol-creation.d.ts +4 -0
  77. package/dist/src/symbol-creation.d.ts.map +1 -0
  78. package/dist/src/symbol-creation.js +24 -0
  79. package/dist/src/symbols/custom-output-scope.d.ts +10 -0
  80. package/dist/src/symbols/custom-output-scope.d.ts.map +1 -0
  81. package/dist/src/symbols/custom-output-scope.js +25 -0
  82. package/dist/src/symbols/index.d.ts +7 -0
  83. package/dist/src/symbols/index.d.ts.map +1 -0
  84. package/dist/src/symbols/index.js +6 -0
  85. package/dist/src/symbols/python-member-scope.d.ts +7 -0
  86. package/dist/src/symbols/python-member-scope.d.ts.map +1 -0
  87. package/dist/src/symbols/python-member-scope.js +9 -0
  88. package/dist/src/symbols/python-module-scope.d.ts +25 -0
  89. package/dist/src/symbols/python-module-scope.d.ts.map +1 -0
  90. package/dist/src/symbols/python-module-scope.js +52 -0
  91. package/dist/src/symbols/python-output-symbol.d.ts +19 -0
  92. package/dist/src/symbols/python-output-symbol.d.ts.map +1 -0
  93. package/dist/src/symbols/python-output-symbol.js +22 -0
  94. package/dist/src/symbols/reference.d.ts +4 -0
  95. package/dist/src/symbols/reference.d.ts.map +1 -0
  96. package/dist/src/symbols/reference.js +60 -0
  97. package/dist/src/symbols/scopes.d.ts +5 -0
  98. package/dist/src/symbols/scopes.d.ts.map +1 -0
  99. package/dist/src/symbols/scopes.js +4 -0
  100. package/dist/src/utils.d.ts +7 -0
  101. package/dist/src/utils.d.ts.map +1 -0
  102. package/dist/src/utils.js +12 -0
  103. package/dist/test/callsignatures.test.d.ts +2 -0
  104. package/dist/test/callsignatures.test.d.ts.map +1 -0
  105. package/dist/test/callsignatures.test.js +276 -0
  106. package/dist/test/classdeclarations.test.d.ts +2 -0
  107. package/dist/test/classdeclarations.test.d.ts.map +1 -0
  108. package/dist/test/classdeclarations.test.js +397 -0
  109. package/dist/test/classinstantiations.test.d.ts +2 -0
  110. package/dist/test/classinstantiations.test.d.ts.map +1 -0
  111. package/dist/test/classinstantiations.test.js +168 -0
  112. package/dist/test/enums.test.d.ts +2 -0
  113. package/dist/test/enums.test.d.ts.map +1 -0
  114. package/dist/test/enums.test.js +211 -0
  115. package/dist/test/externals.test.d.ts +2 -0
  116. package/dist/test/externals.test.d.ts.map +1 -0
  117. package/dist/test/externals.test.js +219 -0
  118. package/dist/test/functioncallexpressions.test.d.ts +2 -0
  119. package/dist/test/functioncallexpressions.test.d.ts.map +1 -0
  120. package/dist/test/functioncallexpressions.test.js +156 -0
  121. package/dist/test/functiondeclaration.test.d.ts +2 -0
  122. package/dist/test/functiondeclaration.test.d.ts.map +1 -0
  123. package/dist/test/functiondeclaration.test.js +363 -0
  124. package/dist/test/imports.test.d.ts +2 -0
  125. package/dist/test/imports.test.d.ts.map +1 -0
  126. package/dist/test/imports.test.js +262 -0
  127. package/dist/test/memberexpressions.test.d.ts +2 -0
  128. package/dist/test/memberexpressions.test.d.ts.map +1 -0
  129. package/dist/test/memberexpressions.test.js +879 -0
  130. package/dist/test/namepolicies.test.d.ts +2 -0
  131. package/dist/test/namepolicies.test.d.ts.map +1 -0
  132. package/dist/test/namepolicies.test.js +109 -0
  133. package/dist/test/pydocs.test.d.ts +2 -0
  134. package/dist/test/pydocs.test.d.ts.map +1 -0
  135. package/dist/test/pydocs.test.js +500 -0
  136. package/dist/test/references.test.d.ts +2 -0
  137. package/dist/test/references.test.d.ts.map +1 -0
  138. package/dist/test/references.test.js +49 -0
  139. package/dist/test/sourcefiles.test.d.ts +2 -0
  140. package/dist/test/sourcefiles.test.d.ts.map +1 -0
  141. package/dist/test/sourcefiles.test.js +198 -0
  142. package/dist/test/utils.d.ts +23 -0
  143. package/dist/test/utils.d.ts.map +1 -0
  144. package/dist/test/utils.js +88 -0
  145. package/dist/test/values.test.d.ts +2 -0
  146. package/dist/test/values.test.d.ts.map +1 -0
  147. package/dist/test/values.test.js +78 -0
  148. package/dist/test/variables.test.d.ts +2 -0
  149. package/dist/test/variables.test.d.ts.map +1 -0
  150. package/dist/test/variables.test.js +173 -0
  151. package/dist/tsconfig.tsbuildinfo +1 -0
  152. package/package.json +39 -0
  153. package/src/builtins/python.ts +20 -0
  154. package/src/components/Atom.tsx +76 -0
  155. package/src/components/CallSignature.tsx +251 -0
  156. package/src/components/ClassDeclaration.tsx +98 -0
  157. package/src/components/ClassInstantiation.tsx +54 -0
  158. package/src/components/Declaration.tsx +91 -0
  159. package/src/components/EnumDeclaration.tsx +291 -0
  160. package/src/components/EnumMember.tsx +92 -0
  161. package/src/components/FunctionCallExpression.tsx +36 -0
  162. package/src/components/FunctionDeclaration.tsx +121 -0
  163. package/src/components/ImportStatement.tsx +134 -0
  164. package/src/components/MemberExpression.tsx +456 -0
  165. package/src/components/NoNamePolicy.tsx +31 -0
  166. package/src/components/PyDoc.tsx +331 -0
  167. package/src/components/PythonBlock.tsx +26 -0
  168. package/src/components/Reference.tsx +21 -0
  169. package/src/components/SourceFile.tsx +93 -0
  170. package/src/components/StatementList.tsx +28 -0
  171. package/src/components/VariableDeclaration.tsx +180 -0
  172. package/src/components/index.ts +18 -0
  173. package/src/create-module.ts +102 -0
  174. package/src/index.ts +7 -0
  175. package/src/name-policy.ts +101 -0
  176. package/src/parameter-descriptor.ts +36 -0
  177. package/src/symbol-creation.ts +36 -0
  178. package/src/symbols/custom-output-scope.ts +35 -0
  179. package/src/symbols/index.ts +6 -0
  180. package/src/symbols/python-member-scope.ts +12 -0
  181. package/src/symbols/python-module-scope.ts +89 -0
  182. package/src/symbols/python-output-symbol.ts +36 -0
  183. package/src/symbols/reference.ts +99 -0
  184. package/src/symbols/scopes.ts +9 -0
  185. package/src/utils.ts +27 -0
  186. package/temp/api.json +7207 -0
  187. package/test/callsignatures.test.tsx +256 -0
  188. package/test/classdeclarations.test.tsx +320 -0
  189. package/test/classinstantiations.test.tsx +159 -0
  190. package/test/enums.test.tsx +203 -0
  191. package/test/externals.test.tsx +190 -0
  192. package/test/functioncallexpressions.test.tsx +145 -0
  193. package/test/functiondeclaration.test.tsx +327 -0
  194. package/test/imports.test.tsx +214 -0
  195. package/test/memberexpressions.test.tsx +725 -0
  196. package/test/namepolicies.test.tsx +109 -0
  197. package/test/pydocs.test.tsx +528 -0
  198. package/test/references.test.tsx +36 -0
  199. package/test/sourcefiles.test.tsx +131 -0
  200. package/test/utils.tsx +131 -0
  201. package/test/values.test.tsx +61 -0
  202. package/test/variables.test.tsx +153 -0
  203. package/tsconfig.json +12 -0
  204. package/tsdoc-metadata.json +11 -0
  205. package/vitest.config.ts +10 -0
  206. package/vitest.setup.ts +1 -0
@@ -0,0 +1,280 @@
1
+ import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { For, Indent, List, Prose, Show, childrenArray } from "@alloy-js/core";
3
+ import { Atom } from "./index.js";
4
+ function GoogleStyleDocParamType(props) {
5
+ return [_$createComponent(Show, {
6
+ get when() {
7
+ return Boolean(props.type);
8
+ },
9
+ get children() {
10
+ return [" (", _$memo(() => props.type), _$createComponent(Show, {
11
+ get when() {
12
+ return props.optional;
13
+ },
14
+ children: ", optional"
15
+ }), ")"];
16
+ }
17
+ })];
18
+ }
19
+ function GoogleStyleDocParamName(props) {
20
+ return [_$memo(() => props.name)];
21
+ }
22
+ function GoogleStyleDocParamDescription(props) {
23
+ return _$createComponent(Show, {
24
+ get when() {
25
+ return Boolean(props.children);
26
+ },
27
+ get children() {
28
+ return [": ", _$createIntrinsic("align", {
29
+ width: 4,
30
+ get children() {
31
+ return [_$createComponent(Prose, {
32
+ get children() {
33
+ return props.children;
34
+ }
35
+ }), _$createComponent(Show, {
36
+ get when() {
37
+ return Boolean(props.defaultValue);
38
+ },
39
+ get children() {
40
+ return [" ", "Defaults to ", _$createComponent(Atom, {
41
+ get jsValue() {
42
+ return props.defaultValue;
43
+ }
44
+ }), "."];
45
+ }
46
+ })];
47
+ }
48
+ })];
49
+ }
50
+ });
51
+ }
52
+ /**
53
+ * Create a GoogleStyleDoc parameter.
54
+ */
55
+ export function GoogleStyleDocParam(props) {
56
+ return [_$createComponent(GoogleStyleDocParamName, {
57
+ get name() {
58
+ return props.name;
59
+ }
60
+ }), _$createComponent(GoogleStyleDocParamType, {
61
+ get type() {
62
+ return props.type;
63
+ },
64
+ get optional() {
65
+ return props.optional;
66
+ }
67
+ }), _$createComponent(GoogleStyleDocParamDescription, {
68
+ get children() {
69
+ return props.children;
70
+ },
71
+ get defaultValue() {
72
+ return props.defaultValue;
73
+ }
74
+ })];
75
+ }
76
+ /**
77
+ * A component that creates a GoogleStyleDoc block for parameters.
78
+ */
79
+ export function GoogleStyleDocParams(props) {
80
+ const parameters = normalizeParametersForDoc(props.parameters);
81
+ return ["Args:", _$createComponent(Indent, {
82
+ get children() {
83
+ return _$createComponent(List, {
84
+ doubleHardline: true,
85
+ get children() {
86
+ return parameters.map(param => _$createComponent(GoogleStyleDocParam, {
87
+ get name() {
88
+ return param.name;
89
+ },
90
+ get type() {
91
+ return param.type;
92
+ },
93
+ get optional() {
94
+ return param.optional;
95
+ },
96
+ get children() {
97
+ return param.doc;
98
+ }
99
+ }));
100
+ }
101
+ });
102
+ }
103
+ })];
104
+ }
105
+ /**
106
+ * A component that creates a GoogleStyleDoc block for parameters.
107
+ */
108
+ export function GoogleStyleDocReturn(props) {
109
+ return ["Returns:", _$createComponent(Indent, {
110
+ get children() {
111
+ return props.message;
112
+ }
113
+ })];
114
+ }
115
+ /**
116
+ * A component that creates a GoogleStyleDoc block for parameters.
117
+ */
118
+ export function GoogleStyleDocRaises(props) {
119
+ return ["Raises:", _$createComponent(Indent, {
120
+ get children() {
121
+ return props.message;
122
+ }
123
+ })];
124
+ }
125
+ /**
126
+ * A component that creates a GoogleStyleFunctionDoc block for parameters.
127
+ */
128
+ export function GoogleStyleFunctionDoc(props) {
129
+ // We are creating a list instead of relying on <Show> because otherwise
130
+ // <List> would render spaces between the elements even if <Show> evaluates to false.
131
+ const children = [];
132
+ if (props.description !== undefined) {
133
+ children.push(_$createComponent(List, {
134
+ doubleHardline: true,
135
+ get children() {
136
+ return props.description.map(param => param);
137
+ }
138
+ }));
139
+ }
140
+ if (props.parameters !== undefined && props.parameters.length > 0) {
141
+ children.push(_$createComponent(GoogleStyleDocParams, {
142
+ get parameters() {
143
+ return props.parameters;
144
+ }
145
+ }));
146
+ }
147
+ if (props.returns !== undefined) {
148
+ children.push(_$createComponent(GoogleStyleDocReturn, {
149
+ get message() {
150
+ return props.returns;
151
+ }
152
+ }));
153
+ }
154
+ if (props.raises !== undefined && props.raises.length > 0) {
155
+ children.push(props.raises.map(param => _$createComponent(GoogleStyleDocRaises, {
156
+ message: param
157
+ })));
158
+ }
159
+ return _$createComponent(PyDoc, {
160
+ children: children
161
+ });
162
+ }
163
+ /**
164
+ * A component that creates a FunctionDoc block for parameters.
165
+ */
166
+ export function FunctionDoc(props) {
167
+ const style = props.style ?? "google";
168
+ if (style === "google") {
169
+ return _$createComponent(GoogleStyleFunctionDoc, {
170
+ get description() {
171
+ return props.description;
172
+ },
173
+ get parameters() {
174
+ return props.parameters;
175
+ },
176
+ get returns() {
177
+ return props.returns;
178
+ },
179
+ get raises() {
180
+ return props.raises;
181
+ }
182
+ });
183
+ }
184
+ }
185
+ /**
186
+ * A component that creates a ClassDoc block for parameters.
187
+ */
188
+ export function ClassDoc(props) {
189
+ const style = props.style ?? "google";
190
+ if (style === "google") {
191
+ return _$createComponent(GoogleStyleClassDoc, {
192
+ get description() {
193
+ return props.description;
194
+ },
195
+ get parameters() {
196
+ return props.parameters;
197
+ }
198
+ });
199
+ }
200
+ }
201
+ /**
202
+ * A component that creates a GoogleStyleClassDoc block for parameters.
203
+ */
204
+ export function GoogleStyleClassDoc(props) {
205
+ // We are creating a list instead of relying on <Show> because otherwise
206
+ // <List> would render spaces between the elements even if <Show> evaluates to false.
207
+ const children = [];
208
+ if (props.description !== undefined) {
209
+ children.push(_$createComponent(List, {
210
+ doubleHardline: true,
211
+ get children() {
212
+ return props.description.map(param => param);
213
+ }
214
+ }));
215
+ }
216
+ if (props.parameters !== undefined && props.parameters.length > 0) {
217
+ children.push(_$createComponent(GoogleStyleDocParams, {
218
+ get parameters() {
219
+ return props.parameters;
220
+ }
221
+ }));
222
+ }
223
+ return _$createComponent(PyDoc, {
224
+ children: children
225
+ });
226
+ }
227
+ /**
228
+ * Create a PyDoc example, which is prepended by \>\>.
229
+ */
230
+ export function PyDocExample(props) {
231
+ const children = childrenArray(() => props.children);
232
+ let lines = [];
233
+ if (children.length === 1 && typeof children[0] === "string") {
234
+ // Split, trim each line, and filter out empty lines
235
+ lines = children[0].split(/\r?\n/).map(line => line.trim()).filter(line => line.length > 0);
236
+ } else {
237
+ // For non-string children, filter out empty/whitespace-only strings
238
+ lines = children.map(child => typeof child === "string" ? child : "").map(line => line.trim()).filter(line => line.length > 0);
239
+ }
240
+ return [_$createComponent(For, {
241
+ each: lines,
242
+ children: line => [">> ", line]
243
+ })];
244
+ }
245
+ function normalizeParametersForDoc(parameters) {
246
+ if (parameters.some(p => typeof p === "string")) {
247
+ return [];
248
+ }
249
+ return parameters;
250
+ }
251
+ /**
252
+ * A PyDoc comment. The children of this component are joined with two hard
253
+ * linebreaks. This is useful for creating PyDoc comments with multiple paragraphs.
254
+ */
255
+ export function PyDoc(props) {
256
+ const children = childrenArray(() => props.children);
257
+ return ['"""', _$createIntrinsic("hbr", {}), _$createComponent(List, {
258
+ doubleHardline: true,
259
+ children: children
260
+ }), _$createIntrinsic("hbr", {}), '"""', _$createIntrinsic("hbr", {})];
261
+ }
262
+ export function SimpleCommentBlock(props) {
263
+ return ["#", " ", _$createIntrinsic("align", {
264
+ string: "# ",
265
+ get children() {
266
+ return _$createComponent(Prose, {
267
+ get children() {
268
+ return props.children;
269
+ }
270
+ });
271
+ }
272
+ })];
273
+ }
274
+ export function SimpleInlineComment(props) {
275
+ return [" ", "# ", _$createComponent(Prose, {
276
+ get children() {
277
+ return props.children;
278
+ }
279
+ })];
280
+ }
@@ -0,0 +1,23 @@
1
+ import { Children } from "@alloy-js/core";
2
+ /**
3
+ * A Python block component that can be used to render a block of Python code.
4
+ *
5
+ * @example
6
+ * ```tsx
7
+ * <PythonBlock opener="def my_function()">
8
+ * <VariableDeclaration name="x" type="int" />
9
+ * <VariableDeclaration name="y" type="str" />
10
+ * </PythonBlock>
11
+ * ```
12
+ * renders to
13
+ * ```py
14
+ * def my_function():
15
+ * x: int = None
16
+ * y: str = None
17
+ * ```
18
+ */
19
+ export declare function PythonBlock(props: {
20
+ children: Children;
21
+ opener?: string;
22
+ }): Children;
23
+ //# sourceMappingURL=PythonBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PythonBlock.d.ts","sourceRoot":"","sources":["../../../src/components/PythonBlock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,YAMzE"}
@@ -0,0 +1,31 @@
1
+ import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { Block } from "@alloy-js/core";
3
+
4
+ /**
5
+ * A Python block component that can be used to render a block of Python code.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * <PythonBlock opener="def my_function()">
10
+ * <VariableDeclaration name="x" type="int" />
11
+ * <VariableDeclaration name="y" type="str" />
12
+ * </PythonBlock>
13
+ * ```
14
+ * renders to
15
+ * ```py
16
+ * def my_function():
17
+ * x: int = None
18
+ * y: str = None
19
+ * ```
20
+ */
21
+ export function PythonBlock(props) {
22
+ return _$createComponent(Block, {
23
+ get opener() {
24
+ return props.opener ?? "";
25
+ },
26
+ closer: "",
27
+ get children() {
28
+ return props.children;
29
+ }
30
+ });
31
+ }
@@ -0,0 +1,13 @@
1
+ import { Refkey } from "@alloy-js/core";
2
+ export interface ReferenceProps {
3
+ refkey: Refkey;
4
+ }
5
+ /**
6
+ * A Python reference to a symbol, such as a variable, function, or class.
7
+ *
8
+ * @remarks
9
+ * This component is used to render references to symbols in Python code.
10
+ * It takes a `refkey` prop which is the key of the symbol to reference.
11
+ */
12
+ export declare function Reference({ refkey }: ReferenceProps): import("@alloy-js/core").Children;
13
+ //# sourceMappingURL=Reference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Reference.d.ts","sourceRoot":"","sources":["../../../src/components/Reference.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwB,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAG9D,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,EAAE,cAAc,qCAMnD"}
@@ -0,0 +1,18 @@
1
+ import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { computed, emitSymbol } from "@alloy-js/core";
3
+ import { ref } from "../symbols/index.js";
4
+ /**
5
+ * A Python reference to a symbol, such as a variable, function, or class.
6
+ *
7
+ * @remarks
8
+ * This component is used to render references to symbols in Python code.
9
+ * It takes a `refkey` prop which is the key of the symbol to reference.
10
+ */
11
+ export function Reference({
12
+ refkey
13
+ }) {
14
+ const reference = ref(refkey);
15
+ const symbolRef = computed(() => reference()[1]);
16
+ emitSymbol(symbolRef);
17
+ return [_$memo(() => reference()[0])];
18
+ }
@@ -0,0 +1,46 @@
1
+ import { ComponentContext, type Children } from "@alloy-js/core";
2
+ import { PythonModuleScope } from "../symbols/index.js";
3
+ export interface PythonSourceFileContext {
4
+ scope: PythonModuleScope;
5
+ /** The module name for this file, e.g. 'test' for test.py */
6
+ module: string;
7
+ }
8
+ export declare const PythonSourceFileContext: ComponentContext<PythonSourceFileContext>;
9
+ export declare function useSourceFile(): PythonSourceFileContext;
10
+ export interface SourceFileProps {
11
+ /**
12
+ * The path to the file relative to the source directory.
13
+ */
14
+ path: string;
15
+ /**
16
+ * Content to add to the file, such as function definitions, class definitions, and variable declarations.
17
+ */
18
+ children?: Children;
19
+ /**
20
+ * Header comment to add to the file, which will be rendered at the top of the file.
21
+ */
22
+ header?: Children;
23
+ /**
24
+ * Comment to add to the header, which will be rendered as a comment in the file.
25
+ */
26
+ headerComment?: string;
27
+ }
28
+ /**
29
+ * A Python source file component that represents a Python file in the source directory.
30
+ * It provides a scope for the file, which is a `PythonModuleScope` that contains
31
+ * all the symbols defined in the file, such as functions, classes, and variables.
32
+ *
33
+ * @example
34
+ * ```tsx
35
+ * <SourceFile path="test.py">
36
+ * <FunctionDeclaration name="test" />
37
+ * </SourceFile>
38
+ * ```
39
+ * renders to
40
+ * ```py
41
+ * def test():
42
+ * pass
43
+ * ```
44
+ */
45
+ export declare function SourceFile(props: SourceFileProps): Children;
46
+ //# sourceMappingURL=SourceFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SourceFile.d.ts","sourceRoot":"","sources":["../../../src/components/SourceFile.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAQhB,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,iBAAiB,CAAC;IACzB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,uBAAuB,EAAE,gBAAgB,CAAC,uBAAuB,CAC3B,CAAC;AAEpD,wBAAgB,aAAa,4BAE5B;AAED,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;OAEG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YA2BhD"}
@@ -0,0 +1,75 @@
1
+ import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { SourceFile as CoreSourceFile, createNamedContext, List, Scope, Show, SourceDirectoryContext, useContext } from "@alloy-js/core";
3
+ import { join } from "pathe";
4
+ import { PythonModuleScope } from "../symbols/index.js";
5
+ import { ImportStatements } from "./ImportStatement.js";
6
+ import { Reference } from "./Reference.js";
7
+ export const PythonSourceFileContext = createNamedContext("@alloy-js/python SourceFile");
8
+ export function useSourceFile() {
9
+ return useContext(PythonSourceFileContext);
10
+ }
11
+ /**
12
+ * A Python source file component that represents a Python file in the source directory.
13
+ * It provides a scope for the file, which is a `PythonModuleScope` that contains
14
+ * all the symbols defined in the file, such as functions, classes, and variables.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * <SourceFile path="test.py">
19
+ * <FunctionDeclaration name="test" />
20
+ * </SourceFile>
21
+ * ```
22
+ * renders to
23
+ * ```py
24
+ * def test():
25
+ * pass
26
+ * ```
27
+ */
28
+ export function SourceFile(props) {
29
+ const directoryContext = useContext(SourceDirectoryContext);
30
+ const currentDir = directoryContext.path;
31
+ // Name of the scope is derived from the file path, minus the .py extension, and with slashes replaced by dots
32
+ const path = join(currentDir, props.path).replace(/\.py$/, "").replace(/\//g, ".");
33
+ const scope = new PythonModuleScope(path);
34
+ const sfContext = {
35
+ scope: scope,
36
+ module: path
37
+ };
38
+ return _$createComponent(CoreSourceFile, {
39
+ get path() {
40
+ return props.path;
41
+ },
42
+ filetype: "py",
43
+ reference: Reference,
44
+ get children() {
45
+ return [_$createComponent(Show, {
46
+ get when() {
47
+ return scope.importedModules.size > 0;
48
+ },
49
+ get children() {
50
+ return [_$createComponent(ImportStatements, {
51
+ get records() {
52
+ return scope.importedModules;
53
+ }
54
+ }), _$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {})];
55
+ }
56
+ }), _$createComponent(PythonSourceFileContext.Provider, {
57
+ value: sfContext,
58
+ get children() {
59
+ return _$createComponent(Scope, {
60
+ value: scope,
61
+ kind: "source-file",
62
+ get children() {
63
+ return _$createComponent(List, {
64
+ doubleHardline: true,
65
+ get children() {
66
+ return props.children;
67
+ }
68
+ });
69
+ }
70
+ });
71
+ }
72
+ })];
73
+ }
74
+ });
75
+ }
@@ -0,0 +1,25 @@
1
+ import { Children } from "@alloy-js/core";
2
+ export interface StatementListProps {
3
+ children: Children;
4
+ }
5
+ /**
6
+ * A Python statement list, which is a list of statements that can be rendered
7
+ * in a Python source file.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * <StatementList>
12
+ * <FunctionDeclaration name="test" />
13
+ * <VariableDeclaration name="x" value={42} />
14
+ * </StatementList>
15
+ * ```
16
+ * renders to
17
+ * ```py
18
+ * def test():
19
+ * pass
20
+ *
21
+ * x = 42
22
+ * ```
23
+ */
24
+ export declare function StatementList(props: StatementListProps): Children;
25
+ //# sourceMappingURL=StatementList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatementList.d.ts","sourceRoot":"","sources":["../../../src/components/StatementList.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,YAEtD"}
@@ -0,0 +1,29 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { List } from "@alloy-js/core";
3
+ /**
4
+ * A Python statement list, which is a list of statements that can be rendered
5
+ * in a Python source file.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * <StatementList>
10
+ * <FunctionDeclaration name="test" />
11
+ * <VariableDeclaration name="x" value={42} />
12
+ * </StatementList>
13
+ * ```
14
+ * renders to
15
+ * ```py
16
+ * def test():
17
+ * pass
18
+ *
19
+ * x = 42
20
+ * ```
21
+ */
22
+ export function StatementList(props) {
23
+ return _$createComponent(List, {
24
+ hardline: true,
25
+ get children() {
26
+ return props.children;
27
+ }
28
+ });
29
+ }
@@ -0,0 +1,62 @@
1
+ import { Children } from "@alloy-js/core";
2
+ import { BaseDeclarationProps } from "./Declaration.jsx";
3
+ export interface VariableDeclarationProps extends BaseDeclarationProps {
4
+ /**
5
+ * The initial value of the variable.
6
+ */
7
+ initializer?: Children;
8
+ /**
9
+ * The type of the variable. Used only for type annotation. Optional.
10
+ */
11
+ type?: Children;
12
+ /**
13
+ * Indicates if we should omit the None assignment. Optional.
14
+ */
15
+ omitNone?: boolean;
16
+ /**
17
+ * Indicates if this is a call statement variable. Optional.
18
+ * This is used to handle cases where the variable is part of a call statement.
19
+ */
20
+ callStatementVar?: boolean;
21
+ /**
22
+ * Indicates if this variable is an instance variable. Optional.
23
+ * This is used to handle cases where the variable is part of a class instance.
24
+ */
25
+ instanceVariable?: boolean;
26
+ }
27
+ /**
28
+ * A variable declaration component for Python.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * <VariableDeclaration
33
+ * name="myVar"
34
+ * type="int"
35
+ * initializer={42} // Initial value
36
+ * />
37
+ * <VariableDeclaration
38
+ * name="myOtherVar"
39
+ * type="str"
40
+ * omitNone={true}
41
+ * />
42
+ * <VariableDeclaration
43
+ * name="myCallStmtVar"
44
+ * callStatementVar={true}
45
+ * initializer={12}
46
+ * />
47
+ * VariableDeclaration
48
+ * name=""
49
+ * callStatementVar={true}
50
+ * initializer={12}
51
+ * />
52
+ * ```
53
+ * renders to
54
+ * ```py
55
+ * myVar: int = 42
56
+ * myOtherVar: str
57
+ * myCallStmtVar=12
58
+ * 12
59
+ * ```
60
+ */
61
+ export declare function VariableDeclaration(props: VariableDeclarationProps): Children;
62
+ //# sourceMappingURL=VariableDeclaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VariableDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/VariableDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAYT,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGzD,MAAM,WAAW,wBAAyB,SAAQ,oBAAoB;IACpE;;OAEG;IACH,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,YAqGlE"}