@alloy-js/python 0.1.0-dev.3 → 0.1.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/components/CallSignature.d.ts.map +1 -1
- package/dist/src/components/CallSignature.js +8 -11
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +6 -20
- package/dist/src/components/ClassInstantiation.d.ts.map +1 -1
- package/dist/src/components/ClassInstantiation.js +4 -4
- package/dist/src/components/Declaration.d.ts +1 -5
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +6 -15
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +33 -59
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +3 -4
- package/dist/src/components/FunctionDeclaration.d.ts +3 -1
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +6 -16
- package/dist/src/components/LexicalScope.d.ts +8 -0
- package/dist/src/components/LexicalScope.d.ts.map +1 -0
- package/dist/src/components/LexicalScope.js +21 -0
- package/dist/src/components/MemberScope.d.ts +8 -0
- package/dist/src/components/MemberScope.d.ts.map +1 -0
- package/dist/src/components/MemberScope.js +15 -0
- package/dist/src/components/PythonBlock.d.ts +5 -4
- package/dist/src/components/PythonBlock.d.ts.map +1 -1
- package/dist/src/components/PythonBlock.js +0 -1
- package/dist/src/components/SourceFile.js +1 -2
- package/dist/src/components/VariableDeclaration.d.ts.map +1 -1
- package/dist/src/components/VariableDeclaration.js +8 -31
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -0
- package/dist/src/create-module.d.ts.map +1 -1
- package/dist/src/create-module.js +3 -4
- package/dist/src/name-conflict-resolver.d.ts +3 -0
- package/dist/src/name-conflict-resolver.d.ts.map +1 -0
- package/dist/src/name-conflict-resolver.js +7 -0
- package/dist/src/symbol-creation.d.ts +13 -2
- package/dist/src/symbol-creation.d.ts.map +1 -1
- package/dist/src/symbol-creation.js +33 -9
- package/dist/src/symbols/index.d.ts +1 -1
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +1 -1
- package/dist/src/symbols/python-lexical-scope.d.ts +7 -0
- package/dist/src/symbols/python-lexical-scope.d.ts.map +1 -0
- package/dist/src/symbols/python-lexical-scope.js +14 -0
- package/dist/src/symbols/python-member-scope.d.ts +3 -4
- package/dist/src/symbols/python-member-scope.d.ts.map +1 -1
- package/dist/src/symbols/python-member-scope.js +4 -7
- package/dist/src/symbols/python-module-scope.d.ts +4 -9
- package/dist/src/symbols/python-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/python-module-scope.js +6 -14
- package/dist/src/symbols/python-output-symbol.d.ts +10 -7
- package/dist/src/symbols/python-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/python-output-symbol.js +23 -6
- package/dist/src/symbols/reference.d.ts +2 -2
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +36 -36
- package/dist/src/symbols/scopes.d.ts +3 -1
- package/dist/src/symbols/scopes.d.ts.map +1 -1
- package/dist/src/symbols/scopes.js +8 -0
- package/dist/test/classdeclarations.test.js +87 -52
- package/dist/test/enums.test.js +8 -2
- package/dist/test/externals.test.js +6 -5
- package/dist/test/functiondeclaration.test.js +73 -36
- package/dist/test/imports.test.js +9 -36
- package/dist/test/utils.d.ts +2 -3
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +3 -2
- package/dist/test/variables.test.js +11 -11
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/CallSignature.tsx +9 -17
- package/src/components/ClassDeclaration.tsx +5 -32
- package/src/components/ClassInstantiation.tsx +6 -12
- package/src/components/Declaration.tsx +1 -20
- package/src/components/EnumDeclaration.tsx +18 -41
- package/src/components/EnumMember.tsx +1 -3
- package/src/components/FunctionDeclaration.tsx +12 -30
- package/src/components/LexicalScope.tsx +24 -0
- package/src/components/MemberScope.tsx +18 -0
- package/src/components/PythonBlock.tsx +6 -1
- package/src/components/SourceFile.tsx +2 -2
- package/src/components/VariableDeclaration.tsx +7 -35
- package/src/components/index.ts +2 -0
- package/src/create-module.ts +7 -13
- package/src/name-conflict-resolver.ts +21 -0
- package/src/symbol-creation.ts +50 -11
- package/src/symbols/index.ts +1 -1
- package/src/symbols/python-lexical-scope.ts +16 -0
- package/src/symbols/python-member-scope.ts +4 -8
- package/src/symbols/python-module-scope.ts +6 -32
- package/src/symbols/python-output-symbol.ts +36 -10
- package/src/symbols/reference.tsx +70 -0
- package/src/symbols/scopes.ts +15 -1
- package/temp/api.json +1015 -561
- package/test/classdeclarations.test.tsx +66 -31
- package/test/enums.test.tsx +2 -2
- package/test/externals.test.tsx +6 -7
- package/test/functiondeclaration.test.tsx +48 -39
- package/test/imports.test.tsx +11 -36
- package/test/utils.tsx +9 -5
- package/test/variables.test.tsx +11 -7
- package/dist/src/symbols/custom-output-scope.d.ts +0 -10
- package/dist/src/symbols/custom-output-scope.d.ts.map +0 -1
- package/dist/src/symbols/custom-output-scope.js +0 -25
- package/src/symbols/custom-output-scope.ts +0 -35
- package/src/symbols/reference.ts +0 -99
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CallSignature.d.ts","sourceRoot":"","sources":["../../../src/components/CallSignature.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"CallSignature.d.ts","sourceRoot":"","sources":["../../../src/components/CallSignature.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAOT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMjE,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,mBAAmB,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,YAmD1E;AAsED,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,UAAU,CAAC,EAAE,mBAAmB,EAAE,GAAG,MAAM,EAAE,CAAC;IAE9C;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,UAAU,CAAC,EAAE,QAAQ,CAAC;CACvB;AACD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,YAyBtD"}
|
|
@@ -66,8 +66,7 @@ export function CallSignatureParameters(props) {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
function parameter(param) {
|
|
69
|
-
const
|
|
70
|
-
SymbolSlot.instantiateInto(param.symbol);
|
|
69
|
+
const TypeSlot = param.TypeSlot; // TypeSlot will always be present when param.type is true.
|
|
71
70
|
return _$createIntrinsic("group", {
|
|
72
71
|
get children() {
|
|
73
72
|
return [_$memo(() => param.symbol.name), _$createComponent(Show, {
|
|
@@ -75,7 +74,7 @@ function parameter(param) {
|
|
|
75
74
|
return !!param.type;
|
|
76
75
|
},
|
|
77
76
|
get children() {
|
|
78
|
-
return [": ", _$createComponent(
|
|
77
|
+
return [": ", _$createComponent(TypeSlot, {
|
|
79
78
|
get children() {
|
|
80
79
|
return param.type;
|
|
81
80
|
}
|
|
@@ -128,16 +127,12 @@ function parameter(param) {
|
|
|
128
127
|
});
|
|
129
128
|
}
|
|
130
129
|
function normalizeAndDeclareParameters(parameters) {
|
|
131
|
-
const sfContext = useContext(PythonSourceFileContext);
|
|
132
|
-
const module = sfContext?.module;
|
|
133
130
|
if (parameters.length === 0) {
|
|
134
131
|
return [];
|
|
135
132
|
}
|
|
136
133
|
if (typeof parameters[0] === "string") {
|
|
137
134
|
return parameters.map(paramName => {
|
|
138
|
-
const symbol = createPythonSymbol(paramName, {
|
|
139
|
-
module: module
|
|
140
|
-
}, "parameter", false);
|
|
135
|
+
const symbol = createPythonSymbol(paramName, {}, "parameter");
|
|
141
136
|
return {
|
|
142
137
|
refkeys: symbol.refkeys,
|
|
143
138
|
symbol
|
|
@@ -145,13 +140,15 @@ function normalizeAndDeclareParameters(parameters) {
|
|
|
145
140
|
});
|
|
146
141
|
} else {
|
|
147
142
|
return parameters.map(param => {
|
|
143
|
+
const TypeSlot = createSymbolSlot();
|
|
148
144
|
const symbol = createPythonSymbol(param.name, {
|
|
149
145
|
refkeys: param.refkey,
|
|
150
|
-
|
|
151
|
-
}, "parameter"
|
|
146
|
+
type: TypeSlot.firstSymbol
|
|
147
|
+
}, "parameter");
|
|
152
148
|
return {
|
|
153
149
|
...param,
|
|
154
|
-
symbol
|
|
150
|
+
symbol,
|
|
151
|
+
TypeSlot
|
|
155
152
|
};
|
|
156
153
|
});
|
|
157
154
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmC,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAIrE,MAAM,WAAW,qBAAsB,SAAQ,oBAAoB;IACjE;;OAEG;IACH,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,YA8B5D"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { List, Name,
|
|
2
|
+
import { List, Name, Show, childrenArray } from "@alloy-js/core";
|
|
3
3
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
4
4
|
import { Declaration } from "./Declaration.js";
|
|
5
|
+
import { MemberScope } from "./MemberScope.js";
|
|
5
6
|
import { PythonBlock } from "./PythonBlock.js";
|
|
6
7
|
/**
|
|
7
8
|
* Create a Python class declaration.
|
|
@@ -39,29 +40,14 @@ export function ClassDeclaration(props) {
|
|
|
39
40
|
space: true
|
|
40
41
|
}), ")"];
|
|
41
42
|
const sym = createPythonSymbol(props.name, {
|
|
42
|
-
refkeys: props.refkey
|
|
43
|
-
|
|
44
|
-
}, "class", true);
|
|
45
|
-
takeSymbols(memberSymbol => {
|
|
46
|
-
// Transform emitted symbols into instance/class members
|
|
47
|
-
memberSymbol.flags |= OutputSymbolFlags.InstanceMember;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Propagate the name after the name policy was applied
|
|
51
|
-
const updatedProps = {
|
|
52
|
-
...props,
|
|
53
|
-
name: sym.name,
|
|
54
|
-
nameKind: "class"
|
|
55
|
-
};
|
|
43
|
+
refkeys: props.refkey
|
|
44
|
+
}, "class");
|
|
56
45
|
const hasChildren = childrenArray(() => props.children).filter(c => Boolean(c)).length > 0;
|
|
57
46
|
return _$createComponent(Declaration, {
|
|
58
47
|
symbol: sym,
|
|
59
48
|
get children() {
|
|
60
|
-
return ["class ", _$createComponent(Name, {}), _$createComponent(
|
|
61
|
-
|
|
62
|
-
return updatedProps.name;
|
|
63
|
-
},
|
|
64
|
-
kind: "class",
|
|
49
|
+
return ["class ", _$createComponent(Name, {}), _$createComponent(MemberScope, {
|
|
50
|
+
ownerSymbol: sym,
|
|
65
51
|
get children() {
|
|
66
52
|
return [basesPart, _$createComponent(PythonBlock, {
|
|
67
53
|
opener: ":",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassInstantiation.d.ts","sourceRoot":"","sources":["../../../src/components/ClassInstantiation.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ClassInstantiation.d.ts","sourceRoot":"","sources":["../../../src/components/ClassInstantiation.tsx"],"names":[],"mappings":"AAMA,OAAO,EAEL,2BAA2B,EAC5B,MAAM,8BAA8B,CAAC;AAGtC,MAAM,WAAW,uBAAwB,SAAQ,2BAA2B;CAAG;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,qCAchE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { emitSymbol, instantiateTakenMembersTo
|
|
2
|
+
import { emitSymbol, instantiateTakenMembersTo, useContext } from "@alloy-js/core";
|
|
3
3
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
4
4
|
import { FunctionCallExpression } from "./FunctionCallExpression.js";
|
|
5
5
|
import { PythonSourceFileContext } from "./SourceFile.js";
|
|
@@ -26,10 +26,10 @@ export function ClassInstantiation(props) {
|
|
|
26
26
|
const sfContext = useContext(PythonSourceFileContext);
|
|
27
27
|
const module = sfContext?.module;
|
|
28
28
|
const sym = createPythonSymbol("", {
|
|
29
|
-
|
|
29
|
+
transient: true,
|
|
30
30
|
module: module
|
|
31
|
-
}
|
|
32
|
-
|
|
31
|
+
});
|
|
32
|
+
instantiateTakenMembersTo(sym, "static", "instance");
|
|
33
33
|
emitSymbol(sym);
|
|
34
34
|
return [_$createComponent(FunctionCallExpression, props)];
|
|
35
35
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Children,
|
|
1
|
+
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { PythonElements } from "../name-policy.js";
|
|
3
3
|
import { PythonOutputSymbol } from "../symbols/index.js";
|
|
4
4
|
export interface BaseDeclarationProps {
|
|
@@ -11,10 +11,6 @@ export interface BaseDeclarationProps {
|
|
|
11
11
|
* The refkey or array of refkeys for this declaration.
|
|
12
12
|
*/
|
|
13
13
|
refkey?: Refkey | Refkey[];
|
|
14
|
-
/**
|
|
15
|
-
* Flags for the symbol created by this component.
|
|
16
|
-
*/
|
|
17
|
-
flags?: OutputSymbolFlags;
|
|
18
14
|
children?: Children;
|
|
19
15
|
/**
|
|
20
16
|
* Documentation for this declaration
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Declaration.d.ts","sourceRoot":"","sources":["../../../src/components/Declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"Declaration.d.ts","sourceRoot":"","sources":["../../../src/components/Declaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,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,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,YAgBlD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { Declaration as CoreDeclaration
|
|
2
|
+
import { Declaration as CoreDeclaration } from "@alloy-js/core";
|
|
3
3
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
4
4
|
/**
|
|
5
5
|
* A Python declaration, which can be a class, function, variable, etc.
|
|
@@ -16,22 +16,13 @@ export function Declaration(props) {
|
|
|
16
16
|
sym = props.symbol;
|
|
17
17
|
} else {
|
|
18
18
|
sym = createPythonSymbol(props.name, {
|
|
19
|
-
refkeys: props.refkey
|
|
20
|
-
|
|
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);
|
|
19
|
+
refkeys: props.refkey
|
|
20
|
+
}, props.nameKind);
|
|
32
21
|
}
|
|
33
22
|
return _$createComponent(CoreDeclaration, {
|
|
34
23
|
symbol: sym,
|
|
35
|
-
children
|
|
24
|
+
get children() {
|
|
25
|
+
return props.children;
|
|
26
|
+
}
|
|
36
27
|
});
|
|
37
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/EnumDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"EnumDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/EnumDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAIT,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAMxD,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,YAoCzD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,YAgDpD"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { Declaration as CoreDeclaration, For,
|
|
2
|
+
import { Declaration as CoreDeclaration, For, Show } from "@alloy-js/core";
|
|
3
3
|
import { enumModule } from "../builtins/python.js";
|
|
4
4
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
5
|
-
import { usePythonScope } from "../symbols/scopes.js";
|
|
6
5
|
import { EnumMember } from "./EnumMember.js";
|
|
7
|
-
import { PythonBlock } from "./PythonBlock.js";
|
|
8
6
|
import { SimpleCommentBlock } from "./index.js";
|
|
7
|
+
import { MemberScope } from "./MemberScope.js";
|
|
8
|
+
import { PythonBlock } from "./PythonBlock.js";
|
|
9
9
|
/**
|
|
10
10
|
* A Python enum declaration, following https://docs.python.org/3.11/library/enum.html.
|
|
11
11
|
*
|
|
@@ -80,14 +80,9 @@ export function EnumDeclaration(props) {
|
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
82
|
export function FunctionalEnumDeclaration(props) {
|
|
83
|
-
const binder = useBinder();
|
|
84
|
-
const scope = usePythonScope();
|
|
85
83
|
const sym = createPythonSymbol(props.name, {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
refkeys: props.refkey,
|
|
89
|
-
flags: OutputSymbolFlags.StaticMemberContainer
|
|
90
|
-
}, "enum", false);
|
|
84
|
+
refkeys: props.refkey
|
|
85
|
+
}, "enum");
|
|
91
86
|
const members = props.members ?? [];
|
|
92
87
|
let opener, ender;
|
|
93
88
|
if (members.length && members.every(m => m.value === undefined)) {
|
|
@@ -116,16 +111,8 @@ export function FunctionalEnumDeclaration(props) {
|
|
|
116
111
|
symbol: sym,
|
|
117
112
|
get children() {
|
|
118
113
|
return [_$memo(() => sym.name), " = ", _$memo(() => enumModule["."].Enum), "('", _$memo(() => sym.name), "',", " ", _$createComponent(MemberScope, {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return _$createComponent(Scope, {
|
|
122
|
-
get name() {
|
|
123
|
-
return props.name;
|
|
124
|
-
},
|
|
125
|
-
kind: "enum",
|
|
126
|
-
children: memberExpr
|
|
127
|
-
});
|
|
128
|
-
}
|
|
114
|
+
ownerSymbol: sym,
|
|
115
|
+
children: memberExpr
|
|
129
116
|
}), ")"];
|
|
130
117
|
}
|
|
131
118
|
})];
|
|
@@ -202,14 +189,9 @@ export function FunctionalEnumDeclaration(props) {
|
|
|
202
189
|
*/
|
|
203
190
|
export function ClassEnumDeclaration(props) {
|
|
204
191
|
const baseType = props.baseType || "Enum";
|
|
205
|
-
const binder = useBinder();
|
|
206
|
-
const scope = usePythonScope();
|
|
207
192
|
const sym = createPythonSymbol(props.name, {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
refkeys: props.refkey,
|
|
211
|
-
flags: OutputSymbolFlags.StaticMemberContainer
|
|
212
|
-
}, "enum", false);
|
|
193
|
+
refkeys: props.refkey
|
|
194
|
+
}, "enum");
|
|
213
195
|
let memberList = (props.members ?? []).map(m => m.value === undefined ? {
|
|
214
196
|
...m,
|
|
215
197
|
auto: false
|
|
@@ -235,40 +217,32 @@ export function ClassEnumDeclaration(props) {
|
|
|
235
217
|
}), _$createIntrinsic("hbr", {})];
|
|
236
218
|
}
|
|
237
219
|
}), "class ", _$memo(() => sym.name), "(", _$memo(() => enumModule["."][baseType]), ")", _$createComponent(MemberScope, {
|
|
238
|
-
|
|
220
|
+
ownerSymbol: sym,
|
|
239
221
|
get children() {
|
|
240
|
-
return _$createComponent(
|
|
241
|
-
|
|
242
|
-
return sym.name;
|
|
243
|
-
},
|
|
244
|
-
kind: "enum",
|
|
222
|
+
return _$createComponent(PythonBlock, {
|
|
223
|
+
opener: ":",
|
|
245
224
|
get children() {
|
|
246
|
-
return _$createComponent(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
})
|
|
269
|
-
}), _$memo(() => props.children)];
|
|
270
|
-
}
|
|
271
|
-
});
|
|
225
|
+
return [_$createComponent(For, {
|
|
226
|
+
each: memberList,
|
|
227
|
+
hardline: true,
|
|
228
|
+
children: member => _$createComponent(EnumMember, {
|
|
229
|
+
get name() {
|
|
230
|
+
return member.name;
|
|
231
|
+
},
|
|
232
|
+
get value() {
|
|
233
|
+
return member.value;
|
|
234
|
+
},
|
|
235
|
+
get jsValue() {
|
|
236
|
+
return member.jsValue;
|
|
237
|
+
},
|
|
238
|
+
get auto() {
|
|
239
|
+
return member.auto;
|
|
240
|
+
},
|
|
241
|
+
get doc() {
|
|
242
|
+
return member.doc;
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
}), _$memo(() => props.children)];
|
|
272
246
|
}
|
|
273
247
|
});
|
|
274
248
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnumMember.d.ts","sourceRoot":"","sources":["../../../src/components/EnumMember.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"EnumMember.d.ts","sourceRoot":"","sources":["../../../src/components/EnumMember.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAQ,MAAM,gBAAgB,CAAC;AAOxD,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,YAgChD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { Show } from "@alloy-js/core";
|
|
3
3
|
import { enumModule } from "../builtins/python.js";
|
|
4
4
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
5
5
|
import { Atom } from "./Atom.js";
|
|
@@ -20,9 +20,8 @@ export function EnumMember(props) {
|
|
|
20
20
|
const autoReference = props.auto === true ? enumModule["."].auto : undefined;
|
|
21
21
|
const value = props.auto === true ? [autoReference, "()"] : props.value;
|
|
22
22
|
const sym = createPythonSymbol(props.name, {
|
|
23
|
-
refkeys: props.refkey
|
|
24
|
-
|
|
25
|
-
}, "enum-member", true);
|
|
23
|
+
refkeys: props.refkey
|
|
24
|
+
}, "enum-member");
|
|
26
25
|
const valueCode = props.jsValue !== undefined ? _$createComponent(Atom, {
|
|
27
26
|
get jsValue() {
|
|
28
27
|
return props.jsValue;
|
|
@@ -22,6 +22,8 @@ export interface FunctionDeclarationProps extends BaseDeclarationProps, CallSign
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export declare function FunctionDeclaration(props: FunctionDeclarationProps): import("@alloy-js/core").Children;
|
|
25
|
+
export interface InitFunctionDeclarationProps extends Omit<FunctionDeclarationProps, "name" | "instanceFunction" | "classFunction"> {
|
|
26
|
+
}
|
|
25
27
|
/**
|
|
26
28
|
* A Python `__init__` function declaration.
|
|
27
29
|
*
|
|
@@ -43,5 +45,5 @@ export declare function FunctionDeclaration(props: FunctionDeclarationProps): im
|
|
|
43
45
|
* an instance function, and forces the name to be `__init__` without applying
|
|
44
46
|
* the name policy.
|
|
45
47
|
*/
|
|
46
|
-
export declare function InitFunctionDeclaration(props:
|
|
48
|
+
export declare function InitFunctionDeclaration(props: InitFunctionDeclarationProps): import("@alloy-js/core").Children;
|
|
47
49
|
//# sourceMappingURL=FunctionDeclaration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionDeclaration.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FunctionDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionDeclaration.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAIrE,MAAM,WAAW,wBACf,SAAQ,oBAAoB,EAC1B,kBAAkB;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,qCA8BlE;AAED,MAAM,WAAW,4BACf,SAAQ,IAAI,CACV,wBAAwB,EACxB,MAAM,GAAG,kBAAkB,GAAG,eAAe,CAC9C;CAAG;AAEN;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,qCAW1E"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, mergeProps as _$mergeProps, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { emitSymbol, Name,
|
|
2
|
+
import { emitSymbol, Name, Show } from "@alloy-js/core";
|
|
3
3
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
4
4
|
import { getCallSignatureProps } from "../utils.js";
|
|
5
5
|
import { CallSignature } from "./CallSignature.js";
|
|
6
6
|
import { Declaration } from "./Declaration.js";
|
|
7
7
|
import { PythonBlock } from "./PythonBlock.js";
|
|
8
|
-
import { NoNamePolicy } from "./index.js";
|
|
8
|
+
import { LexicalScope, NoNamePolicy } from "./index.js";
|
|
9
9
|
/**
|
|
10
10
|
* A Python function declaration.
|
|
11
11
|
*
|
|
@@ -27,28 +27,19 @@ import { NoNamePolicy } from "./index.js";
|
|
|
27
27
|
export function FunctionDeclaration(props) {
|
|
28
28
|
const asyncKwd = props.async ? "async " : "";
|
|
29
29
|
const callSignatureProps = getCallSignatureProps(props, {});
|
|
30
|
-
const memberScope = useMemberScope();
|
|
31
|
-
let scope = undefined;
|
|
32
|
-
if (memberScope !== undefined) {
|
|
33
|
-
scope = memberScope.instanceMembers;
|
|
34
|
-
} else {
|
|
35
|
-
scope = useScope();
|
|
36
|
-
}
|
|
37
30
|
const sym = createPythonSymbol(props.name, {
|
|
38
|
-
|
|
39
|
-
refkeys: props.refkey
|
|
40
|
-
|
|
41
|
-
}, "function", false);
|
|
31
|
+
instance: props.instanceFunction,
|
|
32
|
+
refkeys: props.refkey
|
|
33
|
+
}, "function");
|
|
42
34
|
emitSymbol(sym);
|
|
43
35
|
return [_$createComponent(Declaration, _$mergeProps(props, {
|
|
44
36
|
nameKind: "function",
|
|
45
37
|
symbol: sym,
|
|
46
38
|
get children() {
|
|
47
|
-
return [asyncKwd, "def ", _$createComponent(Name, {}), _$createComponent(
|
|
39
|
+
return [asyncKwd, "def ", _$createComponent(Name, {}), _$createComponent(LexicalScope, {
|
|
48
40
|
get name() {
|
|
49
41
|
return sym.name;
|
|
50
42
|
},
|
|
51
|
-
kind: "function",
|
|
52
43
|
get children() {
|
|
53
44
|
return [_$createComponent(CallSignature, _$mergeProps(callSignatureProps, {
|
|
54
45
|
get returnType() {
|
|
@@ -72,7 +63,6 @@ export function FunctionDeclaration(props) {
|
|
|
72
63
|
}
|
|
73
64
|
}))];
|
|
74
65
|
}
|
|
75
|
-
|
|
76
66
|
/**
|
|
77
67
|
* A Python `__init__` function declaration.
|
|
78
68
|
*
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ScopePropsWithInfo, ScopePropsWithValue } from "@alloy-js/core";
|
|
2
|
+
export interface LexicalScopePropsWithScopeValue extends ScopePropsWithValue {
|
|
3
|
+
}
|
|
4
|
+
export interface LeixcalScopePropsWithScopeInfo extends ScopePropsWithInfo {
|
|
5
|
+
}
|
|
6
|
+
export type LexicalScopeProps = LexicalScopePropsWithScopeValue | LeixcalScopePropsWithScopeInfo;
|
|
7
|
+
export declare function LexicalScope(props: LexicalScopeProps): import("@alloy-js/core").Children;
|
|
8
|
+
//# sourceMappingURL=LexicalScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LexicalScope.d.ts","sourceRoot":"","sources":["../../../src/components/LexicalScope.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAIhF,MAAM,WAAW,+BAAgC,SAAQ,mBAAmB;CAAG;AAC/E,MAAM,WAAW,8BAA+B,SAAQ,kBAAkB;CAAG;AAE7E,MAAM,MAAM,iBAAiB,GACzB,+BAA+B,GAC/B,8BAA8B,CAAC;AAEnC,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,qCAYpD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Scope } from "@alloy-js/core";
|
|
3
|
+
import { createLexicalScope } from "../symbol-creation.js";
|
|
4
|
+
import { PythonLexicalScope } from "../symbols/python-lexical-scope.js";
|
|
5
|
+
export function LexicalScope(props) {
|
|
6
|
+
let scope;
|
|
7
|
+
if ("value" in props) {
|
|
8
|
+
if (!(props.value instanceof PythonLexicalScope)) {
|
|
9
|
+
throw new Error("LexicalScope value must be a TSLexicalScope instance");
|
|
10
|
+
}
|
|
11
|
+
scope = props.value;
|
|
12
|
+
} else {
|
|
13
|
+
scope = createLexicalScope(props.name ?? "Lexical scope", props);
|
|
14
|
+
}
|
|
15
|
+
return _$createComponent(Scope, {
|
|
16
|
+
value: scope,
|
|
17
|
+
get children() {
|
|
18
|
+
return props.children;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Children } from "@alloy-js/core";
|
|
2
|
+
import { PythonOutputSymbol } from "../symbols/python-output-symbol.js";
|
|
3
|
+
export interface MemberScopeProps {
|
|
4
|
+
children: Children;
|
|
5
|
+
ownerSymbol: PythonOutputSymbol;
|
|
6
|
+
}
|
|
7
|
+
export declare function MemberScope(props: MemberScopeProps): Children;
|
|
8
|
+
//# sourceMappingURL=MemberScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemberScope.d.ts","sourceRoot":"","sources":["../../../src/components/MemberScope.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkC,MAAM,gBAAgB,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,kBAAkB,CAAC;CACjC;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAQlD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { MemberScope as CoreMemberScope } from "@alloy-js/core";
|
|
3
|
+
import { PythonMemberScope } from "../symbols/python-member-scope.js";
|
|
4
|
+
import { usePythonScope } from "../symbols/scopes.js";
|
|
5
|
+
export function MemberScope(props) {
|
|
6
|
+
const memberScope = new PythonMemberScope("member-scope", usePythonScope(), {
|
|
7
|
+
ownerSymbol: props.ownerSymbol
|
|
8
|
+
});
|
|
9
|
+
return _$createComponent(CoreMemberScope, {
|
|
10
|
+
value: memberScope,
|
|
11
|
+
get children() {
|
|
12
|
+
return props.children;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { Children } from "@alloy-js/core";
|
|
2
|
+
export interface PythonBlockProps {
|
|
3
|
+
children: Children;
|
|
4
|
+
opener?: string;
|
|
5
|
+
}
|
|
2
6
|
/**
|
|
3
7
|
* A Python block component that can be used to render a block of Python code.
|
|
4
8
|
*
|
|
@@ -16,8 +20,5 @@ import { Children } from "@alloy-js/core";
|
|
|
16
20
|
* y: str = None
|
|
17
21
|
* ```
|
|
18
22
|
*/
|
|
19
|
-
export declare function PythonBlock(props:
|
|
20
|
-
children: Children;
|
|
21
|
-
opener?: string;
|
|
22
|
-
}): Children;
|
|
23
|
+
export declare function PythonBlock(props: PythonBlockProps): Children;
|
|
23
24
|
//# sourceMappingURL=PythonBlock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PythonBlock.d.ts","sourceRoot":"","sources":["../../../src/components/PythonBlock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjD
|
|
1
|
+
{"version":3,"file":"PythonBlock.d.ts","sourceRoot":"","sources":["../../../src/components/PythonBlock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAMlD"}
|
|
@@ -30,7 +30,7 @@ export function SourceFile(props) {
|
|
|
30
30
|
const currentDir = directoryContext.path;
|
|
31
31
|
// Name of the scope is derived from the file path, minus the .py extension, and with slashes replaced by dots
|
|
32
32
|
const path = join(currentDir, props.path).replace(/\.py$/, "").replace(/\//g, ".");
|
|
33
|
-
const scope = new PythonModuleScope(path);
|
|
33
|
+
const scope = new PythonModuleScope(path, undefined);
|
|
34
34
|
const sfContext = {
|
|
35
35
|
scope: scope,
|
|
36
36
|
module: path
|
|
@@ -58,7 +58,6 @@ export function SourceFile(props) {
|
|
|
58
58
|
get children() {
|
|
59
59
|
return _$createComponent(Scope, {
|
|
60
60
|
value: scope,
|
|
61
|
-
kind: "source-file",
|
|
62
61
|
get children() {
|
|
63
62
|
return _$createComponent(List, {
|
|
64
63
|
doubleHardline: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariableDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/VariableDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"VariableDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/VariableDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAOT,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAGzD,MAAM,WAAW,wBAAyB,SAAQ,oBAAoB;IACpE;;OAEG;IACH,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,YA8ElE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { Declaration as CoreDeclaration, Name,
|
|
2
|
+
import { Declaration as CoreDeclaration, Name, Show, createSymbolSlot, emitSymbol, memo } from "@alloy-js/core";
|
|
3
3
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
4
4
|
import { Atom } from "./Atom.js";
|
|
5
5
|
import { SimpleCommentBlock } from "./index.js";
|
|
@@ -38,21 +38,16 @@ import { SimpleCommentBlock } from "./index.js";
|
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
40
|
export function VariableDeclaration(props) {
|
|
41
|
-
const instanceVariable = props.instanceVariable ?? false;
|
|
42
41
|
const TypeSymbolSlot = createSymbolSlot();
|
|
43
42
|
const ValueTypeSymbolSlot = createSymbolSlot();
|
|
44
|
-
const memberScope = useMemberScope();
|
|
45
|
-
let scope = undefined;
|
|
46
|
-
// Only consider the member scope if this is an instance variable
|
|
47
|
-
if (memberScope !== undefined && instanceVariable) {
|
|
48
|
-
scope = memberScope.instanceMembers;
|
|
49
|
-
} else {
|
|
50
|
-
scope = useScope();
|
|
51
|
-
}
|
|
52
43
|
const sym = createPythonSymbol(props.name, {
|
|
53
|
-
|
|
54
|
-
refkeys: props.refkey
|
|
55
|
-
|
|
44
|
+
instance: props.instanceVariable,
|
|
45
|
+
refkeys: props.refkey,
|
|
46
|
+
type: props.type ? TypeSymbolSlot.firstSymbol : undefined
|
|
47
|
+
}, "variable");
|
|
48
|
+
if (!props.type) {
|
|
49
|
+
ValueTypeSymbolSlot.moveMembersTo(sym);
|
|
50
|
+
}
|
|
56
51
|
emitSymbol(sym);
|
|
57
52
|
// Handle optional type annotation
|
|
58
53
|
const type = memo(() => {
|
|
@@ -63,24 +58,6 @@ export function VariableDeclaration(props) {
|
|
|
63
58
|
}
|
|
64
59
|
})];
|
|
65
60
|
});
|
|
66
|
-
effect(() => {
|
|
67
|
-
if (TypeSymbolSlot.ref.value) {
|
|
68
|
-
const takenSymbols = TypeSymbolSlot.ref.value;
|
|
69
|
-
for (const symbol of takenSymbols) {
|
|
70
|
-
// If the symbol is a type, instantiate it
|
|
71
|
-
symbol.instantiateTo(sym);
|
|
72
|
-
}
|
|
73
|
-
} else if (ValueTypeSymbolSlot.ref.value) {
|
|
74
|
-
const takenSymbols = ValueTypeSymbolSlot.ref.value;
|
|
75
|
-
for (const symbol of takenSymbols) {
|
|
76
|
-
// ignore non-transient symbols (likely not the result of an
|
|
77
|
-
// expression).
|
|
78
|
-
if (symbol.flags & OutputSymbolFlags.Transient) {
|
|
79
|
-
symbol.moveTo(sym);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
61
|
|
|
85
62
|
// If we receive a symbol, resolve it to a name
|
|
86
63
|
const value = typeof props.initializer === "object" ? memo(() => props.initializer) : props.initializer;
|
|
@@ -8,7 +8,9 @@ export * from "./EnumMember.js";
|
|
|
8
8
|
export * from "./FunctionCallExpression.js";
|
|
9
9
|
export * from "./FunctionDeclaration.js";
|
|
10
10
|
export * from "./ImportStatement.js";
|
|
11
|
+
export * from "./LexicalScope.js";
|
|
11
12
|
export * from "./MemberExpression.js";
|
|
13
|
+
export * from "./MemberScope.jsx";
|
|
12
14
|
export * from "./NoNamePolicy.js";
|
|
13
15
|
export * from "./PyDoc.js";
|
|
14
16
|
export * from "./PythonBlock.js";
|