@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,48 @@
1
+ import { Children, OutputSymbolFlags, Refkey } from "@alloy-js/core";
2
+ import { PythonElements } from "../name-policy.js";
3
+ import { PythonOutputSymbol } from "../symbols/index.js";
4
+ export interface BaseDeclarationProps {
5
+ /**
6
+ * The base name of this declaration. May change depending on naming policy
7
+ * and any conflicts.
8
+ */
9
+ name: string;
10
+ /**
11
+ * The refkey or array of refkeys for this declaration.
12
+ */
13
+ refkey?: Refkey | Refkey[];
14
+ /**
15
+ * Flags for the symbol created by this component.
16
+ */
17
+ flags?: OutputSymbolFlags;
18
+ children?: Children;
19
+ /**
20
+ * Documentation for this declaration
21
+ */
22
+ doc?: Children;
23
+ }
24
+ export interface DeclarationProps extends Omit<BaseDeclarationProps, "name"> {
25
+ /**
26
+ * The name of this declaration.
27
+ */
28
+ name?: string;
29
+ /**
30
+ * The name policy kind to apply to the declaration.
31
+ */
32
+ nameKind?: PythonElements;
33
+ /**
34
+ * The symbol to use for this declaration.
35
+ */
36
+ symbol?: PythonOutputSymbol;
37
+ }
38
+ /**
39
+ * A Python declaration, which can be a class, function, variable, etc.
40
+ *
41
+ * @remarks
42
+ * This component is used to create a declaration with a symbol that can be
43
+ * referenced in the code. It can also be used to create a member scope for
44
+ * member containers.
45
+ *
46
+ */
47
+ export declare function Declaration(props: DeclarationProps): Children;
48
+ //# sourceMappingURL=Declaration.d.ts.map
@@ -0,0 +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,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE3B;;OAEG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAE1B,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;OAEG;IACH,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC;IAC1E;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YA4BlD"}
@@ -0,0 +1,37 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { Declaration as CoreDeclaration, MemberScope, OutputSymbolFlags } from "@alloy-js/core";
3
+ import { createPythonSymbol } from "../symbol-creation.js";
4
+ /**
5
+ * A Python declaration, which can be a class, function, variable, etc.
6
+ *
7
+ * @remarks
8
+ * This component is used to create a declaration with a symbol that can be
9
+ * referenced in the code. It can also be used to create a member scope for
10
+ * member containers.
11
+ *
12
+ */
13
+ export function Declaration(props) {
14
+ let sym;
15
+ if (props.symbol) {
16
+ sym = props.symbol;
17
+ } else {
18
+ sym = createPythonSymbol(props.name, {
19
+ refkeys: props.refkey,
20
+ flags: props.flags
21
+ }, props.nameKind, true);
22
+ }
23
+ function withMemberScope(children) {
24
+ return _$createComponent(MemberScope, {
25
+ owner: sym,
26
+ children: children
27
+ });
28
+ }
29
+ let children = () => props.children;
30
+ if (sym.flags & OutputSymbolFlags.MemberContainer) {
31
+ children = withMemberScope(children);
32
+ }
33
+ return _$createComponent(CoreDeclaration, {
34
+ symbol: sym,
35
+ children: children
36
+ });
37
+ }
@@ -0,0 +1,164 @@
1
+ import { Children } from "@alloy-js/core";
2
+ import { BaseDeclarationProps } from "./Declaration.js";
3
+ export interface EnumProps extends BaseDeclarationProps {
4
+ /**
5
+ * The base type of the enum. One of: 'Enum', 'IntEnum', 'StrEnum', 'Flag', 'IntFlag'.
6
+ * Defaults to 'Enum'.
7
+ */
8
+ baseType?: "Enum" | "IntEnum" | "StrEnum" | "Flag" | "IntFlag";
9
+ /**
10
+ * Members of the enum as an array of objects.
11
+ */
12
+ members?: Array<{
13
+ name: string;
14
+ value?: Children;
15
+ jsValue?: string | number;
16
+ doc?: string;
17
+ }>;
18
+ /**
19
+ * The enum style: 'classic' (default), 'auto', or 'functional'.
20
+ */
21
+ style?: "classic" | "auto" | "functional";
22
+ /**
23
+ * Optional docstring for the enum.
24
+ */
25
+ doc?: Children;
26
+ }
27
+ /**
28
+ * A Python enum declaration, following https://docs.python.org/3.11/library/enum.html.
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * <EnumDeclaration name="Direction" style="functional">
33
+ * members={[
34
+ * { name: "NORTH" },
35
+ * { name: "SOUTH" },
36
+ * { name: "EAST" },
37
+ * { name: "WEST" },
38
+ * ]}
39
+ * />
40
+ * ```
41
+ * This will generate:
42
+ * ```python
43
+ * from enum import Enum
44
+ * class Direction(Enum):
45
+ * NORTH = "NORTH"
46
+ * SOUTH = "SOUTH"
47
+ * EAST = "EAST"
48
+ * WEST = "WEST"
49
+ * ```
50
+ */
51
+ export declare function EnumDeclaration(props: EnumProps): Children;
52
+ /**
53
+ * Create a Python enum using the functional syntax.
54
+ *
55
+ * This generates enums using the `Enum('Name', [...])` or `Enum('Name', {...})` syntax.
56
+ * The format depends on whether enum members have explicit values:
57
+ * - Members without values: `Enum('Direction', ['NORTH', 'SOUTH', 'EAST', 'WEST'])`
58
+ * - Members with values: `Enum('Direction', {'NORTH': 1, 'SOUTH': 2, 'EAST': 3, 'WEST': 4})`
59
+ *
60
+ * @example
61
+ * ```tsx
62
+ * <FunctionalEnumDeclaration
63
+ * name="Direction"
64
+ * members={[
65
+ * { name: "NORTH" },
66
+ * { name: "SOUTH" },
67
+ * { name: "EAST" },
68
+ * { name: "WEST" }
69
+ * ]}
70
+ * />
71
+ * ```
72
+ * renders to:
73
+ * ```python
74
+ * Direction = Enum('Direction', ['NORTH', 'SOUTH', 'EAST', 'WEST'])
75
+ * ```
76
+ *
77
+ * @example
78
+ * ```tsx
79
+ * <FunctionalEnumDeclaration
80
+ * name="Status"
81
+ * members={[
82
+ * { name: "PENDING", value: 1 },
83
+ * { name: "ACTIVE", value: 2 },
84
+ * { name: "INACTIVE", value: 3 }
85
+ * ]}
86
+ * />
87
+ * ```
88
+ * renders to:
89
+ * ```python
90
+ * Status = Enum('Status', {'PENDING': 1, 'ACTIVE': 2, 'INACTIVE': 3})
91
+ * ```
92
+ */
93
+ export declare function FunctionalEnumDeclaration(props: EnumProps): Children;
94
+ /**
95
+ * Create a Python enum using the class-based syntax.
96
+ *
97
+ * This generates enums using the `class Name(Enum):` syntax with member definitions
98
+ * inside the class body. Supports various member value styles including auto-generated
99
+ * values, explicit values, and custom base types.
100
+ *
101
+ * @example
102
+ * ```tsx
103
+ * <ClassEnumDeclaration
104
+ * name="Direction"
105
+ * members={[
106
+ * { name: "NORTH" },
107
+ * { name: "SOUTH" },
108
+ * { name: "EAST" },
109
+ * { name: "WEST" }
110
+ * ]}
111
+ * />
112
+ * ```
113
+ * renders to:
114
+ * ```python
115
+ * class Direction(Enum):
116
+ * NORTH = "NORTH"
117
+ * SOUTH = "SOUTH"
118
+ * EAST = "EAST"
119
+ * WEST = "WEST"
120
+ * ```
121
+ *
122
+ * @example
123
+ * With explicit values:
124
+ * ```tsx
125
+ * <ClassEnumDeclaration
126
+ * name="Status"
127
+ * members={[
128
+ * { name: "PENDING", value: 1 },
129
+ * { name: "ACTIVE", value: 2 },
130
+ * { name: "INACTIVE", value: 3 }
131
+ * ]}
132
+ * />
133
+ * ```
134
+ * renders to:
135
+ * ```python
136
+ * class Status(Enum):
137
+ * PENDING = 1
138
+ * ACTIVE = 2
139
+ * INACTIVE = 3
140
+ * ```
141
+ *
142
+ * @example
143
+ * With auto() values:
144
+ * ```tsx
145
+ * <ClassEnumDeclaration
146
+ * name="Color"
147
+ * style="auto"
148
+ * members={[
149
+ * { name: "RED" },
150
+ * { name: "GREEN" },
151
+ * { name: "BLUE" }
152
+ * ]}
153
+ * />
154
+ * ```
155
+ * renders to:
156
+ * ```python
157
+ * class Color(Enum):
158
+ * RED = auto()
159
+ * GREEN = auto()
160
+ * BLUE = auto()
161
+ * ```
162
+ */
163
+ export declare function ClassEnumDeclaration(props: EnumProps): Children;
164
+ //# sourceMappingURL=EnumDeclaration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnumDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/EnumDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAQT,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAKxD,MAAM,WAAW,SAAU,SAAQ,oBAAoB;IACrD;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IAC/D;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,QAAQ,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IACH;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,YAAY,CAAC;IAC1C;;OAEG;IACH,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,YAM/C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,SAAS,YA+CzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,YAwDpD"}
@@ -0,0 +1,278 @@
1
+ import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
2
+ import { Declaration as CoreDeclaration, For, MemberScope, OutputSymbolFlags, Scope, Show, useBinder } from "@alloy-js/core";
3
+ import { enumModule } from "../builtins/python.js";
4
+ import { createPythonSymbol } from "../symbol-creation.js";
5
+ import { usePythonScope } from "../symbols/scopes.js";
6
+ import { EnumMember } from "./EnumMember.js";
7
+ import { PythonBlock } from "./PythonBlock.js";
8
+ import { SimpleCommentBlock } from "./index.js";
9
+ /**
10
+ * A Python enum declaration, following https://docs.python.org/3.11/library/enum.html.
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * <EnumDeclaration name="Direction" style="functional">
15
+ * members={[
16
+ * { name: "NORTH" },
17
+ * { name: "SOUTH" },
18
+ * { name: "EAST" },
19
+ * { name: "WEST" },
20
+ * ]}
21
+ * />
22
+ * ```
23
+ * This will generate:
24
+ * ```python
25
+ * from enum import Enum
26
+ * class Direction(Enum):
27
+ * NORTH = "NORTH"
28
+ * SOUTH = "SOUTH"
29
+ * EAST = "EAST"
30
+ * WEST = "WEST"
31
+ * ```
32
+ */
33
+ export function EnumDeclaration(props) {
34
+ // Handle enum styles
35
+ if (props.style === "functional") {
36
+ return _$createComponent(FunctionalEnumDeclaration, props);
37
+ }
38
+ return _$createComponent(ClassEnumDeclaration, props);
39
+ }
40
+
41
+ /**
42
+ * Create a Python enum using the functional syntax.
43
+ *
44
+ * This generates enums using the `Enum('Name', [...])` or `Enum('Name', {...})` syntax.
45
+ * The format depends on whether enum members have explicit values:
46
+ * - Members without values: `Enum('Direction', ['NORTH', 'SOUTH', 'EAST', 'WEST'])`
47
+ * - Members with values: `Enum('Direction', {'NORTH': 1, 'SOUTH': 2, 'EAST': 3, 'WEST': 4})`
48
+ *
49
+ * @example
50
+ * ```tsx
51
+ * <FunctionalEnumDeclaration
52
+ * name="Direction"
53
+ * members={[
54
+ * { name: "NORTH" },
55
+ * { name: "SOUTH" },
56
+ * { name: "EAST" },
57
+ * { name: "WEST" }
58
+ * ]}
59
+ * />
60
+ * ```
61
+ * renders to:
62
+ * ```python
63
+ * Direction = Enum('Direction', ['NORTH', 'SOUTH', 'EAST', 'WEST'])
64
+ * ```
65
+ *
66
+ * @example
67
+ * ```tsx
68
+ * <FunctionalEnumDeclaration
69
+ * name="Status"
70
+ * members={[
71
+ * { name: "PENDING", value: 1 },
72
+ * { name: "ACTIVE", value: 2 },
73
+ * { name: "INACTIVE", value: 3 }
74
+ * ]}
75
+ * />
76
+ * ```
77
+ * renders to:
78
+ * ```python
79
+ * Status = Enum('Status', {'PENDING': 1, 'ACTIVE': 2, 'INACTIVE': 3})
80
+ * ```
81
+ */
82
+ export function FunctionalEnumDeclaration(props) {
83
+ const binder = useBinder();
84
+ const scope = usePythonScope();
85
+ const sym = createPythonSymbol(props.name, {
86
+ binder: binder,
87
+ scope: scope,
88
+ refkeys: props.refkey,
89
+ flags: OutputSymbolFlags.StaticMemberContainer
90
+ }, "enum", false);
91
+ const members = props.members ?? [];
92
+ let opener, ender;
93
+ if (members.length && members.every(m => m.value === undefined)) {
94
+ // List of names: Enum('Direction', ['NORTH', ...])
95
+ opener = "[";
96
+ ender = "]";
97
+ } else {
98
+ // List of name-value pairs: Enum('Direction', {'NORTH': 1, ...})
99
+ opener = "{";
100
+ ender = "}";
101
+ }
102
+ const memberExpr = [opener, _$createComponent(For, {
103
+ each: members,
104
+ joiner: ", ",
105
+ children: m => _$createComponent(EnumMember, {
106
+ get name() {
107
+ return m.name;
108
+ },
109
+ get value() {
110
+ return m.value;
111
+ },
112
+ functional: true
113
+ })
114
+ }), ender];
115
+ return [_$createComponent(CoreDeclaration, {
116
+ symbol: sym,
117
+ get children() {
118
+ return [_$memo(() => sym.name), " = ", _$memo(() => enumModule["."].Enum), "('", _$memo(() => sym.name), "',", " ", _$createComponent(MemberScope, {
119
+ owner: sym,
120
+ get children() {
121
+ return _$createComponent(Scope, {
122
+ get name() {
123
+ return props.name;
124
+ },
125
+ kind: "enum",
126
+ children: memberExpr
127
+ });
128
+ }
129
+ }), ")"];
130
+ }
131
+ })];
132
+ }
133
+
134
+ /**
135
+ * Create a Python enum using the class-based syntax.
136
+ *
137
+ * This generates enums using the `class Name(Enum):` syntax with member definitions
138
+ * inside the class body. Supports various member value styles including auto-generated
139
+ * values, explicit values, and custom base types.
140
+ *
141
+ * @example
142
+ * ```tsx
143
+ * <ClassEnumDeclaration
144
+ * name="Direction"
145
+ * members={[
146
+ * { name: "NORTH" },
147
+ * { name: "SOUTH" },
148
+ * { name: "EAST" },
149
+ * { name: "WEST" }
150
+ * ]}
151
+ * />
152
+ * ```
153
+ * renders to:
154
+ * ```python
155
+ * class Direction(Enum):
156
+ * NORTH = "NORTH"
157
+ * SOUTH = "SOUTH"
158
+ * EAST = "EAST"
159
+ * WEST = "WEST"
160
+ * ```
161
+ *
162
+ * @example
163
+ * With explicit values:
164
+ * ```tsx
165
+ * <ClassEnumDeclaration
166
+ * name="Status"
167
+ * members={[
168
+ * { name: "PENDING", value: 1 },
169
+ * { name: "ACTIVE", value: 2 },
170
+ * { name: "INACTIVE", value: 3 }
171
+ * ]}
172
+ * />
173
+ * ```
174
+ * renders to:
175
+ * ```python
176
+ * class Status(Enum):
177
+ * PENDING = 1
178
+ * ACTIVE = 2
179
+ * INACTIVE = 3
180
+ * ```
181
+ *
182
+ * @example
183
+ * With auto() values:
184
+ * ```tsx
185
+ * <ClassEnumDeclaration
186
+ * name="Color"
187
+ * style="auto"
188
+ * members={[
189
+ * { name: "RED" },
190
+ * { name: "GREEN" },
191
+ * { name: "BLUE" }
192
+ * ]}
193
+ * />
194
+ * ```
195
+ * renders to:
196
+ * ```python
197
+ * class Color(Enum):
198
+ * RED = auto()
199
+ * GREEN = auto()
200
+ * BLUE = auto()
201
+ * ```
202
+ */
203
+ export function ClassEnumDeclaration(props) {
204
+ const baseType = props.baseType || "Enum";
205
+ const binder = useBinder();
206
+ const scope = usePythonScope();
207
+ const sym = createPythonSymbol(props.name, {
208
+ binder: binder,
209
+ scope: scope,
210
+ refkeys: props.refkey,
211
+ flags: OutputSymbolFlags.StaticMemberContainer
212
+ }, "enum", false);
213
+ let memberList = (props.members ?? []).map(m => m.value === undefined ? {
214
+ ...m,
215
+ auto: false
216
+ } : m);
217
+ if (props.style === "auto") {
218
+ memberList = memberList.map(m => m.value === undefined ? {
219
+ name: m.name,
220
+ auto: true
221
+ } : m);
222
+ }
223
+ return _$createComponent(CoreDeclaration, {
224
+ symbol: sym,
225
+ get children() {
226
+ return [_$createComponent(Show, {
227
+ get when() {
228
+ return Boolean(props.doc);
229
+ },
230
+ get children() {
231
+ return [_$createComponent(SimpleCommentBlock, {
232
+ get children() {
233
+ return props.doc;
234
+ }
235
+ }), _$createIntrinsic("hbr", {})];
236
+ }
237
+ }), "class ", _$memo(() => sym.name), "(", _$memo(() => enumModule["."][baseType]), ")", _$createComponent(MemberScope, {
238
+ owner: sym,
239
+ get children() {
240
+ return _$createComponent(Scope, {
241
+ get name() {
242
+ return sym.name;
243
+ },
244
+ kind: "enum",
245
+ get children() {
246
+ return _$createComponent(PythonBlock, {
247
+ opener: ":",
248
+ get children() {
249
+ return [_$createComponent(For, {
250
+ each: memberList,
251
+ hardline: true,
252
+ children: member => _$createComponent(EnumMember, {
253
+ get name() {
254
+ return member.name;
255
+ },
256
+ get value() {
257
+ return member.value;
258
+ },
259
+ get jsValue() {
260
+ return member.jsValue;
261
+ },
262
+ get auto() {
263
+ return member.auto;
264
+ },
265
+ get doc() {
266
+ return member.doc;
267
+ }
268
+ })
269
+ }), _$memo(() => props.children)];
270
+ }
271
+ });
272
+ }
273
+ });
274
+ }
275
+ })];
276
+ }
277
+ });
278
+ }
@@ -0,0 +1,46 @@
1
+ import { Children, Refkey } from "@alloy-js/core";
2
+ export interface EnumMemberProps {
3
+ /**
4
+ * The name of the enum member.
5
+ */
6
+ name: string;
7
+ /**
8
+ * Refkey for the enum member symbol. If the refkey is not provided, a symbol
9
+ * will be created and the member cannot be referenced by refkey.
10
+ */
11
+ refkey?: Refkey;
12
+ /**
13
+ * The value of the enum member.
14
+ */
15
+ value?: Children;
16
+ /**
17
+ * The JS value of the enum member.
18
+ */
19
+ jsValue?: string | number;
20
+ /**
21
+ * Functional mappings/list
22
+ */
23
+ functional?: boolean;
24
+ /**
25
+ * Will use auto() to generate the value if set to true.
26
+ */
27
+ auto?: boolean;
28
+ /**
29
+ * Documentation for the enum member.
30
+ */
31
+ doc?: Children;
32
+ }
33
+ /**
34
+ * A Python enum member.
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * <EnumMember name="NORTH" />
39
+ * ```
40
+ * This will generate:
41
+ * ```python
42
+ * NORTH
43
+ * ```
44
+ */
45
+ export declare function EnumMember(props: EnumMemberProps): Children;
46
+ //# sourceMappingURL=EnumMember.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnumMember.d.ts","sourceRoot":"","sources":["../../../src/components/EnumMember.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,MAAM,EAAQ,MAAM,gBAAgB,CAAC;AAO3E,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,QAAQ,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAE1B;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAkChD"}
@@ -0,0 +1,67 @@
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { OutputSymbolFlags, Show } from "@alloy-js/core";
3
+ import { enumModule } from "../builtins/python.js";
4
+ import { createPythonSymbol } from "../symbol-creation.js";
5
+ import { Atom } from "./Atom.js";
6
+ import { SimpleInlineComment } from "./index.js";
7
+ /**
8
+ * A Python enum member.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * <EnumMember name="NORTH" />
13
+ * ```
14
+ * This will generate:
15
+ * ```python
16
+ * NORTH
17
+ * ```
18
+ */
19
+ export function EnumMember(props) {
20
+ const autoReference = props.auto === true ? enumModule["."].auto : undefined;
21
+ const value = props.auto === true ? [autoReference, "()"] : props.value;
22
+ const sym = createPythonSymbol(props.name, {
23
+ refkeys: props.refkey,
24
+ flags: OutputSymbolFlags.StaticMember
25
+ }, "enum-member", true);
26
+ const valueCode = props.jsValue !== undefined ? _$createComponent(Atom, {
27
+ get jsValue() {
28
+ return props.jsValue;
29
+ }
30
+ }) : value;
31
+ if (props.functional) {
32
+ return ["'", _$memo(() => sym.name), "'", _$createComponent(Show, {
33
+ when: valueCode !== undefined,
34
+ get children() {
35
+ return [" : ", valueCode];
36
+ }
37
+ }), _$createComponent(Show, {
38
+ get when() {
39
+ return props.doc !== undefined;
40
+ },
41
+ get children() {
42
+ return _$createComponent(SimpleInlineComment, {
43
+ get children() {
44
+ return props.doc;
45
+ }
46
+ });
47
+ }
48
+ })];
49
+ }
50
+ return [_$memo(() => sym.name), _$createComponent(Show, {
51
+ when: valueCode !== undefined,
52
+ get children() {
53
+ return [" = ", valueCode];
54
+ }
55
+ }), _$createComponent(Show, {
56
+ get when() {
57
+ return props.doc !== undefined;
58
+ },
59
+ get children() {
60
+ return _$createComponent(SimpleInlineComment, {
61
+ get children() {
62
+ return props.doc;
63
+ }
64
+ });
65
+ }
66
+ })];
67
+ }
@@ -0,0 +1,19 @@
1
+ import { Children } from "@alloy-js/core";
2
+ export interface FunctionCallExpressionProps {
3
+ target: Children;
4
+ args?: Children[];
5
+ }
6
+ /**
7
+ * A Python function call expression.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * <FunctionCallExpression target="foo" args={["arg1", "arg2"]} />
12
+ * ```
13
+ * This will generate:
14
+ * ```python
15
+ * foo(arg1, arg2)
16
+ * ```
17
+ */
18
+ export declare function FunctionCallExpression(props: FunctionCallExpressionProps): Children;
19
+ //# sourceMappingURL=FunctionCallExpression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionCallExpression.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionCallExpression.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAqB,MAAM,gBAAgB,CAAC;AAE7D,MAAM,WAAW,2BAA2B;IAC1C,MAAM,EAAE,QAAQ,CAAC;IACjB,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,YAgBxE"}