@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.
- package/CHANGELOG.md +3 -0
- package/LICENSE +7 -0
- package/api-extractor.json +4 -0
- package/dist/src/builtins/python.d.ts +9 -0
- package/dist/src/builtins/python.d.ts.map +1 -0
- package/dist/src/builtins/python.js +17 -0
- package/dist/src/components/Atom.d.ts +19 -0
- package/dist/src/components/Atom.d.ts.map +1 -0
- package/dist/src/components/Atom.js +82 -0
- package/dist/src/components/CallSignature.d.ts +79 -0
- package/dist/src/components/CallSignature.d.ts.map +1 -0
- package/dist/src/components/CallSignature.js +201 -0
- package/dist/src/components/ClassDeclaration.d.ts +37 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
- package/dist/src/components/ClassDeclaration.js +83 -0
- package/dist/src/components/ClassInstantiation.d.ts +24 -0
- package/dist/src/components/ClassInstantiation.d.ts.map +1 -0
- package/dist/src/components/ClassInstantiation.js +35 -0
- package/dist/src/components/Declaration.d.ts +48 -0
- package/dist/src/components/Declaration.d.ts.map +1 -0
- package/dist/src/components/Declaration.js +37 -0
- package/dist/src/components/EnumDeclaration.d.ts +164 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
- package/dist/src/components/EnumDeclaration.js +278 -0
- package/dist/src/components/EnumMember.d.ts +46 -0
- package/dist/src/components/EnumMember.d.ts.map +1 -0
- package/dist/src/components/EnumMember.js +67 -0
- package/dist/src/components/FunctionCallExpression.d.ts +19 -0
- package/dist/src/components/FunctionCallExpression.d.ts.map +1 -0
- package/dist/src/components/FunctionCallExpression.js +40 -0
- package/dist/src/components/FunctionDeclaration.d.ts +47 -0
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -0
- package/dist/src/components/FunctionDeclaration.js +107 -0
- package/dist/src/components/ImportStatement.d.ts +39 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -0
- package/dist/src/components/ImportStatement.js +104 -0
- package/dist/src/components/MemberExpression.d.ts +97 -0
- package/dist/src/components/MemberExpression.d.ts.map +1 -0
- package/dist/src/components/MemberExpression.js +308 -0
- package/dist/src/components/NoNamePolicy.d.ts +23 -0
- package/dist/src/components/NoNamePolicy.d.ts.map +1 -0
- package/dist/src/components/NoNamePolicy.js +27 -0
- package/dist/src/components/PyDoc.d.ts +90 -0
- package/dist/src/components/PyDoc.d.ts.map +1 -0
- package/dist/src/components/PyDoc.js +280 -0
- package/dist/src/components/PythonBlock.d.ts +23 -0
- package/dist/src/components/PythonBlock.d.ts.map +1 -0
- package/dist/src/components/PythonBlock.js +31 -0
- package/dist/src/components/Reference.d.ts +13 -0
- package/dist/src/components/Reference.d.ts.map +1 -0
- package/dist/src/components/Reference.js +18 -0
- package/dist/src/components/SourceFile.d.ts +46 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -0
- package/dist/src/components/SourceFile.js +75 -0
- package/dist/src/components/StatementList.d.ts +25 -0
- package/dist/src/components/StatementList.d.ts.map +1 -0
- package/dist/src/components/StatementList.js +29 -0
- package/dist/src/components/VariableDeclaration.d.ts +62 -0
- package/dist/src/components/VariableDeclaration.d.ts.map +1 -0
- package/dist/src/components/VariableDeclaration.js +131 -0
- package/dist/src/components/index.d.ts +19 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +18 -0
- package/dist/src/create-module.d.ts +16 -0
- package/dist/src/create-module.d.ts.map +1 -0
- package/dist/src/create-module.js +64 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/name-policy.d.ts +5 -0
- package/dist/src/name-policy.d.ts.map +1 -0
- package/dist/src/name-policy.js +47 -0
- package/dist/src/parameter-descriptor.d.ts +31 -0
- package/dist/src/parameter-descriptor.d.ts.map +1 -0
- package/dist/src/parameter-descriptor.js +1 -0
- package/dist/src/symbol-creation.d.ts +4 -0
- package/dist/src/symbol-creation.d.ts.map +1 -0
- package/dist/src/symbol-creation.js +24 -0
- package/dist/src/symbols/custom-output-scope.d.ts +10 -0
- package/dist/src/symbols/custom-output-scope.d.ts.map +1 -0
- package/dist/src/symbols/custom-output-scope.js +25 -0
- package/dist/src/symbols/index.d.ts +7 -0
- package/dist/src/symbols/index.d.ts.map +1 -0
- package/dist/src/symbols/index.js +6 -0
- package/dist/src/symbols/python-member-scope.d.ts +7 -0
- package/dist/src/symbols/python-member-scope.d.ts.map +1 -0
- package/dist/src/symbols/python-member-scope.js +9 -0
- package/dist/src/symbols/python-module-scope.d.ts +25 -0
- package/dist/src/symbols/python-module-scope.d.ts.map +1 -0
- package/dist/src/symbols/python-module-scope.js +52 -0
- package/dist/src/symbols/python-output-symbol.d.ts +19 -0
- package/dist/src/symbols/python-output-symbol.d.ts.map +1 -0
- package/dist/src/symbols/python-output-symbol.js +22 -0
- package/dist/src/symbols/reference.d.ts +4 -0
- package/dist/src/symbols/reference.d.ts.map +1 -0
- package/dist/src/symbols/reference.js +60 -0
- package/dist/src/symbols/scopes.d.ts +5 -0
- package/dist/src/symbols/scopes.d.ts.map +1 -0
- package/dist/src/symbols/scopes.js +4 -0
- package/dist/src/utils.d.ts +7 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +12 -0
- package/dist/test/callsignatures.test.d.ts +2 -0
- package/dist/test/callsignatures.test.d.ts.map +1 -0
- package/dist/test/callsignatures.test.js +276 -0
- package/dist/test/classdeclarations.test.d.ts +2 -0
- package/dist/test/classdeclarations.test.d.ts.map +1 -0
- package/dist/test/classdeclarations.test.js +397 -0
- package/dist/test/classinstantiations.test.d.ts +2 -0
- package/dist/test/classinstantiations.test.d.ts.map +1 -0
- package/dist/test/classinstantiations.test.js +168 -0
- package/dist/test/enums.test.d.ts +2 -0
- package/dist/test/enums.test.d.ts.map +1 -0
- package/dist/test/enums.test.js +211 -0
- package/dist/test/externals.test.d.ts +2 -0
- package/dist/test/externals.test.d.ts.map +1 -0
- package/dist/test/externals.test.js +219 -0
- package/dist/test/functioncallexpressions.test.d.ts +2 -0
- package/dist/test/functioncallexpressions.test.d.ts.map +1 -0
- package/dist/test/functioncallexpressions.test.js +156 -0
- package/dist/test/functiondeclaration.test.d.ts +2 -0
- package/dist/test/functiondeclaration.test.d.ts.map +1 -0
- package/dist/test/functiondeclaration.test.js +363 -0
- package/dist/test/imports.test.d.ts +2 -0
- package/dist/test/imports.test.d.ts.map +1 -0
- package/dist/test/imports.test.js +262 -0
- package/dist/test/memberexpressions.test.d.ts +2 -0
- package/dist/test/memberexpressions.test.d.ts.map +1 -0
- package/dist/test/memberexpressions.test.js +879 -0
- package/dist/test/namepolicies.test.d.ts +2 -0
- package/dist/test/namepolicies.test.d.ts.map +1 -0
- package/dist/test/namepolicies.test.js +109 -0
- package/dist/test/pydocs.test.d.ts +2 -0
- package/dist/test/pydocs.test.d.ts.map +1 -0
- package/dist/test/pydocs.test.js +500 -0
- package/dist/test/references.test.d.ts +2 -0
- package/dist/test/references.test.d.ts.map +1 -0
- package/dist/test/references.test.js +49 -0
- package/dist/test/sourcefiles.test.d.ts +2 -0
- package/dist/test/sourcefiles.test.d.ts.map +1 -0
- package/dist/test/sourcefiles.test.js +198 -0
- package/dist/test/utils.d.ts +23 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/utils.js +88 -0
- package/dist/test/values.test.d.ts +2 -0
- package/dist/test/values.test.d.ts.map +1 -0
- package/dist/test/values.test.js +78 -0
- package/dist/test/variables.test.d.ts +2 -0
- package/dist/test/variables.test.d.ts.map +1 -0
- package/dist/test/variables.test.js +173 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +39 -0
- package/src/builtins/python.ts +20 -0
- package/src/components/Atom.tsx +76 -0
- package/src/components/CallSignature.tsx +251 -0
- package/src/components/ClassDeclaration.tsx +98 -0
- package/src/components/ClassInstantiation.tsx +54 -0
- package/src/components/Declaration.tsx +91 -0
- package/src/components/EnumDeclaration.tsx +291 -0
- package/src/components/EnumMember.tsx +92 -0
- package/src/components/FunctionCallExpression.tsx +36 -0
- package/src/components/FunctionDeclaration.tsx +121 -0
- package/src/components/ImportStatement.tsx +134 -0
- package/src/components/MemberExpression.tsx +456 -0
- package/src/components/NoNamePolicy.tsx +31 -0
- package/src/components/PyDoc.tsx +331 -0
- package/src/components/PythonBlock.tsx +26 -0
- package/src/components/Reference.tsx +21 -0
- package/src/components/SourceFile.tsx +93 -0
- package/src/components/StatementList.tsx +28 -0
- package/src/components/VariableDeclaration.tsx +180 -0
- package/src/components/index.ts +18 -0
- package/src/create-module.ts +102 -0
- package/src/index.ts +7 -0
- package/src/name-policy.ts +101 -0
- package/src/parameter-descriptor.ts +36 -0
- package/src/symbol-creation.ts +36 -0
- package/src/symbols/custom-output-scope.ts +35 -0
- package/src/symbols/index.ts +6 -0
- package/src/symbols/python-member-scope.ts +12 -0
- package/src/symbols/python-module-scope.ts +89 -0
- package/src/symbols/python-output-symbol.ts +36 -0
- package/src/symbols/reference.ts +99 -0
- package/src/symbols/scopes.ts +9 -0
- package/src/utils.ts +27 -0
- package/temp/api.json +7207 -0
- package/test/callsignatures.test.tsx +256 -0
- package/test/classdeclarations.test.tsx +320 -0
- package/test/classinstantiations.test.tsx +159 -0
- package/test/enums.test.tsx +203 -0
- package/test/externals.test.tsx +190 -0
- package/test/functioncallexpressions.test.tsx +145 -0
- package/test/functiondeclaration.test.tsx +327 -0
- package/test/imports.test.tsx +214 -0
- package/test/memberexpressions.test.tsx +725 -0
- package/test/namepolicies.test.tsx +109 -0
- package/test/pydocs.test.tsx +528 -0
- package/test/references.test.tsx +36 -0
- package/test/sourcefiles.test.tsx +131 -0
- package/test/utils.tsx +131 -0
- package/test/values.test.tsx +61 -0
- package/test/variables.test.tsx +153 -0
- package/tsconfig.json +12 -0
- package/tsdoc-metadata.json +11 -0
- package/vitest.config.ts +10 -0
- package/vitest.setup.ts +1 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { createIntrinsic as _$createIntrinsic, memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { childrenArray, code, computed, For, isComponentCreator, reactive, ref, Show, takeSymbols, useBinder } from "@alloy-js/core";
|
|
3
|
+
const MEMBER_ACCESS_TYPES = {
|
|
4
|
+
ATTRIBUTE: "attribute",
|
|
5
|
+
SUBSCRIPTION: "subscription",
|
|
6
|
+
CALL: "call"
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Create a member expression from parts. Each part can provide one of
|
|
10
|
+
* the following:
|
|
11
|
+
*
|
|
12
|
+
* * **id**: The identifier for the member expression part
|
|
13
|
+
* * **refkey**: a refkey for a symbol whose name becomes the identifier
|
|
14
|
+
* * **symbol**: a symbol whose name becomes the identifier part
|
|
15
|
+
* * **args**: create a method call with the given args
|
|
16
|
+
* * **children**: arbitrary contents for the identifier part.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <MemberExpression>
|
|
22
|
+
* <MemberExpression.Part id="base" />
|
|
23
|
+
* <MemberExpression.Part refkey={rk} />
|
|
24
|
+
* <MemberExpression.Part symbol={sym} />
|
|
25
|
+
* <MemberExpression.Part args={["hello", "world"]} />
|
|
26
|
+
* <MemberExpression.Part>SomeValue</MemberExpression.Part>
|
|
27
|
+
* </MemberExpression>
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Assuming `rk` is a refkey to a symbol name "prop1", and `sym` is a symbol
|
|
31
|
+
* with a name of "prop2", this will render:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* base.prop1.prop2("hello", "world").SomeValue
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function MemberExpression(props) {
|
|
38
|
+
const children = childrenArray(() => props.children);
|
|
39
|
+
const parts = childrenToPartDescriptors(children);
|
|
40
|
+
// any symbols emitted from the children won't be relevant to
|
|
41
|
+
// parent scopes. TODO: emit the proper symbol if we know it?
|
|
42
|
+
takeSymbols();
|
|
43
|
+
if (parts.length === 0) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
return computed(() => {
|
|
47
|
+
return formatChain(parts);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Build part descriptors from the children of a MemberExpression.
|
|
53
|
+
*/
|
|
54
|
+
function childrenToPartDescriptors(children) {
|
|
55
|
+
const parts = [];
|
|
56
|
+
for (const child of children) {
|
|
57
|
+
if (!isComponentCreator(child, MemberExpression.Part)) {
|
|
58
|
+
// we ignore non-parts
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
parts.push(createPartDescriptorFromProps(child.props, child === children[0]));
|
|
62
|
+
}
|
|
63
|
+
return parts;
|
|
64
|
+
}
|
|
65
|
+
const exclusiveParts = ["args", "refkey", "symbol", "id", "key", "keys", "slice"];
|
|
66
|
+
/**
|
|
67
|
+
* Creates a reactive part descriptor from the given part props.
|
|
68
|
+
*
|
|
69
|
+
* @param partProps The props for the part.
|
|
70
|
+
* @param first Whether this is the first part in the expression. Refkeys are
|
|
71
|
+
* handled specially for the first part.
|
|
72
|
+
*/
|
|
73
|
+
function createPartDescriptorFromProps(partProps, first) {
|
|
74
|
+
const foundProps = exclusiveParts.filter(key => {
|
|
75
|
+
return key in partProps;
|
|
76
|
+
});
|
|
77
|
+
if (foundProps.length > 1) {
|
|
78
|
+
throw new Error(`Only one of ${foundProps.join(", ")} can be used for a MemberExpression part at a time`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Validate slice syntax
|
|
82
|
+
if (partProps.slice) {
|
|
83
|
+
const {
|
|
84
|
+
start,
|
|
85
|
+
stop,
|
|
86
|
+
step
|
|
87
|
+
} = partProps.slice;
|
|
88
|
+
if (!start && !stop && !step) {
|
|
89
|
+
throw new Error("MemberExpression.Part: slice object cannot be empty");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Validate keys array
|
|
94
|
+
if (partProps.keys?.length === 0) {
|
|
95
|
+
throw new Error("MemberExpression.Part: keys array cannot be empty");
|
|
96
|
+
}
|
|
97
|
+
const symbolSource = computed(() => {
|
|
98
|
+
if (partProps.refkey) {
|
|
99
|
+
return getSymbolForRefkey(partProps.refkey).value;
|
|
100
|
+
} else if (partProps.symbol) {
|
|
101
|
+
return partProps.symbol;
|
|
102
|
+
} else {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Return different descriptor types based on what props are provided
|
|
108
|
+
let part;
|
|
109
|
+
if (partProps.args !== undefined) {
|
|
110
|
+
// CallDescriptor
|
|
111
|
+
part = {
|
|
112
|
+
type: computed(() => {
|
|
113
|
+
return "call";
|
|
114
|
+
}),
|
|
115
|
+
args: ref(partProps.args === true ? [] : partProps.args)
|
|
116
|
+
};
|
|
117
|
+
} else if (partProps.key !== undefined || partProps.keys !== undefined || partProps.slice !== undefined) {
|
|
118
|
+
// SubscriptionDescriptor
|
|
119
|
+
part = {
|
|
120
|
+
type: computed(() => {
|
|
121
|
+
return "subscription";
|
|
122
|
+
}),
|
|
123
|
+
expression: computed(() => {
|
|
124
|
+
return getSubscriptionValue(partProps);
|
|
125
|
+
}),
|
|
126
|
+
quoted: computed(() => {
|
|
127
|
+
return partProps.key !== undefined && typeof partProps.key === "string";
|
|
128
|
+
})
|
|
129
|
+
};
|
|
130
|
+
} else {
|
|
131
|
+
// IdentifierDescriptor
|
|
132
|
+
part = {
|
|
133
|
+
type: computed(() => {
|
|
134
|
+
return "attribute";
|
|
135
|
+
}),
|
|
136
|
+
name: computed(() => {
|
|
137
|
+
if (first && partProps.refkey) {
|
|
138
|
+
return partProps.refkey;
|
|
139
|
+
} else if (partProps.id !== undefined) {
|
|
140
|
+
if (!isValidIdentifier(partProps.id)) {
|
|
141
|
+
throw new Error(`Invalid identifier: ${partProps.id}`);
|
|
142
|
+
}
|
|
143
|
+
return partProps.id;
|
|
144
|
+
} else if (symbolSource.value) {
|
|
145
|
+
return symbolSource.value.name;
|
|
146
|
+
} else {
|
|
147
|
+
return "<unresolved symbol>";
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return reactive(part);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Convert a refkey to a symbol ref using the current binder.
|
|
157
|
+
*/
|
|
158
|
+
function getSymbolForRefkey(refkey) {
|
|
159
|
+
const binder = useBinder();
|
|
160
|
+
return binder.getSymbolForRefkey(refkey);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Format a chain of parts into a MemberExpression.
|
|
165
|
+
*/
|
|
166
|
+
function formatChain(parts) {
|
|
167
|
+
return computed(() => {
|
|
168
|
+
const expression = [];
|
|
169
|
+
for (let i = 0; i < parts.length; i++) {
|
|
170
|
+
const part = parts[i];
|
|
171
|
+
if (i === 0) {
|
|
172
|
+
if (!isAttributeDescriptor(part)) {
|
|
173
|
+
throw new Error("The first part of a MemberExpression must be an id or refkey");
|
|
174
|
+
}
|
|
175
|
+
expression.push(part.name);
|
|
176
|
+
} else {
|
|
177
|
+
if (isCallDescriptor(part)) {
|
|
178
|
+
expression.push(formatCallOutput(part));
|
|
179
|
+
} else if (isAttributeDescriptor(part)) {
|
|
180
|
+
expression.push(formatAttributeOutput(part));
|
|
181
|
+
} else if (isSubscriptionDescriptor(part)) {
|
|
182
|
+
expression.push(formatSubscriptionOutput(part));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return expression;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Format a part of a member expression that is an array access.
|
|
192
|
+
* This is used for parts like `foo[0]` or `foo["bar"]`.
|
|
193
|
+
*/
|
|
194
|
+
function formatSubscriptionOutput(part) {
|
|
195
|
+
return _$createIntrinsic("group", {
|
|
196
|
+
get children() {
|
|
197
|
+
return ["", "[", _$createIntrinsic("indent", {
|
|
198
|
+
get children() {
|
|
199
|
+
return [_$createIntrinsic("sbr", {}), _$memo(() => part.quoted && '"'), _$memo(() => part.expression), _$memo(() => part.quoted && '"')];
|
|
200
|
+
}
|
|
201
|
+
}), _$createIntrinsic("sbr", {}), "]"];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function formatAttributeOutput(part) {
|
|
206
|
+
return _$createIntrinsic("group", {
|
|
207
|
+
get children() {
|
|
208
|
+
return _$createIntrinsic("indent", {
|
|
209
|
+
get children() {
|
|
210
|
+
return [_$createIntrinsic("ifBreak", {
|
|
211
|
+
children: " \\"
|
|
212
|
+
}), _$createIntrinsic("sbr", {}), ".", _$memo(() => part.name)];
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function formatCallOutput(part) {
|
|
219
|
+
const args = computed(() => {
|
|
220
|
+
return typeof part.args === "boolean" ? [] : part.args ?? [];
|
|
221
|
+
});
|
|
222
|
+
return _$createIntrinsic("group", {
|
|
223
|
+
get children() {
|
|
224
|
+
return ["", "(", _$createComponent(Show, {
|
|
225
|
+
get when() {
|
|
226
|
+
return args.value.length <= 1;
|
|
227
|
+
},
|
|
228
|
+
get children() {
|
|
229
|
+
return args.value[0];
|
|
230
|
+
}
|
|
231
|
+
}), _$createComponent(Show, {
|
|
232
|
+
get when() {
|
|
233
|
+
return args.value.length > 1;
|
|
234
|
+
},
|
|
235
|
+
get children() {
|
|
236
|
+
return [_$createIntrinsic("indent", {
|
|
237
|
+
get children() {
|
|
238
|
+
return [_$createIntrinsic("sbr", {}), _$createComponent(For, {
|
|
239
|
+
each: args,
|
|
240
|
+
comma: true,
|
|
241
|
+
line: true,
|
|
242
|
+
children: arg => arg
|
|
243
|
+
})];
|
|
244
|
+
}
|
|
245
|
+
}), _$createIntrinsic("sbr", {})];
|
|
246
|
+
}
|
|
247
|
+
}), ")"];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* A part of a member expression. Each part can provide one of the following
|
|
253
|
+
* props:
|
|
254
|
+
*
|
|
255
|
+
* * **id**: The identifier for the member expression part
|
|
256
|
+
* * **refkey**: A refkey for a symbol whose name becomes the identifier
|
|
257
|
+
* * **symbol**: a symbol whose name becomes the identifier part
|
|
258
|
+
* * **args**: create a method call with the given args
|
|
259
|
+
*/
|
|
260
|
+
MemberExpression.Part = function (props) {
|
|
261
|
+
/**
|
|
262
|
+
* This component does nothing except hold props which are retrieved by
|
|
263
|
+
* the `MemberExpression` component.
|
|
264
|
+
*/
|
|
265
|
+
};
|
|
266
|
+
function isValidIdentifier(id) {
|
|
267
|
+
if (typeof id === "string" && id.includes('"')) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
function isCallDescriptor(part) {
|
|
273
|
+
return "type" in part && part.type === MEMBER_ACCESS_TYPES.CALL;
|
|
274
|
+
}
|
|
275
|
+
function isAttributeDescriptor(part) {
|
|
276
|
+
return "type" in part && part.type === MEMBER_ACCESS_TYPES.ATTRIBUTE;
|
|
277
|
+
}
|
|
278
|
+
function isSubscriptionDescriptor(part) {
|
|
279
|
+
return "type" in part && part.type === MEMBER_ACCESS_TYPES.SUBSCRIPTION;
|
|
280
|
+
}
|
|
281
|
+
function getNameForRefkey(refkey) {
|
|
282
|
+
const parsedValue = getSymbolForRefkey(refkey).value;
|
|
283
|
+
return parsedValue !== undefined ? parsedValue.name : refkey;
|
|
284
|
+
}
|
|
285
|
+
function getSubscriptionValue(partProps) {
|
|
286
|
+
// Handle tuple keys: obj[a, b] → (a, b)
|
|
287
|
+
if (partProps.keys?.length) {
|
|
288
|
+
const parsedKeys = partProps.keys.map(key => getNameForRefkey(key));
|
|
289
|
+
return code`${parsedKeys.join(", ")}`;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Handle slice: obj[start:stop:step]
|
|
293
|
+
if (partProps.slice && Object.keys(partProps.slice).length > 0) {
|
|
294
|
+
const {
|
|
295
|
+
start,
|
|
296
|
+
stop,
|
|
297
|
+
step
|
|
298
|
+
} = partProps.slice;
|
|
299
|
+
const parts = [start ? getNameForRefkey(start) : "", ":", stop ? getNameForRefkey(stop) : ""];
|
|
300
|
+
if (step) {
|
|
301
|
+
parts.push(":", getNameForRefkey(step));
|
|
302
|
+
}
|
|
303
|
+
return code`${parts.join("")}`;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Handle single key: obj[key]
|
|
307
|
+
return getNameForRefkey(partProps.key);
|
|
308
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
export interface NoNamePolicyProps {
|
|
3
|
+
children: Children;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A wrapper component that disables name policy transformation for its children.
|
|
7
|
+
*
|
|
8
|
+
* This is useful for components that need to preserve exact names without applying
|
|
9
|
+
* naming conventions, such as Python dunder methods like `__init__`, `__str__`, etc.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <NoNamePolicy>
|
|
14
|
+
* <FunctionDeclaration name="__init__" instanceFunction>
|
|
15
|
+
* // Function content
|
|
16
|
+
* </FunctionDeclaration>
|
|
17
|
+
* </NoNamePolicy>
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* This ensures `__init__` stays as `__init__` without name policy transformation.
|
|
21
|
+
*/
|
|
22
|
+
export declare function NoNamePolicy(props: NoNamePolicyProps): Children;
|
|
23
|
+
//# sourceMappingURL=NoNamePolicy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NoNamePolicy.d.ts","sourceRoot":"","sources":["../../../src/components/NoNamePolicy.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,YAMpD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { NamePolicyContext } from "@alloy-js/core";
|
|
3
|
+
/**
|
|
4
|
+
* A wrapper component that disables name policy transformation for its children.
|
|
5
|
+
*
|
|
6
|
+
* This is useful for components that need to preserve exact names without applying
|
|
7
|
+
* naming conventions, such as Python dunder methods like `__init__`, `__str__`, etc.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <NoNamePolicy>
|
|
12
|
+
* <FunctionDeclaration name="__init__" instanceFunction>
|
|
13
|
+
* // Function content
|
|
14
|
+
* </FunctionDeclaration>
|
|
15
|
+
* </NoNamePolicy>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* This ensures `__init__` stays as `__init__` without name policy transformation.
|
|
19
|
+
*/
|
|
20
|
+
export function NoNamePolicy(props) {
|
|
21
|
+
return _$createComponent(NamePolicyContext.Provider, {
|
|
22
|
+
value: undefined,
|
|
23
|
+
get children() {
|
|
24
|
+
return props.children;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { ParameterDescriptor } from "../parameter-descriptor.js";
|
|
3
|
+
export interface GoogleStyleDocParamProps {
|
|
4
|
+
name: Children;
|
|
5
|
+
type?: Children;
|
|
6
|
+
children?: Children;
|
|
7
|
+
optional?: boolean;
|
|
8
|
+
defaultValue?: Children;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create a GoogleStyleDoc parameter.
|
|
12
|
+
*/
|
|
13
|
+
export declare function GoogleStyleDocParam(props: GoogleStyleDocParamProps): Children;
|
|
14
|
+
export interface GoogleStyleDocParamsProps {
|
|
15
|
+
parameters: ParameterDescriptor[] | string[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A component that creates a GoogleStyleDoc block for parameters.
|
|
19
|
+
*/
|
|
20
|
+
export declare function GoogleStyleDocParams(props: GoogleStyleDocParamsProps): Children;
|
|
21
|
+
export interface GoogleStyleDocReturnProps {
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A component that creates a GoogleStyleDoc block for parameters.
|
|
26
|
+
*/
|
|
27
|
+
export declare function GoogleStyleDocReturn(props: GoogleStyleDocReturnProps): Children;
|
|
28
|
+
export interface GoogleStyleDocRaisesProps {
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A component that creates a GoogleStyleDoc block for parameters.
|
|
33
|
+
*/
|
|
34
|
+
export declare function GoogleStyleDocRaises(props: GoogleStyleDocRaisesProps): Children;
|
|
35
|
+
export interface GoogleStyleFunctionDocProps extends Omit<FunctionDocProps, "style"> {
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A component that creates a GoogleStyleFunctionDoc block for parameters.
|
|
39
|
+
*/
|
|
40
|
+
export declare function GoogleStyleFunctionDoc(props: GoogleStyleFunctionDocProps): Children;
|
|
41
|
+
export interface FunctionDocProps {
|
|
42
|
+
description: Children[];
|
|
43
|
+
parameters?: ParameterDescriptor[] | string[];
|
|
44
|
+
returns?: string;
|
|
45
|
+
raises?: string[];
|
|
46
|
+
style?: "google";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A component that creates a FunctionDoc block for parameters.
|
|
50
|
+
*/
|
|
51
|
+
export declare function FunctionDoc(props: FunctionDocProps): Children;
|
|
52
|
+
export interface ClassDocProps {
|
|
53
|
+
description: Children[];
|
|
54
|
+
parameters?: ParameterDescriptor[] | string[];
|
|
55
|
+
style?: "google";
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A component that creates a ClassDoc block for parameters.
|
|
59
|
+
*/
|
|
60
|
+
export declare function ClassDoc(props: ClassDocProps): Children;
|
|
61
|
+
export interface GoogleStyleClassDocProps extends Omit<ClassDocProps, "style"> {
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A component that creates a GoogleStyleClassDoc block for parameters.
|
|
65
|
+
*/
|
|
66
|
+
export declare function GoogleStyleClassDoc(props: GoogleStyleClassDocProps): Children;
|
|
67
|
+
export interface PyDocExampleProps {
|
|
68
|
+
children: Children;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Create a PyDoc example, which is prepended by \>\>.
|
|
72
|
+
*/
|
|
73
|
+
export declare function PyDocExample(props: PyDocExampleProps): Children;
|
|
74
|
+
export interface PyDocProps {
|
|
75
|
+
children: Children;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A PyDoc comment. The children of this component are joined with two hard
|
|
79
|
+
* linebreaks. This is useful for creating PyDoc comments with multiple paragraphs.
|
|
80
|
+
*/
|
|
81
|
+
export declare function PyDoc(props: PyDocProps): Children;
|
|
82
|
+
export interface SimpleCommentBlockProps {
|
|
83
|
+
children: Children;
|
|
84
|
+
}
|
|
85
|
+
export declare function SimpleCommentBlock(props: SimpleCommentBlockProps): Children;
|
|
86
|
+
export interface SimpleInlineCommentProps {
|
|
87
|
+
children: Children;
|
|
88
|
+
}
|
|
89
|
+
export declare function SimpleInlineComment(props: SimpleInlineCommentProps): Children;
|
|
90
|
+
//# sourceMappingURL=PyDoc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PyDoc.d.ts","sourceRoot":"","sources":["../../../src/components/PyDoc.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,mBA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