@alloy-js/python 0.2.0-dev.3 → 0.2.0-dev.5
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/dist/src/builtins/python.d.ts +3 -0
- package/dist/src/builtins/python.d.ts.map +1 -1
- package/dist/src/builtins/python.js +6 -0
- package/dist/src/builtins/python.js.map +1 -1
- package/dist/src/components/Atom.d.ts +1 -0
- package/dist/src/components/Atom.d.ts.map +1 -1
- package/dist/src/components/Atom.js +3 -0
- package/dist/src/components/Atom.js.map +1 -1
- package/dist/src/components/CallSignature.d.ts +4 -15
- package/dist/src/components/CallSignature.d.ts.map +1 -1
- package/dist/src/components/CallSignature.js +13 -67
- package/dist/src/components/CallSignature.js.map +1 -1
- package/dist/src/components/ClassMethodDeclaration.d.ts +22 -0
- package/dist/src/components/ClassMethodDeclaration.d.ts.map +1 -0
- package/dist/src/components/ClassMethodDeclaration.js +32 -0
- package/dist/src/components/ClassMethodDeclaration.js.map +1 -0
- package/dist/src/components/ConstructorDeclaration.d.ts +21 -0
- package/dist/src/components/ConstructorDeclaration.d.ts.map +1 -0
- package/dist/src/components/ConstructorDeclaration.js +35 -0
- package/dist/src/components/ConstructorDeclaration.js.map +1 -0
- package/dist/src/components/DunderMethodDeclaration.d.ts +21 -0
- package/dist/src/components/DunderMethodDeclaration.d.ts.map +1 -0
- package/dist/src/components/DunderMethodDeclaration.js +29 -0
- package/dist/src/components/DunderMethodDeclaration.js.map +1 -0
- package/dist/src/components/EnumDeclaration.d.ts +11 -32
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +10 -48
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.js +3 -3
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/FunctionBase.d.ts +48 -0
- package/dist/src/components/FunctionBase.d.ts.map +1 -0
- package/dist/src/components/FunctionBase.js +91 -0
- package/dist/src/components/FunctionBase.js.map +1 -0
- package/dist/src/components/FunctionDeclaration.d.ts +11 -31
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +22 -79
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/MethodBase.d.ts +29 -0
- package/dist/src/components/MethodBase.d.ts.map +1 -0
- package/dist/src/components/MethodBase.js +32 -0
- package/dist/src/components/MethodBase.js.map +1 -0
- package/dist/src/components/MethodDeclaration.d.ts +22 -0
- package/dist/src/components/MethodDeclaration.d.ts.map +1 -0
- package/dist/src/components/MethodDeclaration.js +34 -0
- package/dist/src/components/MethodDeclaration.js.map +1 -0
- package/dist/src/components/PropertyDeclaration.d.ts +71 -0
- package/dist/src/components/PropertyDeclaration.d.ts.map +1 -0
- package/dist/src/components/PropertyDeclaration.js +227 -0
- package/dist/src/components/PropertyDeclaration.js.map +1 -0
- package/dist/src/components/PyDoc.d.ts +107 -42
- package/dist/src/components/PyDoc.d.ts.map +1 -1
- package/dist/src/components/PyDoc.js +845 -181
- package/dist/src/components/PyDoc.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts +24 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +28 -1
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/StaticMethodDeclaration.d.ts +22 -0
- package/dist/src/components/StaticMethodDeclaration.d.ts.map +1 -0
- package/dist/src/components/StaticMethodDeclaration.js +32 -0
- package/dist/src/components/StaticMethodDeclaration.js.map +1 -0
- package/dist/src/components/TypeArguments.d.ts +9 -0
- package/dist/src/components/TypeArguments.d.ts.map +1 -0
- package/dist/src/components/TypeArguments.js +18 -0
- package/dist/src/components/TypeArguments.js.map +1 -0
- package/dist/src/components/TypeReference.d.ts +14 -0
- package/dist/src/components/TypeReference.d.ts.map +1 -0
- package/dist/src/components/TypeReference.js +29 -0
- package/dist/src/components/TypeReference.js.map +1 -0
- package/dist/src/components/UnionTypeExpression.d.ts +1 -2
- package/dist/src/components/UnionTypeExpression.d.ts.map +1 -1
- package/dist/src/components/UnionTypeExpression.js +3 -11
- package/dist/src/components/UnionTypeExpression.js.map +1 -1
- package/dist/src/components/VariableDeclaration.d.ts.map +1 -1
- package/dist/src/components/VariableDeclaration.js +3 -3
- package/dist/src/components/VariableDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +10 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +9 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/parameter-descriptor.d.ts +1 -4
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/parameter-descriptor.js +7 -1
- package/dist/src/parameter-descriptor.js.map +1 -1
- package/dist/src/symbol-creation.d.ts +4 -0
- package/dist/src/symbol-creation.d.ts.map +1 -1
- package/dist/src/symbol-creation.js +12 -0
- package/dist/src/symbol-creation.js.map +1 -1
- package/dist/src/symbols/factories.d.ts +15 -0
- package/dist/src/symbols/factories.d.ts.map +1 -0
- package/dist/src/symbols/factories.js +28 -0
- package/dist/src/symbols/factories.js.map +1 -0
- package/dist/src/symbols/index.d.ts +1 -0
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +1 -0
- package/dist/src/symbols/index.js.map +1 -1
- package/dist/src/symbols/reference.d.ts +1 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +1 -1
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/test/callsignatures.test.js +42 -64
- package/dist/test/callsignatures.test.js.map +1 -1
- package/dist/test/class-method-declaration.test.d.ts +2 -0
- package/dist/test/class-method-declaration.test.d.ts.map +1 -0
- package/dist/test/class-method-declaration.test.js +61 -0
- package/dist/test/class-method-declaration.test.js.map +1 -0
- package/dist/test/classdeclarations.test.js +6 -8
- package/dist/test/classdeclarations.test.js.map +1 -1
- package/dist/test/constructordeclaration.test.d.ts +2 -0
- package/dist/test/constructordeclaration.test.d.ts.map +1 -0
- package/dist/test/constructordeclaration.test.js +58 -0
- package/dist/test/constructordeclaration.test.js.map +1 -0
- package/dist/test/dundermethoddeclaration.test.d.ts +2 -0
- package/dist/test/dundermethoddeclaration.test.d.ts.map +1 -0
- package/dist/test/dundermethoddeclaration.test.js +65 -0
- package/dist/test/dundermethoddeclaration.test.js.map +1 -0
- package/dist/test/enums.test.js +14 -16
- package/dist/test/enums.test.js.map +1 -1
- package/dist/test/externals.test.js +2 -4
- package/dist/test/externals.test.js.map +1 -1
- package/dist/test/factories.test.d.ts +2 -0
- package/dist/test/factories.test.d.ts.map +1 -0
- package/dist/test/factories.test.js +78 -0
- package/dist/test/factories.test.js.map +1 -0
- package/dist/test/functiondeclaration.test.js +213 -59
- package/dist/test/functiondeclaration.test.js.map +1 -1
- package/dist/test/memberexpressions.test.js +1 -1
- package/dist/test/memberexpressions.test.js.map +1 -1
- package/dist/test/methoddeclaration.test.d.ts +2 -0
- package/dist/test/methoddeclaration.test.d.ts.map +1 -0
- package/dist/test/methoddeclaration.test.js +239 -0
- package/dist/test/methoddeclaration.test.js.map +1 -0
- package/dist/test/namepolicies.test.js +1 -2
- package/dist/test/namepolicies.test.js.map +1 -1
- package/dist/test/propertydeclaration.test.d.ts +2 -0
- package/dist/test/propertydeclaration.test.d.ts.map +1 -0
- package/dist/test/propertydeclaration.test.js +229 -0
- package/dist/test/propertydeclaration.test.js.map +1 -0
- package/dist/test/pydocs.test.js +926 -126
- package/dist/test/pydocs.test.js.map +1 -1
- package/dist/test/references.test.js +1 -5
- package/dist/test/references.test.js.map +1 -1
- package/dist/test/sourcefiles.test.js +90 -1
- package/dist/test/sourcefiles.test.js.map +1 -1
- package/dist/test/staticmethoddeclaration.test.d.ts +2 -0
- package/dist/test/staticmethoddeclaration.test.d.ts.map +1 -0
- package/dist/test/staticmethoddeclaration.test.js +61 -0
- package/dist/test/staticmethoddeclaration.test.js.map +1 -0
- package/dist/test/typereference.test.d.ts +2 -0
- package/dist/test/typereference.test.d.ts.map +1 -0
- package/dist/test/typereference.test.js +51 -0
- package/dist/test/typereference.test.js.map +1 -0
- package/dist/test/uniontypeexpression.test.js +152 -15
- package/dist/test/uniontypeexpression.test.js.map +1 -1
- package/dist/test/values.test.js +35 -0
- package/dist/test/values.test.js.map +1 -1
- package/dist/test/variables.test.js +28 -19
- package/dist/test/variables.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/builtins/python.ts +7 -0
- package/src/components/Atom.tsx +4 -0
- package/src/components/CallSignature.tsx +17 -69
- package/src/components/ClassMethodDeclaration.tsx +34 -0
- package/src/components/ConstructorDeclaration.tsx +37 -0
- package/src/components/DunderMethodDeclaration.tsx +30 -0
- package/src/components/EnumDeclaration.tsx +16 -44
- package/src/components/EnumMember.tsx +3 -3
- package/src/components/FunctionBase.tsx +88 -0
- package/src/components/FunctionDeclaration.tsx +18 -82
- package/src/components/MethodBase.tsx +53 -0
- package/src/components/MethodDeclaration.tsx +27 -0
- package/src/components/PropertyDeclaration.tsx +264 -0
- package/src/components/PyDoc.tsx +795 -195
- package/src/components/SourceFile.tsx +29 -0
- package/src/components/StaticMethodDeclaration.tsx +34 -0
- package/src/components/TypeArguments.tsx +24 -0
- package/src/components/TypeReference.tsx +33 -0
- package/src/components/UnionTypeExpression.tsx +4 -15
- package/src/components/VariableDeclaration.tsx +1 -3
- package/src/components/index.ts +10 -0
- package/src/parameter-descriptor.ts +6 -5
- package/src/symbol-creation.ts +17 -0
- package/src/symbols/factories.ts +39 -0
- package/src/symbols/index.ts +1 -0
- package/src/symbols/reference.tsx +3 -5
- package/src/utils.ts +0 -2
- package/temp/api.json +5323 -2288
- package/test/callsignatures.test.tsx +102 -74
- package/test/class-method-declaration.test.tsx +53 -0
- package/test/classdeclarations.test.tsx +7 -9
- package/test/constructordeclaration.test.tsx +48 -0
- package/test/dundermethoddeclaration.test.tsx +53 -0
- package/test/enums.test.tsx +14 -16
- package/test/externals.test.tsx +5 -7
- package/test/factories.test.tsx +72 -0
- package/test/functiondeclaration.test.tsx +196 -44
- package/test/memberexpressions.test.tsx +7 -2
- package/test/methoddeclaration.test.tsx +202 -0
- package/test/namepolicies.test.tsx +1 -2
- package/test/propertydeclaration.test.tsx +192 -0
- package/test/pydocs.test.tsx +1093 -129
- package/test/references.test.tsx +1 -1
- package/test/sourcefiles.test.tsx +100 -1
- package/test/staticmethoddeclaration.test.tsx +49 -0
- package/test/typereference.test.tsx +52 -0
- package/test/uniontypeexpression.test.tsx +169 -34
- package/test/values.test.tsx +34 -0
- package/test/variables.test.tsx +27 -16
|
@@ -44,6 +44,10 @@ export interface SourceFileProps {
|
|
|
44
44
|
* Comment to add to the header, which will be rendered as a comment in the file.
|
|
45
45
|
*/
|
|
46
46
|
headerComment?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Documentation for this module, which will be rendered as a module-level docstring.
|
|
49
|
+
*/
|
|
50
|
+
doc?: Children;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
/**
|
|
@@ -62,6 +66,26 @@ export interface SourceFileProps {
|
|
|
62
66
|
* def test():
|
|
63
67
|
* pass
|
|
64
68
|
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* With module documentation:
|
|
72
|
+
* ```tsx
|
|
73
|
+
* <SourceFile
|
|
74
|
+
* path="utils.py"
|
|
75
|
+
* doc={<ModuleDoc description={[<Prose>Utility functions for data processing.</Prose>]} />}
|
|
76
|
+
* >
|
|
77
|
+
* <FunctionDeclaration name="process_data" />
|
|
78
|
+
* </SourceFile>
|
|
79
|
+
* ```
|
|
80
|
+
* renders to
|
|
81
|
+
* ```py
|
|
82
|
+
* """
|
|
83
|
+
* Utility functions for data processing.
|
|
84
|
+
* """
|
|
85
|
+
*
|
|
86
|
+
* def process_data():
|
|
87
|
+
* pass
|
|
88
|
+
* ```
|
|
65
89
|
*/
|
|
66
90
|
export function SourceFile(props: SourceFileProps) {
|
|
67
91
|
const directoryContext = useContext(SourceDirectoryContext)!;
|
|
@@ -83,6 +107,11 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
83
107
|
<hbr />
|
|
84
108
|
<hbr />
|
|
85
109
|
</Show>
|
|
110
|
+
<Show when={props.doc !== undefined}>
|
|
111
|
+
{props.doc}
|
|
112
|
+
<hbr />
|
|
113
|
+
<hbr />
|
|
114
|
+
</Show>
|
|
86
115
|
<PythonSourceFileContext.Provider value={sfContext}>
|
|
87
116
|
<Scope value={scope}>
|
|
88
117
|
<List doubleHardline>{props.children}</List>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createMethodSymbol } from "../symbols/factories.js";
|
|
2
|
+
import type { CommonFunctionProps } from "./FunctionBase.js";
|
|
3
|
+
import { MethodDeclarationBase } from "./MethodBase.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A Python static method declaration component.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <py.StaticMethodDeclaration name="identity" parameters={[{ name: "value", type: "int" }]}>
|
|
11
|
+
* return value
|
|
12
|
+
* </py.StaticMethodDeclaration>
|
|
13
|
+
* ```
|
|
14
|
+
* Generates:
|
|
15
|
+
* ```python
|
|
16
|
+
* @staticmethod
|
|
17
|
+
* def identity(value: int) -> None:
|
|
18
|
+
* return value
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export interface StaticMethodDeclarationProps extends CommonFunctionProps {
|
|
22
|
+
abstract?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function StaticMethodDeclaration(props: StaticMethodDeclarationProps) {
|
|
26
|
+
const sym = createMethodSymbol(props.name, { refkeys: props.refkey });
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
{"@staticmethod"}
|
|
30
|
+
<hbr />
|
|
31
|
+
<MethodDeclarationBase functionType="static" {...props} sym={sym} />
|
|
32
|
+
</>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Children, For } from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
export interface TypeArgumentsProps {
|
|
4
|
+
args: Children[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Render Python-style type arguments, e.g. [T, P].
|
|
9
|
+
*/
|
|
10
|
+
export function TypeArguments(props: TypeArgumentsProps) {
|
|
11
|
+
if (!props.args || props.args.length === 0) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<>
|
|
17
|
+
[
|
|
18
|
+
<For each={props.args} joiner=", ">
|
|
19
|
+
{(arg) => arg}
|
|
20
|
+
</For>
|
|
21
|
+
]
|
|
22
|
+
</>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Children, Refkey, Show } from "@alloy-js/core";
|
|
2
|
+
import { TypeArguments } from "./TypeArguments.js";
|
|
3
|
+
|
|
4
|
+
export interface TypeReferenceProps {
|
|
5
|
+
/** A refkey to a declared symbol. */
|
|
6
|
+
refkey?: Refkey;
|
|
7
|
+
/** A raw name to reference when no refkey is provided. */
|
|
8
|
+
name?: Children;
|
|
9
|
+
/** Type arguments to render inside brackets. */
|
|
10
|
+
typeArgs?: Children[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A type reference like Foo[T, P] or int.
|
|
15
|
+
*/
|
|
16
|
+
export function TypeReference(props: TypeReferenceProps) {
|
|
17
|
+
const type = props.refkey ? props.refkey : props.name;
|
|
18
|
+
const typeArgs =
|
|
19
|
+
props.typeArgs && props.typeArgs.length ?
|
|
20
|
+
<TypeArguments args={props.typeArgs} />
|
|
21
|
+
: undefined;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<group>
|
|
25
|
+
<indent>
|
|
26
|
+
<sbr />
|
|
27
|
+
{type}
|
|
28
|
+
<Show when={Boolean(typeArgs)}>{typeArgs}</Show>
|
|
29
|
+
</indent>
|
|
30
|
+
<sbr />
|
|
31
|
+
</group>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
import { Children,
|
|
1
|
+
import { Children, For, childrenArray } from "@alloy-js/core";
|
|
2
2
|
|
|
3
3
|
export interface UnionTypeExpressionProps {
|
|
4
|
-
children: Children
|
|
5
|
-
optional?: boolean;
|
|
4
|
+
children: Children;
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
export function UnionTypeExpression(props: UnionTypeExpressionProps) {
|
|
9
|
-
const
|
|
10
|
-
const children = childrenArray(() => props.children, {
|
|
11
|
-
preserveFragments: true,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
if (props.optional) {
|
|
15
|
-
children.push("None");
|
|
16
|
-
}
|
|
17
|
-
return children;
|
|
18
|
-
});
|
|
19
|
-
|
|
8
|
+
const items = childrenArray(() => props.children);
|
|
20
9
|
return (
|
|
21
10
|
<group>
|
|
22
11
|
<ifBreak>(</ifBreak>
|
|
23
12
|
<indent>
|
|
24
13
|
<sbr />
|
|
25
14
|
<For
|
|
26
|
-
each={
|
|
15
|
+
each={items}
|
|
27
16
|
joiner={
|
|
28
17
|
<>
|
|
29
18
|
<br />|{" "}
|
|
@@ -4,13 +4,12 @@ import {
|
|
|
4
4
|
Name,
|
|
5
5
|
Show,
|
|
6
6
|
createSymbolSlot,
|
|
7
|
-
emitSymbol,
|
|
8
7
|
memo,
|
|
9
8
|
} from "@alloy-js/core";
|
|
10
9
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
11
10
|
import { Atom } from "./Atom.jsx";
|
|
12
11
|
import { BaseDeclarationProps } from "./Declaration.jsx";
|
|
13
|
-
import { SimpleCommentBlock } from "./
|
|
12
|
+
import { SimpleCommentBlock } from "./PyDoc.jsx";
|
|
14
13
|
|
|
15
14
|
export interface VariableDeclarationProps extends BaseDeclarationProps {
|
|
16
15
|
/**
|
|
@@ -89,7 +88,6 @@ export function VariableDeclaration(props: VariableDeclarationProps) {
|
|
|
89
88
|
ValueTypeSymbolSlot.moveMembersTo(sym);
|
|
90
89
|
}
|
|
91
90
|
|
|
92
|
-
emitSymbol(sym);
|
|
93
91
|
// Handle optional type annotation
|
|
94
92
|
const type = memo(() => {
|
|
95
93
|
if (!props.type || props.callStatementVar) return undefined;
|
package/src/components/index.ts
CHANGED
|
@@ -2,19 +2,29 @@ export * from "./Atom.js";
|
|
|
2
2
|
export * from "./CallSignature.js";
|
|
3
3
|
export * from "./ClassDeclaration.js";
|
|
4
4
|
export * from "./ClassInstantiation.js";
|
|
5
|
+
export * from "./ClassMethodDeclaration.js";
|
|
6
|
+
export * from "./ConstructorDeclaration.js";
|
|
5
7
|
export * from "./Declaration.js";
|
|
8
|
+
export * from "./DunderMethodDeclaration.js";
|
|
6
9
|
export * from "./EnumDeclaration.js";
|
|
7
10
|
export * from "./EnumMember.js";
|
|
11
|
+
export type { CommonFunctionProps } from "./FunctionBase.js";
|
|
8
12
|
export * from "./FunctionCallExpression.js";
|
|
9
13
|
export * from "./FunctionDeclaration.js";
|
|
10
14
|
export * from "./ImportStatement.js";
|
|
11
15
|
export * from "./LexicalScope.js";
|
|
12
16
|
export * from "./MemberExpression.js";
|
|
13
17
|
export * from "./MemberScope.jsx";
|
|
18
|
+
export type { MethodDeclarationBaseProps } from "./MethodBase.js";
|
|
19
|
+
export * from "./MethodDeclaration.js";
|
|
20
|
+
export * from "./PropertyDeclaration.js";
|
|
14
21
|
export * from "./PyDoc.js";
|
|
15
22
|
export * from "./PythonBlock.js";
|
|
16
23
|
export * from "./Reference.js";
|
|
17
24
|
export * from "./SourceFile.js";
|
|
18
25
|
export * from "./StatementList.js";
|
|
26
|
+
export * from "./StaticMethodDeclaration.js";
|
|
27
|
+
export * from "./TypeArguments.js";
|
|
28
|
+
export * from "./TypeReference.js";
|
|
19
29
|
export * from "./UnionTypeExpression.js";
|
|
20
30
|
export * from "./VariableDeclaration.js";
|
|
@@ -19,11 +19,6 @@ export interface ParameterDescriptor {
|
|
|
19
19
|
*/
|
|
20
20
|
readonly refkey?: Refkey | Refkey[];
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* Whether the parameter is optional.
|
|
24
|
-
*/
|
|
25
|
-
readonly optional?: boolean;
|
|
26
|
-
|
|
27
22
|
/**
|
|
28
23
|
* Documentation for the parameter.
|
|
29
24
|
*/
|
|
@@ -34,3 +29,9 @@ export interface ParameterDescriptor {
|
|
|
34
29
|
*/
|
|
35
30
|
readonly default?: Children;
|
|
36
31
|
}
|
|
32
|
+
|
|
33
|
+
export function isParameterDescriptor(
|
|
34
|
+
param: unknown,
|
|
35
|
+
): param is ParameterDescriptor {
|
|
36
|
+
return typeof param === "object" && param !== null && "name" in param;
|
|
37
|
+
}
|
package/src/symbol-creation.ts
CHANGED
|
@@ -18,6 +18,22 @@ interface CreatePythonSymbolOptions extends PythonOutputSymbolOptions {
|
|
|
18
18
|
space?: OutputSpace;
|
|
19
19
|
instance?: boolean;
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Attempts to find an existing symbol by name in the target space.
|
|
24
|
+
*/
|
|
25
|
+
export function findExistingSymbol(
|
|
26
|
+
name: string,
|
|
27
|
+
targetSpace?: OutputSpace,
|
|
28
|
+
): PythonOutputSymbol | undefined {
|
|
29
|
+
if (!targetSpace) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const existingSymbol = targetSpace.symbolNames.get(name);
|
|
34
|
+
return existingSymbol as PythonOutputSymbol | undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
21
37
|
/**
|
|
22
38
|
* Creates a symbol for a python declaration in the current scope.
|
|
23
39
|
*/
|
|
@@ -55,6 +71,7 @@ export function createPythonSymbol(
|
|
|
55
71
|
metadata: options.metadata,
|
|
56
72
|
module: sfContext?.module,
|
|
57
73
|
type: options.type,
|
|
74
|
+
ignoreNameConflict: options.ignoreNameConflict,
|
|
58
75
|
namePolicy: usePythonNamePolicy().for(kind),
|
|
59
76
|
});
|
|
60
77
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Namekey } from "@alloy-js/core";
|
|
2
|
+
import { createPythonSymbol } from "../symbol-creation.js";
|
|
3
|
+
import type { PythonOutputSymbol } from "./python-output-symbol.js";
|
|
4
|
+
import { usePythonScope } from "./scopes.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a function symbol in the current scope.
|
|
8
|
+
*/
|
|
9
|
+
export function createFunctionSymbol(
|
|
10
|
+
name: string | Namekey,
|
|
11
|
+
options: { refkeys?: any } = {},
|
|
12
|
+
): PythonOutputSymbol {
|
|
13
|
+
return createPythonSymbol(
|
|
14
|
+
name,
|
|
15
|
+
{ instance: false, refkeys: options.refkeys },
|
|
16
|
+
"function",
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates a method symbol in a class. Validates that the current scope is a member scope.
|
|
22
|
+
*/
|
|
23
|
+
export function createMethodSymbol(
|
|
24
|
+
name: string | Namekey,
|
|
25
|
+
options: { refkeys?: any } = {},
|
|
26
|
+
): PythonOutputSymbol {
|
|
27
|
+
const scope = usePythonScope();
|
|
28
|
+
if (!scope?.isMemberScope) {
|
|
29
|
+
const displayName = typeof name === "string" ? name : name.name;
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Method "${displayName}" must be declared inside a class (member scope)`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return createPythonSymbol(
|
|
35
|
+
name,
|
|
36
|
+
{ instance: true, refkeys: options.refkeys },
|
|
37
|
+
"function",
|
|
38
|
+
);
|
|
39
|
+
}
|
package/src/symbols/index.ts
CHANGED
|
@@ -9,11 +9,9 @@ import {
|
|
|
9
9
|
} from "@alloy-js/core";
|
|
10
10
|
import { MemberExpression } from "../components/MemberExpression.jsx";
|
|
11
11
|
import { PythonSourceFileContext } from "../components/SourceFile.jsx";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
PythonOutputSymbol,
|
|
16
|
-
} from "./index.js";
|
|
12
|
+
import { PythonModuleScope } from "./python-module-scope.js";
|
|
13
|
+
import { PythonOutputSymbol } from "./python-output-symbol.js";
|
|
14
|
+
import { PythonOutputScope } from "./scopes.js";
|
|
17
15
|
|
|
18
16
|
export function ref(
|
|
19
17
|
refkey: Refkey,
|