@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.
- package/dist/src/builtins/python.js +2 -1
- package/dist/src/builtins/python.js.map +1 -0
- package/dist/src/components/Atom.js +2 -1
- package/dist/src/components/Atom.js.map +1 -0
- package/dist/src/components/CallSignature.d.ts.map +1 -1
- package/dist/src/components/CallSignature.js +10 -12
- package/dist/src/components/CallSignature.js.map +1 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +8 -21
- package/dist/src/components/ClassDeclaration.js.map +1 -0
- package/dist/src/components/ClassInstantiation.d.ts.map +1 -1
- package/dist/src/components/ClassInstantiation.js +6 -5
- package/dist/src/components/ClassInstantiation.js.map +1 -0
- 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 +8 -16
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +35 -60
- package/dist/src/components/EnumDeclaration.js.map +1 -0
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +5 -5
- package/dist/src/components/EnumMember.js.map +1 -0
- package/dist/src/components/FunctionCallExpression.js +2 -1
- package/dist/src/components/FunctionCallExpression.js.map +1 -0
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +8 -16
- package/dist/src/components/FunctionDeclaration.js.map +1 -0
- package/dist/src/components/ImportStatement.js +2 -1
- package/dist/src/components/ImportStatement.js.map +1 -0
- 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 +22 -0
- package/dist/src/components/LexicalScope.js.map +1 -0
- package/dist/src/components/MemberExpression.js +2 -1
- package/dist/src/components/MemberExpression.js.map +1 -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 +16 -0
- package/dist/src/components/MemberScope.js.map +1 -0
- package/dist/src/components/NoNamePolicy.js +2 -1
- package/dist/src/components/NoNamePolicy.js.map +1 -0
- package/dist/src/components/PyDoc.js +2 -1
- package/dist/src/components/PyDoc.js.map +1 -0
- package/dist/src/components/PythonBlock.js +2 -1
- package/dist/src/components/PythonBlock.js.map +1 -0
- package/dist/src/components/Reference.js +2 -1
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SourceFile.js +3 -3
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/StatementList.js +2 -1
- package/dist/src/components/StatementList.js.map +1 -0
- package/dist/src/components/UnionTypeExpression.js +2 -1
- package/dist/src/components/UnionTypeExpression.js.map +1 -0
- package/dist/src/components/VariableDeclaration.d.ts.map +1 -1
- package/dist/src/components/VariableDeclaration.js +10 -32
- package/dist/src/components/VariableDeclaration.js.map +1 -0
- 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 +4 -1
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/create-module.d.ts.map +1 -1
- package/dist/src/create-module.js +5 -5
- package/dist/src/create-module.js.map +1 -0
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -0
- 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 +8 -0
- package/dist/src/name-conflict-resolver.js.map +1 -0
- package/dist/src/name-policy.js +2 -1
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/parameter-descriptor.js +2 -1
- package/dist/src/parameter-descriptor.js.map +1 -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 +35 -10
- package/dist/src/symbol-creation.js.map +1 -0
- 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 +3 -2
- package/dist/src/symbols/index.js.map +1 -0
- 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 +15 -0
- package/dist/src/symbols/python-lexical-scope.js.map +1 -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 +6 -8
- package/dist/src/symbols/python-member-scope.js.map +1 -0
- 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 +8 -15
- package/dist/src/symbols/python-module-scope.js.map +1 -0
- 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 +25 -7
- package/dist/src/symbols/python-output-symbol.js.map +1 -0
- 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 +37 -36
- package/dist/src/symbols/reference.js.map +1 -0
- 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 +10 -1
- package/dist/src/symbols/scopes.js.map +1 -0
- package/dist/src/utils.js +2 -1
- package/dist/src/utils.js.map +1 -0
- package/dist/test/callsignatures.test.js +2 -1
- package/dist/test/callsignatures.test.js.map +1 -0
- package/dist/test/classdeclarations.test.js +89 -53
- package/dist/test/classdeclarations.test.js.map +1 -0
- package/dist/test/classinstantiations.test.js +2 -1
- package/dist/test/classinstantiations.test.js.map +1 -0
- package/dist/test/enums.test.js +10 -3
- package/dist/test/enums.test.js.map +1 -0
- package/dist/test/externals.test.js +8 -6
- package/dist/test/externals.test.js.map +1 -0
- package/dist/test/functioncallexpressions.test.js +2 -1
- package/dist/test/functioncallexpressions.test.js.map +1 -0
- package/dist/test/functiondeclaration.test.js +75 -37
- package/dist/test/functiondeclaration.test.js.map +1 -0
- package/dist/test/imports.test.js +11 -37
- package/dist/test/imports.test.js.map +1 -0
- package/dist/test/memberexpressions.test.js +2 -1
- package/dist/test/memberexpressions.test.js.map +1 -0
- package/dist/test/namepolicies.test.js +2 -1
- package/dist/test/namepolicies.test.js.map +1 -0
- package/dist/test/pydocs.test.js +2 -1
- package/dist/test/pydocs.test.js.map +1 -0
- package/dist/test/references.test.js +2 -1
- package/dist/test/references.test.js.map +1 -0
- package/dist/test/sourcefiles.test.js +2 -1
- package/dist/test/sourcefiles.test.js.map +1 -0
- package/dist/test/uniontypeexpression.test.js +2 -1
- package/dist/test/uniontypeexpression.test.js.map +1 -0
- package/dist/test/utils.d.ts +2 -3
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +8 -4
- package/dist/test/utils.js.map +1 -0
- package/dist/test/values.test.js +2 -1
- package/dist/test/values.test.js.map +1 -0
- package/dist/test/variables.test.js +13 -12
- package/dist/test/variables.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- 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 +5 -24
- package/src/components/LexicalScope.tsx +24 -0
- package/src/components/MemberScope.tsx +18 -0
- 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 +897 -539
- 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 +11 -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
|
-
}
|