@alloy-js/python 0.2.0-dev.0 → 0.2.0-dev.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/dist/src/components/Declaration.d.ts +4 -6
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +1 -3
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/EnumDeclaration.d.ts +2 -6
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.d.ts +2 -2
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +11 -11
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +0 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +0 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/parameter-descriptor.d.ts +2 -2
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/symbol-creation.d.ts +2 -2
- package/dist/src/symbol-creation.d.ts.map +1 -1
- package/dist/src/symbol-creation.js +3 -10
- package/dist/src/symbol-creation.js.map +1 -1
- package/dist/src/symbols/python-output-symbol.d.ts +2 -2
- package/dist/src/symbols/python-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/python-output-symbol.js.map +1 -1
- package/dist/test/classdeclarations.test.js +14 -1
- package/dist/test/classdeclarations.test.js.map +1 -1
- package/dist/test/functiondeclaration.test.js +14 -1
- package/dist/test/functiondeclaration.test.js.map +1 -1
- package/dist/test/variables.test.js +11 -1
- package/dist/test/variables.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/Declaration.tsx +4 -5
- package/src/components/EnumDeclaration.tsx +3 -14
- package/src/components/EnumMember.tsx +2 -2
- package/src/components/FunctionDeclaration.tsx +8 -10
- package/src/components/index.ts +0 -1
- package/src/parameter-descriptor.ts +2 -2
- package/src/symbol-creation.ts +4 -10
- package/src/symbols/python-output-symbol.ts +7 -2
- package/temp/api.json +44 -112
- package/test/classdeclarations.test.tsx +13 -1
- package/test/functiondeclaration.test.tsx +13 -1
- package/test/variables.test.tsx +12 -1
- package/dist/src/components/NoNamePolicy.d.ts +0 -23
- package/dist/src/components/NoNamePolicy.d.ts.map +0 -1
- package/dist/src/components/NoNamePolicy.js +0 -28
- package/dist/src/components/NoNamePolicy.js.map +0 -1
- package/src/components/NoNamePolicy.tsx +0 -31
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import { enumModule } from "../builtins/python.js";
|
|
8
8
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
9
9
|
import { BaseDeclarationProps } from "./Declaration.js";
|
|
10
|
-
import { EnumMember } from "./EnumMember.js";
|
|
10
|
+
import { EnumMember, EnumMemberProps } from "./EnumMember.js";
|
|
11
11
|
import { SimpleCommentBlock } from "./index.js";
|
|
12
12
|
import { MemberScope } from "./MemberScope.jsx";
|
|
13
13
|
import { PythonBlock } from "./PythonBlock.jsx";
|
|
@@ -21,12 +21,7 @@ export interface EnumProps extends BaseDeclarationProps {
|
|
|
21
21
|
/**
|
|
22
22
|
* Members of the enum as an array of objects.
|
|
23
23
|
*/
|
|
24
|
-
members?: Array<
|
|
25
|
-
name: string;
|
|
26
|
-
value?: Children;
|
|
27
|
-
jsValue?: string | number;
|
|
28
|
-
doc?: string;
|
|
29
|
-
}>;
|
|
24
|
+
members?: Array<EnumMemberProps>;
|
|
30
25
|
/**
|
|
31
26
|
* The enum style: 'classic' (default), 'auto', or 'functional'.
|
|
32
27
|
*/
|
|
@@ -226,13 +221,7 @@ export function ClassEnumDeclaration(props: EnumProps) {
|
|
|
226
221
|
},
|
|
227
222
|
"enum",
|
|
228
223
|
);
|
|
229
|
-
let memberList: Array<
|
|
230
|
-
name: string;
|
|
231
|
-
value?: Children;
|
|
232
|
-
jsValue?: string | number;
|
|
233
|
-
auto?: boolean;
|
|
234
|
-
doc?: string;
|
|
235
|
-
}> = (props.members ?? []).map((m) =>
|
|
224
|
+
let memberList: Array<EnumMemberProps> = (props.members ?? []).map((m) =>
|
|
236
225
|
m.value === undefined ? { ...m, auto: false } : m,
|
|
237
226
|
);
|
|
238
227
|
if (props.style === "auto") {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Children, Refkey, Show } from "@alloy-js/core";
|
|
1
|
+
import { Children, Namekey, Refkey, Show } from "@alloy-js/core";
|
|
2
2
|
import { enumModule } from "../builtins/python.js";
|
|
3
3
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
4
4
|
import { PythonOutputSymbol } from "../symbols/index.js";
|
|
@@ -9,7 +9,7 @@ export interface EnumMemberProps {
|
|
|
9
9
|
/**
|
|
10
10
|
* The name of the enum member.
|
|
11
11
|
*/
|
|
12
|
-
name: string;
|
|
12
|
+
name: string | Namekey;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Refkey for the enum member symbol. If the refkey is not provided, a symbol
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { emitSymbol, Name, Show } from "@alloy-js/core";
|
|
1
|
+
import { emitSymbol, Name, namekey, Show } from "@alloy-js/core";
|
|
2
2
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
3
3
|
import { getCallSignatureProps } from "../utils.js";
|
|
4
4
|
import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
|
|
5
5
|
import { BaseDeclarationProps, Declaration } from "./Declaration.js";
|
|
6
6
|
import { PythonBlock } from "./PythonBlock.jsx";
|
|
7
|
-
import { LexicalScope
|
|
7
|
+
import { LexicalScope } from "./index.js";
|
|
8
8
|
|
|
9
9
|
export interface FunctionDeclarationProps
|
|
10
10
|
extends BaseDeclarationProps,
|
|
@@ -91,13 +91,11 @@ export interface InitFunctionDeclarationProps
|
|
|
91
91
|
*/
|
|
92
92
|
export function InitFunctionDeclaration(props: InitFunctionDeclarationProps) {
|
|
93
93
|
return (
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
/>
|
|
101
|
-
</NoNamePolicy>
|
|
94
|
+
<FunctionDeclaration
|
|
95
|
+
{...props}
|
|
96
|
+
name={namekey("__init__", { ignoreNamePolicy: true })}
|
|
97
|
+
instanceFunction={true}
|
|
98
|
+
classFunction={false}
|
|
99
|
+
/>
|
|
102
100
|
);
|
|
103
101
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -11,7 +11,6 @@ export * from "./ImportStatement.js";
|
|
|
11
11
|
export * from "./LexicalScope.js";
|
|
12
12
|
export * from "./MemberExpression.js";
|
|
13
13
|
export * from "./MemberScope.jsx";
|
|
14
|
-
export * from "./NoNamePolicy.js";
|
|
15
14
|
export * from "./PyDoc.js";
|
|
16
15
|
export * from "./PythonBlock.js";
|
|
17
16
|
export * from "./Reference.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Children, Refkey } from "@alloy-js/core";
|
|
1
|
+
import type { Children, Namekey, Refkey } from "@alloy-js/core";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Information for a Python function parameter.
|
|
@@ -7,7 +7,7 @@ export interface ParameterDescriptor {
|
|
|
7
7
|
/**
|
|
8
8
|
* The name of the parameter.
|
|
9
9
|
*/
|
|
10
|
-
readonly name: string;
|
|
10
|
+
readonly name: string | Namekey;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The type of the parameter.
|
package/src/symbol-creation.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Namekey,
|
|
2
3
|
OutputScopeOptions,
|
|
3
4
|
OutputSpace,
|
|
4
5
|
useBinder,
|
|
@@ -21,19 +22,11 @@ interface CreatePythonSymbolOptions extends PythonOutputSymbolOptions {
|
|
|
21
22
|
* Creates a symbol for a python declaration in the current scope.
|
|
22
23
|
*/
|
|
23
24
|
export function createPythonSymbol(
|
|
24
|
-
name: string,
|
|
25
|
+
name: string | Namekey,
|
|
25
26
|
options: CreatePythonSymbolOptions = {},
|
|
26
27
|
kind?: PythonElements,
|
|
27
28
|
): PythonOutputSymbol {
|
|
28
|
-
let processedName = name;
|
|
29
29
|
const sfContext = useContext(PythonSourceFileContext);
|
|
30
|
-
// Only apply the name policy if a kind is provided and name policy context is available
|
|
31
|
-
if (kind) {
|
|
32
|
-
const namePolicy = usePythonNamePolicy();
|
|
33
|
-
if (namePolicy) {
|
|
34
|
-
processedName = namePolicy.getName(name, kind);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
30
|
const currentScope = usePythonScope();
|
|
38
31
|
let targetSpace = options.space ?? undefined;
|
|
39
32
|
if (!options.space && currentScope) {
|
|
@@ -55,13 +48,14 @@ export function createPythonSymbol(
|
|
|
55
48
|
|
|
56
49
|
const binder = options.binder ?? currentScope?.binder ?? useBinder();
|
|
57
50
|
|
|
58
|
-
return new PythonOutputSymbol(
|
|
51
|
+
return new PythonOutputSymbol(name, targetSpace, {
|
|
59
52
|
binder: binder,
|
|
60
53
|
aliasTarget: options.aliasTarget,
|
|
61
54
|
refkeys: options.refkeys,
|
|
62
55
|
metadata: options.metadata,
|
|
63
56
|
module: sfContext?.module,
|
|
64
57
|
type: options.type,
|
|
58
|
+
namePolicy: usePythonNamePolicy().for(kind),
|
|
65
59
|
});
|
|
66
60
|
}
|
|
67
61
|
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Namekey,
|
|
3
|
+
OutputSpace,
|
|
4
|
+
OutputSymbol,
|
|
5
|
+
OutputSymbolOptions,
|
|
6
|
+
} from "@alloy-js/core";
|
|
2
7
|
|
|
3
8
|
export interface PythonOutputSymbolOptions extends OutputSymbolOptions {
|
|
4
9
|
module?: string;
|
|
@@ -16,7 +21,7 @@ export class PythonOutputSymbol extends OutputSymbol {
|
|
|
16
21
|
static readonly memberSpaces = ["static", "instance"] as const;
|
|
17
22
|
|
|
18
23
|
constructor(
|
|
19
|
-
name: string,
|
|
24
|
+
name: string | Namekey,
|
|
20
25
|
spaces: OutputSpace[] | OutputSpace | undefined,
|
|
21
26
|
options: PythonOutputSymbolOptions,
|
|
22
27
|
) {
|
package/temp/api.json
CHANGED
|
@@ -345,7 +345,12 @@
|
|
|
345
345
|
},
|
|
346
346
|
{
|
|
347
347
|
"kind": "Content",
|
|
348
|
-
"text": "string"
|
|
348
|
+
"text": "string | "
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
"kind": "Reference",
|
|
352
|
+
"text": "Namekey",
|
|
353
|
+
"canonicalReference": "@alloy-js/core!Namekey:interface"
|
|
349
354
|
},
|
|
350
355
|
{
|
|
351
356
|
"kind": "Content",
|
|
@@ -358,7 +363,7 @@
|
|
|
358
363
|
"name": "name",
|
|
359
364
|
"propertyTypeTokenRange": {
|
|
360
365
|
"startIndex": 1,
|
|
361
|
-
"endIndex":
|
|
366
|
+
"endIndex": 3
|
|
362
367
|
}
|
|
363
368
|
},
|
|
364
369
|
{
|
|
@@ -1546,7 +1551,7 @@
|
|
|
1546
1551
|
{
|
|
1547
1552
|
"kind": "Function",
|
|
1548
1553
|
"canonicalReference": "@alloy-js/python!Declaration:function(1)",
|
|
1549
|
-
"docComment": "/**\n * A Python declaration, which can be a class, function, variable, etc.\n *\n * @remarks\n *\n *\n * This component is used to create a declaration with a symbol that can be\n * referenced in the code
|
|
1554
|
+
"docComment": "/**\n * A Python declaration, which can be a class, function, variable, etc.\n *\n * @remarks\n *\n *\n * This component is used to create a declaration with a symbol that can be\n * referenced in the code.\n */\n",
|
|
1550
1555
|
"excerptTokens": [
|
|
1551
1556
|
{
|
|
1552
1557
|
"kind": "Content",
|
|
@@ -1638,7 +1643,12 @@
|
|
|
1638
1643
|
},
|
|
1639
1644
|
{
|
|
1640
1645
|
"kind": "Content",
|
|
1641
|
-
"text": "string"
|
|
1646
|
+
"text": "string | "
|
|
1647
|
+
},
|
|
1648
|
+
{
|
|
1649
|
+
"kind": "Reference",
|
|
1650
|
+
"text": "Namekey",
|
|
1651
|
+
"canonicalReference": "@alloy-js/core!Namekey:interface"
|
|
1642
1652
|
},
|
|
1643
1653
|
{
|
|
1644
1654
|
"kind": "Content",
|
|
@@ -1651,7 +1661,7 @@
|
|
|
1651
1661
|
"name": "name",
|
|
1652
1662
|
"propertyTypeTokenRange": {
|
|
1653
1663
|
"startIndex": 1,
|
|
1654
|
-
"endIndex":
|
|
1664
|
+
"endIndex": 3
|
|
1655
1665
|
}
|
|
1656
1666
|
},
|
|
1657
1667
|
{
|
|
@@ -1947,7 +1957,12 @@
|
|
|
1947
1957
|
},
|
|
1948
1958
|
{
|
|
1949
1959
|
"kind": "Content",
|
|
1950
|
-
"text": "string"
|
|
1960
|
+
"text": "string | "
|
|
1961
|
+
},
|
|
1962
|
+
{
|
|
1963
|
+
"kind": "Reference",
|
|
1964
|
+
"text": "Namekey",
|
|
1965
|
+
"canonicalReference": "@alloy-js/core!Namekey:interface"
|
|
1951
1966
|
},
|
|
1952
1967
|
{
|
|
1953
1968
|
"kind": "Content",
|
|
@@ -1960,7 +1975,7 @@
|
|
|
1960
1975
|
"name": "name",
|
|
1961
1976
|
"propertyTypeTokenRange": {
|
|
1962
1977
|
"startIndex": 1,
|
|
1963
|
-
"endIndex":
|
|
1978
|
+
"endIndex": 3
|
|
1964
1979
|
}
|
|
1965
1980
|
},
|
|
1966
1981
|
{
|
|
@@ -2154,16 +2169,16 @@
|
|
|
2154
2169
|
},
|
|
2155
2170
|
{
|
|
2156
2171
|
"kind": "Content",
|
|
2157
|
-
"text": "<
|
|
2172
|
+
"text": "<"
|
|
2158
2173
|
},
|
|
2159
2174
|
{
|
|
2160
2175
|
"kind": "Reference",
|
|
2161
|
-
"text": "
|
|
2162
|
-
"canonicalReference": "@alloy-js/
|
|
2176
|
+
"text": "EnumMemberProps",
|
|
2177
|
+
"canonicalReference": "@alloy-js/python!EnumMemberProps:interface"
|
|
2163
2178
|
},
|
|
2164
2179
|
{
|
|
2165
2180
|
"kind": "Content",
|
|
2166
|
-
"text": "
|
|
2181
|
+
"text": ">"
|
|
2167
2182
|
},
|
|
2168
2183
|
{
|
|
2169
2184
|
"kind": "Content",
|
|
@@ -4975,99 +4990,6 @@
|
|
|
4975
4990
|
"endIndex": 6
|
|
4976
4991
|
}
|
|
4977
4992
|
},
|
|
4978
|
-
{
|
|
4979
|
-
"kind": "Function",
|
|
4980
|
-
"canonicalReference": "@alloy-js/python!NoNamePolicy:function(1)",
|
|
4981
|
-
"docComment": "/**\n * A wrapper component that disables name policy transformation for its children.\n *\n * This is useful for components that need to preserve exact names without applying\n * naming conventions, such as Python dunder methods like `__init__`, `__str__`, etc.\n *\n * @example\n * ```tsx\n * <NoNamePolicy>\n * <FunctionDeclaration name=\"__init__\" instanceFunction>\n * // Function content\n * </FunctionDeclaration>\n * </NoNamePolicy>\n * ```\n *\n *\n * This ensures `__init__` stays as `__init__` without name policy transformation.\n */\n",
|
|
4982
|
-
"excerptTokens": [
|
|
4983
|
-
{
|
|
4984
|
-
"kind": "Content",
|
|
4985
|
-
"text": "export declare function NoNamePolicy(props: "
|
|
4986
|
-
},
|
|
4987
|
-
{
|
|
4988
|
-
"kind": "Reference",
|
|
4989
|
-
"text": "NoNamePolicyProps",
|
|
4990
|
-
"canonicalReference": "@alloy-js/python!NoNamePolicyProps:interface"
|
|
4991
|
-
},
|
|
4992
|
-
{
|
|
4993
|
-
"kind": "Content",
|
|
4994
|
-
"text": "): "
|
|
4995
|
-
},
|
|
4996
|
-
{
|
|
4997
|
-
"kind": "Reference",
|
|
4998
|
-
"text": "Children",
|
|
4999
|
-
"canonicalReference": "@alloy-js/core!Children:type"
|
|
5000
|
-
},
|
|
5001
|
-
{
|
|
5002
|
-
"kind": "Content",
|
|
5003
|
-
"text": ";"
|
|
5004
|
-
}
|
|
5005
|
-
],
|
|
5006
|
-
"fileUrlPath": "src/components/NoNamePolicy.tsx",
|
|
5007
|
-
"returnTypeTokenRange": {
|
|
5008
|
-
"startIndex": 3,
|
|
5009
|
-
"endIndex": 4
|
|
5010
|
-
},
|
|
5011
|
-
"releaseTag": "Public",
|
|
5012
|
-
"overloadIndex": 1,
|
|
5013
|
-
"parameters": [
|
|
5014
|
-
{
|
|
5015
|
-
"parameterName": "props",
|
|
5016
|
-
"parameterTypeTokenRange": {
|
|
5017
|
-
"startIndex": 1,
|
|
5018
|
-
"endIndex": 2
|
|
5019
|
-
},
|
|
5020
|
-
"isOptional": false
|
|
5021
|
-
}
|
|
5022
|
-
],
|
|
5023
|
-
"name": "NoNamePolicy"
|
|
5024
|
-
},
|
|
5025
|
-
{
|
|
5026
|
-
"kind": "Interface",
|
|
5027
|
-
"canonicalReference": "@alloy-js/python!NoNamePolicyProps:interface",
|
|
5028
|
-
"docComment": "",
|
|
5029
|
-
"excerptTokens": [
|
|
5030
|
-
{
|
|
5031
|
-
"kind": "Content",
|
|
5032
|
-
"text": "export interface NoNamePolicyProps "
|
|
5033
|
-
}
|
|
5034
|
-
],
|
|
5035
|
-
"fileUrlPath": "src/components/NoNamePolicy.tsx",
|
|
5036
|
-
"releaseTag": "Public",
|
|
5037
|
-
"name": "NoNamePolicyProps",
|
|
5038
|
-
"preserveMemberOrder": false,
|
|
5039
|
-
"members": [
|
|
5040
|
-
{
|
|
5041
|
-
"kind": "PropertySignature",
|
|
5042
|
-
"canonicalReference": "@alloy-js/python!NoNamePolicyProps#children:member",
|
|
5043
|
-
"docComment": "",
|
|
5044
|
-
"excerptTokens": [
|
|
5045
|
-
{
|
|
5046
|
-
"kind": "Content",
|
|
5047
|
-
"text": "children: "
|
|
5048
|
-
},
|
|
5049
|
-
{
|
|
5050
|
-
"kind": "Reference",
|
|
5051
|
-
"text": "Children",
|
|
5052
|
-
"canonicalReference": "@alloy-js/core!Children:type"
|
|
5053
|
-
},
|
|
5054
|
-
{
|
|
5055
|
-
"kind": "Content",
|
|
5056
|
-
"text": ";"
|
|
5057
|
-
}
|
|
5058
|
-
],
|
|
5059
|
-
"isReadonly": false,
|
|
5060
|
-
"isOptional": false,
|
|
5061
|
-
"releaseTag": "Public",
|
|
5062
|
-
"name": "children",
|
|
5063
|
-
"propertyTypeTokenRange": {
|
|
5064
|
-
"startIndex": 1,
|
|
5065
|
-
"endIndex": 2
|
|
5066
|
-
}
|
|
5067
|
-
}
|
|
5068
|
-
],
|
|
5069
|
-
"extendsTokenRanges": []
|
|
5070
|
-
},
|
|
5071
4993
|
{
|
|
5072
4994
|
"kind": "Interface",
|
|
5073
4995
|
"canonicalReference": "@alloy-js/python!ParameterDescriptor:interface",
|
|
@@ -5150,7 +5072,12 @@
|
|
|
5150
5072
|
},
|
|
5151
5073
|
{
|
|
5152
5074
|
"kind": "Content",
|
|
5153
|
-
"text": "string"
|
|
5075
|
+
"text": "string | "
|
|
5076
|
+
},
|
|
5077
|
+
{
|
|
5078
|
+
"kind": "Reference",
|
|
5079
|
+
"text": "Namekey",
|
|
5080
|
+
"canonicalReference": "@alloy-js/core!Namekey:interface"
|
|
5154
5081
|
},
|
|
5155
5082
|
{
|
|
5156
5083
|
"kind": "Content",
|
|
@@ -5163,7 +5090,7 @@
|
|
|
5163
5090
|
"name": "name",
|
|
5164
5091
|
"propertyTypeTokenRange": {
|
|
5165
5092
|
"startIndex": 1,
|
|
5166
|
-
"endIndex":
|
|
5093
|
+
"endIndex": 3
|
|
5167
5094
|
}
|
|
5168
5095
|
},
|
|
5169
5096
|
{
|
|
@@ -6051,7 +5978,12 @@
|
|
|
6051
5978
|
},
|
|
6052
5979
|
{
|
|
6053
5980
|
"kind": "Content",
|
|
6054
|
-
"text": "string"
|
|
5981
|
+
"text": "string | "
|
|
5982
|
+
},
|
|
5983
|
+
{
|
|
5984
|
+
"kind": "Reference",
|
|
5985
|
+
"text": "Namekey",
|
|
5986
|
+
"canonicalReference": "@alloy-js/core!Namekey:interface"
|
|
6055
5987
|
},
|
|
6056
5988
|
{
|
|
6057
5989
|
"kind": "Content",
|
|
@@ -6097,23 +6029,23 @@
|
|
|
6097
6029
|
"parameterName": "name",
|
|
6098
6030
|
"parameterTypeTokenRange": {
|
|
6099
6031
|
"startIndex": 1,
|
|
6100
|
-
"endIndex":
|
|
6032
|
+
"endIndex": 3
|
|
6101
6033
|
},
|
|
6102
6034
|
"isOptional": false
|
|
6103
6035
|
},
|
|
6104
6036
|
{
|
|
6105
6037
|
"parameterName": "spaces",
|
|
6106
6038
|
"parameterTypeTokenRange": {
|
|
6107
|
-
"startIndex":
|
|
6108
|
-
"endIndex":
|
|
6039
|
+
"startIndex": 4,
|
|
6040
|
+
"endIndex": 8
|
|
6109
6041
|
},
|
|
6110
6042
|
"isOptional": false
|
|
6111
6043
|
},
|
|
6112
6044
|
{
|
|
6113
6045
|
"parameterName": "options",
|
|
6114
6046
|
"parameterTypeTokenRange": {
|
|
6115
|
-
"startIndex":
|
|
6116
|
-
"endIndex":
|
|
6047
|
+
"startIndex": 9,
|
|
6048
|
+
"endIndex": 10
|
|
6117
6049
|
},
|
|
6118
6050
|
"isOptional": false
|
|
6119
6051
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { memberRefkey, refkey } from "@alloy-js/core";
|
|
1
|
+
import { memberRefkey, namekey, refkey } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import * as py from "../src/index.js";
|
|
@@ -19,6 +19,18 @@ describe("Python Class", () => {
|
|
|
19
19
|
`);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
it("takes a namekey", () => {
|
|
23
|
+
const result = toSourceText([
|
|
24
|
+
<py.ClassDeclaration name={namekey("Foo")} />,
|
|
25
|
+
]);
|
|
26
|
+
expect(result).toRenderTo(d`
|
|
27
|
+
class Foo:
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
`);
|
|
32
|
+
});
|
|
33
|
+
|
|
22
34
|
it("renders a class with a body", () => {
|
|
23
35
|
const result = toSourceText([
|
|
24
36
|
<py.ClassDeclaration name="Bar">print('hi')</py.ClassDeclaration>,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { refkey } from "@alloy-js/core";
|
|
1
|
+
import { namekey, refkey } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import * as py from "../src/index.js";
|
|
@@ -19,6 +19,18 @@ describe("Function Declaration", () => {
|
|
|
19
19
|
`);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
it("takes a namekey", () => {
|
|
23
|
+
const result = toSourceText([
|
|
24
|
+
<py.FunctionDeclaration name={namekey("foo-bar")} />,
|
|
25
|
+
]);
|
|
26
|
+
expect(result).toRenderTo(d`
|
|
27
|
+
def foo_bar():
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
`);
|
|
32
|
+
});
|
|
33
|
+
|
|
22
34
|
it("renders a function with no body as 'pass' with return type", () => {
|
|
23
35
|
const result = toSourceText([
|
|
24
36
|
<py.FunctionDeclaration name="foo" returnType="int" />,
|
package/test/variables.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { code, refkey } from "@alloy-js/core";
|
|
1
|
+
import { code, namekey, refkey } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
4
|
import * as py from "../src/index.js";
|
|
@@ -16,6 +16,17 @@ describe("Python Variable", () => {
|
|
|
16
16
|
expect(res).toBe(`my_var: int = 42`);
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
it("takes a namekey", () => {
|
|
20
|
+
const res = toSourceText([
|
|
21
|
+
<py.VariableDeclaration
|
|
22
|
+
name={namekey("my-var")}
|
|
23
|
+
type="int"
|
|
24
|
+
initializer={42}
|
|
25
|
+
/>,
|
|
26
|
+
]);
|
|
27
|
+
expect(res).toBe(`my_var: int = 42`);
|
|
28
|
+
});
|
|
29
|
+
|
|
19
30
|
it("declares a python variable without value", () => {
|
|
20
31
|
const res = toSourceText([
|
|
21
32
|
<py.VariableDeclaration name="myVar" type="int" omitNone />,
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
28
|
-
//# sourceMappingURL=NoNamePolicy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["NamePolicyContext","NoNamePolicy","props","_$createComponent","Provider","value","undefined","children"],"sources":["../../../src/components/NoNamePolicy.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,iBAAiB,QAAQ,gBAAgB;AAOlD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAACC,KAAwB,EAAE;EACrD,OAAAC,iBAAA,CACGH,iBAAiB,CAACI,QAAQ;IAACC,KAAK,EAAEC,SAAS;IAAA,IAAAC,SAAA;MAAA,OACzCL,KAAK,CAACK,QAAQ;IAAA;EAAA;AAGrB","ignoreList":[]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { NamePolicyContext } from "@alloy-js/core";
|
|
2
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
export interface NoNamePolicyProps {
|
|
5
|
-
children: Children;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A wrapper component that disables name policy transformation for its children.
|
|
10
|
-
*
|
|
11
|
-
* This is useful for components that need to preserve exact names without applying
|
|
12
|
-
* naming conventions, such as Python dunder methods like `__init__`, `__str__`, etc.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```tsx
|
|
16
|
-
* <NoNamePolicy>
|
|
17
|
-
* <FunctionDeclaration name="__init__" instanceFunction>
|
|
18
|
-
* // Function content
|
|
19
|
-
* </FunctionDeclaration>
|
|
20
|
-
* </NoNamePolicy>
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* This ensures `__init__` stays as `__init__` without name policy transformation.
|
|
24
|
-
*/
|
|
25
|
-
export function NoNamePolicy(props: NoNamePolicyProps) {
|
|
26
|
-
return (
|
|
27
|
-
<NamePolicyContext.Provider value={undefined}>
|
|
28
|
-
{props.children}
|
|
29
|
-
</NamePolicyContext.Provider>
|
|
30
|
-
);
|
|
31
|
-
}
|