@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,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
|
-
}
|
package/src/symbols/reference.ts
DELETED
|
@@ -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
|
-
}
|