@alloy-js/python 0.1.0-dev.4 → 0.1.0-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/dist/src/builtins/python.js +2 -1
  2. package/dist/src/builtins/python.js.map +1 -0
  3. package/dist/src/components/Atom.js +2 -1
  4. package/dist/src/components/Atom.js.map +1 -0
  5. package/dist/src/components/CallSignature.d.ts.map +1 -1
  6. package/dist/src/components/CallSignature.js +10 -12
  7. package/dist/src/components/CallSignature.js.map +1 -0
  8. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  9. package/dist/src/components/ClassDeclaration.js +8 -21
  10. package/dist/src/components/ClassDeclaration.js.map +1 -0
  11. package/dist/src/components/ClassInstantiation.d.ts.map +1 -1
  12. package/dist/src/components/ClassInstantiation.js +6 -5
  13. package/dist/src/components/ClassInstantiation.js.map +1 -0
  14. package/dist/src/components/Declaration.d.ts +1 -5
  15. package/dist/src/components/Declaration.d.ts.map +1 -1
  16. package/dist/src/components/Declaration.js +8 -16
  17. package/dist/src/components/Declaration.js.map +1 -0
  18. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  19. package/dist/src/components/EnumDeclaration.js +35 -60
  20. package/dist/src/components/EnumDeclaration.js.map +1 -0
  21. package/dist/src/components/EnumMember.d.ts.map +1 -1
  22. package/dist/src/components/EnumMember.js +5 -5
  23. package/dist/src/components/EnumMember.js.map +1 -0
  24. package/dist/src/components/FunctionCallExpression.js +2 -1
  25. package/dist/src/components/FunctionCallExpression.js.map +1 -0
  26. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  27. package/dist/src/components/FunctionDeclaration.js +8 -16
  28. package/dist/src/components/FunctionDeclaration.js.map +1 -0
  29. package/dist/src/components/ImportStatement.js +2 -1
  30. package/dist/src/components/ImportStatement.js.map +1 -0
  31. package/dist/src/components/LexicalScope.d.ts +8 -0
  32. package/dist/src/components/LexicalScope.d.ts.map +1 -0
  33. package/dist/src/components/LexicalScope.js +22 -0
  34. package/dist/src/components/LexicalScope.js.map +1 -0
  35. package/dist/src/components/MemberExpression.js +2 -1
  36. package/dist/src/components/MemberExpression.js.map +1 -0
  37. package/dist/src/components/MemberScope.d.ts +8 -0
  38. package/dist/src/components/MemberScope.d.ts.map +1 -0
  39. package/dist/src/components/MemberScope.js +16 -0
  40. package/dist/src/components/MemberScope.js.map +1 -0
  41. package/dist/src/components/NoNamePolicy.js +2 -1
  42. package/dist/src/components/NoNamePolicy.js.map +1 -0
  43. package/dist/src/components/PyDoc.js +2 -1
  44. package/dist/src/components/PyDoc.js.map +1 -0
  45. package/dist/src/components/PythonBlock.js +2 -1
  46. package/dist/src/components/PythonBlock.js.map +1 -0
  47. package/dist/src/components/Reference.js +2 -1
  48. package/dist/src/components/Reference.js.map +1 -0
  49. package/dist/src/components/SourceFile.js +3 -3
  50. package/dist/src/components/SourceFile.js.map +1 -0
  51. package/dist/src/components/StatementList.js +2 -1
  52. package/dist/src/components/StatementList.js.map +1 -0
  53. package/dist/src/components/UnionTypeExpression.js +2 -1
  54. package/dist/src/components/UnionTypeExpression.js.map +1 -0
  55. package/dist/src/components/VariableDeclaration.d.ts.map +1 -1
  56. package/dist/src/components/VariableDeclaration.js +10 -32
  57. package/dist/src/components/VariableDeclaration.js.map +1 -0
  58. package/dist/src/components/index.d.ts +2 -0
  59. package/dist/src/components/index.d.ts.map +1 -1
  60. package/dist/src/components/index.js +4 -1
  61. package/dist/src/components/index.js.map +1 -0
  62. package/dist/src/create-module.d.ts.map +1 -1
  63. package/dist/src/create-module.js +5 -5
  64. package/dist/src/create-module.js.map +1 -0
  65. package/dist/src/index.js +2 -1
  66. package/dist/src/index.js.map +1 -0
  67. package/dist/src/name-conflict-resolver.d.ts +3 -0
  68. package/dist/src/name-conflict-resolver.d.ts.map +1 -0
  69. package/dist/src/name-conflict-resolver.js +8 -0
  70. package/dist/src/name-conflict-resolver.js.map +1 -0
  71. package/dist/src/name-policy.js +2 -1
  72. package/dist/src/name-policy.js.map +1 -0
  73. package/dist/src/parameter-descriptor.js +2 -1
  74. package/dist/src/parameter-descriptor.js.map +1 -0
  75. package/dist/src/symbol-creation.d.ts +13 -2
  76. package/dist/src/symbol-creation.d.ts.map +1 -1
  77. package/dist/src/symbol-creation.js +35 -10
  78. package/dist/src/symbol-creation.js.map +1 -0
  79. package/dist/src/symbols/index.d.ts +1 -1
  80. package/dist/src/symbols/index.d.ts.map +1 -1
  81. package/dist/src/symbols/index.js +3 -2
  82. package/dist/src/symbols/index.js.map +1 -0
  83. package/dist/src/symbols/python-lexical-scope.d.ts +7 -0
  84. package/dist/src/symbols/python-lexical-scope.d.ts.map +1 -0
  85. package/dist/src/symbols/python-lexical-scope.js +15 -0
  86. package/dist/src/symbols/python-lexical-scope.js.map +1 -0
  87. package/dist/src/symbols/python-member-scope.d.ts +3 -4
  88. package/dist/src/symbols/python-member-scope.d.ts.map +1 -1
  89. package/dist/src/symbols/python-member-scope.js +6 -8
  90. package/dist/src/symbols/python-member-scope.js.map +1 -0
  91. package/dist/src/symbols/python-module-scope.d.ts +4 -9
  92. package/dist/src/symbols/python-module-scope.d.ts.map +1 -1
  93. package/dist/src/symbols/python-module-scope.js +8 -15
  94. package/dist/src/symbols/python-module-scope.js.map +1 -0
  95. package/dist/src/symbols/python-output-symbol.d.ts +10 -7
  96. package/dist/src/symbols/python-output-symbol.d.ts.map +1 -1
  97. package/dist/src/symbols/python-output-symbol.js +25 -7
  98. package/dist/src/symbols/python-output-symbol.js.map +1 -0
  99. package/dist/src/symbols/reference.d.ts +2 -2
  100. package/dist/src/symbols/reference.d.ts.map +1 -1
  101. package/dist/src/symbols/reference.js +37 -36
  102. package/dist/src/symbols/reference.js.map +1 -0
  103. package/dist/src/symbols/scopes.d.ts +3 -1
  104. package/dist/src/symbols/scopes.d.ts.map +1 -1
  105. package/dist/src/symbols/scopes.js +10 -1
  106. package/dist/src/symbols/scopes.js.map +1 -0
  107. package/dist/src/utils.js +2 -1
  108. package/dist/src/utils.js.map +1 -0
  109. package/dist/test/callsignatures.test.js +2 -1
  110. package/dist/test/callsignatures.test.js.map +1 -0
  111. package/dist/test/classdeclarations.test.js +89 -53
  112. package/dist/test/classdeclarations.test.js.map +1 -0
  113. package/dist/test/classinstantiations.test.js +2 -1
  114. package/dist/test/classinstantiations.test.js.map +1 -0
  115. package/dist/test/enums.test.js +10 -3
  116. package/dist/test/enums.test.js.map +1 -0
  117. package/dist/test/externals.test.js +8 -6
  118. package/dist/test/externals.test.js.map +1 -0
  119. package/dist/test/functioncallexpressions.test.js +2 -1
  120. package/dist/test/functioncallexpressions.test.js.map +1 -0
  121. package/dist/test/functiondeclaration.test.js +75 -37
  122. package/dist/test/functiondeclaration.test.js.map +1 -0
  123. package/dist/test/imports.test.js +11 -37
  124. package/dist/test/imports.test.js.map +1 -0
  125. package/dist/test/memberexpressions.test.js +2 -1
  126. package/dist/test/memberexpressions.test.js.map +1 -0
  127. package/dist/test/namepolicies.test.js +2 -1
  128. package/dist/test/namepolicies.test.js.map +1 -0
  129. package/dist/test/pydocs.test.js +2 -1
  130. package/dist/test/pydocs.test.js.map +1 -0
  131. package/dist/test/references.test.js +2 -1
  132. package/dist/test/references.test.js.map +1 -0
  133. package/dist/test/sourcefiles.test.js +2 -1
  134. package/dist/test/sourcefiles.test.js.map +1 -0
  135. package/dist/test/uniontypeexpression.test.js +2 -1
  136. package/dist/test/uniontypeexpression.test.js.map +1 -0
  137. package/dist/test/utils.d.ts +2 -3
  138. package/dist/test/utils.d.ts.map +1 -1
  139. package/dist/test/utils.js +8 -4
  140. package/dist/test/utils.js.map +1 -0
  141. package/dist/test/values.test.js +2 -1
  142. package/dist/test/values.test.js.map +1 -0
  143. package/dist/test/variables.test.js +13 -12
  144. package/dist/test/variables.test.js.map +1 -0
  145. package/dist/tsconfig.tsbuildinfo +1 -1
  146. package/package.json +3 -3
  147. package/src/components/CallSignature.tsx +9 -17
  148. package/src/components/ClassDeclaration.tsx +5 -32
  149. package/src/components/ClassInstantiation.tsx +6 -12
  150. package/src/components/Declaration.tsx +1 -20
  151. package/src/components/EnumDeclaration.tsx +18 -41
  152. package/src/components/EnumMember.tsx +1 -3
  153. package/src/components/FunctionDeclaration.tsx +5 -24
  154. package/src/components/LexicalScope.tsx +24 -0
  155. package/src/components/MemberScope.tsx +18 -0
  156. package/src/components/SourceFile.tsx +2 -2
  157. package/src/components/VariableDeclaration.tsx +7 -35
  158. package/src/components/index.ts +2 -0
  159. package/src/create-module.ts +7 -13
  160. package/src/name-conflict-resolver.ts +21 -0
  161. package/src/symbol-creation.ts +50 -11
  162. package/src/symbols/index.ts +1 -1
  163. package/src/symbols/python-lexical-scope.ts +16 -0
  164. package/src/symbols/python-member-scope.ts +4 -8
  165. package/src/symbols/python-module-scope.ts +6 -32
  166. package/src/symbols/python-output-symbol.ts +36 -10
  167. package/src/symbols/reference.tsx +70 -0
  168. package/src/symbols/scopes.ts +15 -1
  169. package/temp/api.json +897 -539
  170. package/test/classdeclarations.test.tsx +66 -31
  171. package/test/enums.test.tsx +2 -2
  172. package/test/externals.test.tsx +6 -7
  173. package/test/functiondeclaration.test.tsx +48 -39
  174. package/test/imports.test.tsx +11 -36
  175. package/test/utils.tsx +11 -5
  176. package/test/variables.test.tsx +11 -7
  177. package/dist/src/symbols/custom-output-scope.d.ts +0 -10
  178. package/dist/src/symbols/custom-output-scope.d.ts.map +0 -1
  179. package/dist/src/symbols/custom-output-scope.js +0 -25
  180. package/src/symbols/custom-output-scope.ts +0 -35
  181. package/src/symbols/reference.ts +0 -99
@@ -1,35 +0,0 @@
1
- import { OutputScope, OutputScopeOptions, SymbolTable } from "@alloy-js/core";
2
-
3
- // This is named as CustomOutputScope and not PythonOutputScope to avoid confusion with the one defined in scopes.ts
4
- // We are creating a custom output scope so we can add out custom name conflict resolution logic.
5
- export class CustomOutputScope extends OutputScope {
6
- #symbols: SymbolTable;
7
- /**
8
- * The symbols defined within this scope.
9
- */
10
- get symbols() {
11
- return this.#symbols;
12
- }
13
-
14
- constructor(name: string, options: OutputScopeOptions = {}) {
15
- super(name, options);
16
- this.#symbols = new SymbolTable(this, {
17
- nameConflictResolver: (_, symbols) => {
18
- for (let i = 1; i < symbols.length; i++) {
19
- // Rename all but the first symbol to have a suffix of _2, _3, plus the scope name if available.
20
- const symbol = symbols[i] as unknown as {
21
- originalName: string;
22
- name: string;
23
- module?: string;
24
- };
25
- symbol.name =
26
- symbol.originalName +
27
- "_" +
28
- (i + 1) +
29
- "_" +
30
- (symbols[i].aliasTarget?.scope?.name ?? symbol.module ?? "");
31
- }
32
- },
33
- });
34
- }
35
- }
@@ -1,99 +0,0 @@
1
- import {
2
- memo,
3
- OutputSymbolFlags,
4
- Refkey,
5
- resolve,
6
- untrack,
7
- useContext,
8
- useMemberScope,
9
- } from "@alloy-js/core";
10
- import { PythonSourceFileContext } from "../components/SourceFile.jsx";
11
- import {
12
- PythonMemberScope,
13
- PythonModuleScope,
14
- PythonOutputScope,
15
- PythonOutputSymbol,
16
- } from "./index.js";
17
-
18
- export function ref(
19
- refkey: Refkey,
20
- ): () => [string, PythonOutputSymbol | undefined] {
21
- const sourceFile = useContext(PythonSourceFileContext);
22
- const resolveResult = resolve<PythonOutputScope, PythonOutputSymbol>(
23
- refkey as Refkey,
24
- );
25
- const currentScope = useMemberScope();
26
-
27
- return memo(() => {
28
- if (resolveResult.value === undefined) {
29
- return ["<Unresolved Symbol>", undefined];
30
- }
31
-
32
- const { targetDeclaration, pathDown, memberPath } = resolveResult.value;
33
-
34
- // if we resolved a instance member, check if we should be able to access
35
- // it.
36
- if (targetDeclaration.flags & OutputSymbolFlags.InstanceMember) {
37
- if (currentScope?.instanceMembers !== targetDeclaration.scope) {
38
- throw new Error(
39
- "Cannot resolve member symbols from a different member scope",
40
- );
41
- }
42
- }
43
-
44
- // Where the target declaration is relative to the referencing scope.
45
- // * module: target symbol is in a different module
46
- // * local: target symbol is within the current module
47
- const targetLocation = pathDown[0]?.kind ?? "local";
48
- let localSymbol: PythonOutputSymbol | undefined;
49
-
50
- if (targetLocation === "module") {
51
- // Handling of targets in other modules, either created with createModule()
52
- // or from other files.
53
- const symbolPath = [
54
- ...(pathDown.slice(1) as PythonMemberScope[]).map((s) => s.owner),
55
- targetDeclaration,
56
- ];
57
-
58
- const importSymbol = symbolPath[0];
59
-
60
- localSymbol = untrack(() =>
61
- sourceFile!.scope.addImport(
62
- importSymbol,
63
- pathDown[0] as PythonModuleScope,
64
- ),
65
- );
66
- }
67
-
68
- if (memberPath && memberPath.length > 0) {
69
- if (localSymbol) {
70
- memberPath[0] = localSymbol;
71
- }
72
-
73
- return [buildMemberExpression(memberPath), memberPath.at(-1)];
74
- } else {
75
- return [
76
- buildMemberExpression([localSymbol ?? targetDeclaration]),
77
- localSymbol ?? targetDeclaration,
78
- ];
79
- }
80
- });
81
- }
82
-
83
- function buildMemberExpression(path: PythonOutputSymbol[]) {
84
- let memberExpr = "";
85
-
86
- const base: PythonOutputSymbol = path[0];
87
- if (base.flags & OutputSymbolFlags.InstanceMember) {
88
- memberExpr += "self";
89
- } else {
90
- memberExpr += base.name;
91
- path = path.slice(1);
92
- }
93
-
94
- for (const sym of path) {
95
- memberExpr += `.${sym.name}`;
96
- }
97
-
98
- return memberExpr;
99
- }