@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":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC"}
|
|
@@ -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.js";
|
|
12
14
|
export * from "./NoNamePolicy.js";
|
|
13
15
|
export * from "./PyDoc.js";
|
|
14
16
|
export * from "./PythonBlock.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-module.d.ts","sourceRoot":"","sources":["../../src/create-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EAEX,aAAa,EACd,MAAM,gBAAgB,CAAC;AAIxB,MAAM,WAAW,gBAAgB;IAC/B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,gBAAgB;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,CAAC,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,CAAC,WAAW,SAAS,SAAS,MAAM,EAAE,IAAI;KAC3D,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM;CACnC,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI;KAC9D,CAAC,IAAI,MAAM,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACjC,CAAC;
|
|
1
|
+
{"version":3,"file":"create-module.d.ts","sourceRoot":"","sources":["../../src/create-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EAEX,aAAa,EACd,MAAM,gBAAgB,CAAC;AAIxB,MAAM,WAAW,gBAAgB;IAC/B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,gBAAgB;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,CAAC,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,CAAC,WAAW,SAAS,SAAS,MAAM,EAAE,IAAI;KAC3D,CAAC,IAAI,WAAW,CAAC,MAAM,CAAC,GAAG,MAAM;CACnC,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI;KAC9D,CAAC,IAAI,MAAM,EAAE,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;CACjC,CAAC;AAqDF,wBAAgB,YAAY,CAAC,KAAK,CAAC,CAAC,SAAS,gBAAgB,EAC3D,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC1B,aAAa,CAAC,CAAC,CAAC,GAAG,aAAa,CAelC"}
|
|
@@ -8,8 +8,7 @@ function createSymbols(binder, props, refkeys) {
|
|
|
8
8
|
// Otherwise, we append the path to the module name
|
|
9
9
|
const fullModuleScopeName = props.name + (path === "." ? "" : `.${path}`);
|
|
10
10
|
const keys = refkeys[path];
|
|
11
|
-
const moduleScope = new PythonModuleScope(fullModuleScopeName, {
|
|
12
|
-
parent: undefined,
|
|
11
|
+
const moduleScope = new PythonModuleScope(fullModuleScopeName, undefined, {
|
|
13
12
|
binder: binder
|
|
14
13
|
});
|
|
15
14
|
|
|
@@ -17,11 +16,11 @@ function createSymbols(binder, props, refkeys) {
|
|
|
17
16
|
for (const exportedName of symbols ?? []) {
|
|
18
17
|
const key = keys[exportedName];
|
|
19
18
|
const _ = createPythonSymbol(exportedName, {
|
|
19
|
+
space: moduleScope.symbols,
|
|
20
20
|
binder: binder,
|
|
21
|
-
scope: moduleScope,
|
|
22
21
|
refkeys: key,
|
|
23
22
|
module: moduleScope.name
|
|
24
|
-
}
|
|
23
|
+
});
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"name-conflict-resolver.d.ts","sourceRoot":"","sources":["../../src/name-conflict-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,wBAAgB,0BAA0B,CACxC,CAAC,EAAE,MAAM,EACT,OAAO,EAAE,kBAAkB,EAAE,QAgB9B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function pythonNameConflictResolver(_, symbols) {
|
|
2
|
+
for (let i = 1; i < symbols.length; i++) {
|
|
3
|
+
// Rename all but the first symbol to have a suffix of _2, _3, plus the scope name if available.
|
|
4
|
+
const symbol = symbols[i];
|
|
5
|
+
symbol.name = symbol.originalName + "_" + (i + 1) + "_" + (symbols[i].aliasTarget?.scope?.name ?? symbol.module ?? "");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
import { OutputScopeOptions, OutputSpace } from "@alloy-js/core";
|
|
1
2
|
import { PythonElements } from "./name-policy.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
3
|
+
import { PythonOutputSymbol, PythonOutputSymbolOptions } from "./symbols/index.js";
|
|
4
|
+
import { PythonLexicalScope } from "./symbols/python-lexical-scope.js";
|
|
5
|
+
interface CreatePythonSymbolOptions extends PythonOutputSymbolOptions {
|
|
6
|
+
space?: OutputSpace;
|
|
7
|
+
instance?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a symbol for a python declaration in the current scope.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createPythonSymbol(name: string, options?: CreatePythonSymbolOptions, kind?: PythonElements): PythonOutputSymbol;
|
|
13
|
+
export declare function createLexicalScope(name: string, options?: OutputScopeOptions): PythonLexicalScope;
|
|
14
|
+
export {};
|
|
4
15
|
//# sourceMappingURL=symbol-creation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"symbol-creation.d.ts","sourceRoot":"","sources":["../../src/symbol-creation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"symbol-creation.d.ts","sourceRoot":"","sources":["../../src/symbol-creation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,WAAW,EAGZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AACvE,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EAE1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAEvE,UAAU,yBAA0B,SAAQ,yBAAyB;IACnE,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AACD;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,yBAA8B,EACvC,IAAI,CAAC,EAAE,cAAc,GACpB,kBAAkB,CAuCpB;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,kBAAuB,sBAKjC"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useBinder, useContext } from "@alloy-js/core";
|
|
2
2
|
import { PythonSourceFileContext } from "./components/SourceFile.js";
|
|
3
3
|
import { usePythonNamePolicy } from "./name-policy.js";
|
|
4
|
-
import { PythonOutputSymbol } from "./symbols/index.js";
|
|
5
|
-
|
|
4
|
+
import { PythonOutputSymbol, usePythonScope } from "./symbols/index.js";
|
|
5
|
+
import { PythonLexicalScope } from "./symbols/python-lexical-scope.js";
|
|
6
|
+
/**
|
|
7
|
+
* Creates a symbol for a python declaration in the current scope.
|
|
8
|
+
*/
|
|
9
|
+
export function createPythonSymbol(name, options = {}, kind) {
|
|
6
10
|
let processedName = name;
|
|
7
11
|
const sfContext = useContext(PythonSourceFileContext);
|
|
8
12
|
// Only apply the name policy if a kind is provided and name policy context is available
|
|
@@ -12,13 +16,33 @@ export function createPythonSymbol(name, options, kind, createRefkeyIfNeeded = f
|
|
|
12
16
|
processedName = namePolicy.getName(name, kind);
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
const currentScope = usePythonScope();
|
|
20
|
+
let targetSpace = options.space ?? undefined;
|
|
21
|
+
if (!options.space && currentScope) {
|
|
22
|
+
if (currentScope.isMemberScope) {
|
|
23
|
+
if (options.instance) {
|
|
24
|
+
targetSpace = currentScope.ownerSymbol.instanceMembers;
|
|
25
|
+
} else {
|
|
26
|
+
targetSpace = currentScope.ownerSymbol.staticMembers;
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
if (options.instance) {
|
|
30
|
+
throw new Error(`Cannot declare instance variable ${name} outside of a member scope`);
|
|
31
|
+
}
|
|
32
|
+
targetSpace = currentScope.symbols;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const binder = options.binder ?? currentScope?.binder ?? useBinder();
|
|
36
|
+
return new PythonOutputSymbol(processedName, targetSpace, {
|
|
37
|
+
binder: binder,
|
|
17
38
|
aliasTarget: options.aliasTarget,
|
|
18
|
-
|
|
19
|
-
refkeys: options.refkeys ?? (createRefkeyIfNeeded ? refkey(processedName) : undefined),
|
|
20
|
-
flags: options.flags,
|
|
39
|
+
refkeys: options.refkeys,
|
|
21
40
|
metadata: options.metadata,
|
|
22
|
-
module: sfContext?.module
|
|
41
|
+
module: sfContext?.module,
|
|
42
|
+
type: options.type
|
|
23
43
|
});
|
|
44
|
+
}
|
|
45
|
+
export function createLexicalScope(name, options = {}) {
|
|
46
|
+
const parent = usePythonScope();
|
|
47
|
+
return new PythonLexicalScope(name, parent, options);
|
|
24
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/symbols/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/symbols/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OutputScope } from "@alloy-js/core";
|
|
2
|
+
export declare class PythonLexicalScope extends OutputScope {
|
|
3
|
+
static readonly declarationSpaces: readonly string[];
|
|
4
|
+
get symbols(): import("@alloy-js/core").OutputSpace;
|
|
5
|
+
get ownerSymbol(): undefined;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=python-lexical-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"python-lexical-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/python-lexical-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,qBAAa,kBAAmB,SAAQ,WAAW;IACjD,gBAAuB,iBAAiB,EAAE,SAAS,MAAM,EAAE,CAAe;IAE1E,IAAI,OAAO,yCAEV;IAKD,IAAI,WAAW,IAAI,SAAS,CAE3B;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OutputScope } from "@alloy-js/core";
|
|
2
|
+
export class PythonLexicalScope extends OutputScope {
|
|
3
|
+
static declarationSpaces = ["symbols"];
|
|
4
|
+
get symbols() {
|
|
5
|
+
return this.spaceFor("symbols");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Lexical scopes do not have an owner symbol. This ensures that we get the
|
|
9
|
+
// correct type when using `usePythonScope` (i.e. we don't get the
|
|
10
|
+
// OutputScope's `OutputSymbol | undefined` type).
|
|
11
|
+
get ownerSymbol() {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OutputScope } from "@alloy-js/core";
|
|
2
2
|
import { PythonOutputSymbol } from "./python-output-symbol.js";
|
|
3
|
-
export declare class PythonMemberScope extends
|
|
4
|
-
get
|
|
5
|
-
get owner(): PythonOutputSymbol;
|
|
3
|
+
export declare class PythonMemberScope extends OutputScope {
|
|
4
|
+
get ownerSymbol(): PythonOutputSymbol;
|
|
6
5
|
}
|
|
7
6
|
//# sourceMappingURL=python-member-scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python-member-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/python-member-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"python-member-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/python-member-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,qBAAa,iBAAkB,SAAQ,WAAW;IAChD,IAAI,WAAW,IACe,kBAAkB,CAC/C;CACF"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export class PythonMemberScope extends
|
|
3
|
-
get
|
|
4
|
-
return
|
|
5
|
-
}
|
|
6
|
-
get owner() {
|
|
7
|
-
return super.owner;
|
|
1
|
+
import { OutputScope } from "@alloy-js/core";
|
|
2
|
+
export class PythonMemberScope extends OutputScope {
|
|
3
|
+
get ownerSymbol() {
|
|
4
|
+
return super.ownerSymbol;
|
|
8
5
|
}
|
|
9
6
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PythonLexicalScope } from "./python-lexical-scope.js";
|
|
2
2
|
import { PythonOutputSymbol } from "./python-output-symbol.js";
|
|
3
3
|
export declare class ImportedSymbol {
|
|
4
4
|
local: PythonOutputSymbol;
|
|
@@ -9,15 +9,10 @@ export declare class ImportedSymbol {
|
|
|
9
9
|
export interface ImportRecordProps {
|
|
10
10
|
symbols: Set<ImportedSymbol>;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
new (entries?: readonly (readonly [PythonModuleScope, ImportRecordProps])[] | null): ImportRecords;
|
|
16
|
-
prototype: Map<PythonModuleScope, ImportRecordProps>;
|
|
17
|
-
};
|
|
18
|
-
export declare class PythonModuleScope extends CustomOutputScope {
|
|
12
|
+
export declare class ImportRecords extends Map<PythonModuleScope, ImportRecordProps> {
|
|
13
|
+
}
|
|
14
|
+
export declare class PythonModuleScope extends PythonLexicalScope {
|
|
19
15
|
#private;
|
|
20
|
-
get kind(): "module";
|
|
21
16
|
get importedSymbols(): Map<PythonOutputSymbol, PythonOutputSymbol>;
|
|
22
17
|
get importedModules(): ImportRecords;
|
|
23
18
|
addImport(targetSymbol: PythonOutputSymbol, targetModule: PythonModuleScope): PythonOutputSymbol;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python-module-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/python-module-scope.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"python-module-scope.d.ts","sourceRoot":"","sources":["../../../src/symbols/python-module-scope.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,qBAAa,cAAc;IACzB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,MAAM,EAAE,kBAAkB,CAAC;gBAEf,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,kBAAkB;IAKjE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,kBAAkB;CAGlE;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC9B;AAED,qBAAa,aAAc,SAAQ,GAAG,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;CAAG;AAE/E,qBAAa,iBAAkB,SAAQ,kBAAkB;;IAGvD,IAAI,eAAe,gDAElB;IAGD,IAAI,eAAe,kBAElB;IAED,SAAS,CAAC,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,iBAAiB;CA0B5E"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { reactive, shallowReactive } from "@alloy-js/core";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { PythonLexicalScope } from "./python-lexical-scope.js";
|
|
3
|
+
import { PythonOutputSymbol } from "./python-output-symbol.js";
|
|
4
4
|
export class ImportedSymbol {
|
|
5
5
|
constructor(target, local) {
|
|
6
6
|
this.target = target;
|
|
@@ -10,11 +10,8 @@ export class ImportedSymbol {
|
|
|
10
10
|
return new ImportedSymbol(target, local);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
export
|
|
14
|
-
export class PythonModuleScope extends
|
|
15
|
-
get kind() {
|
|
16
|
-
return "module";
|
|
17
|
-
}
|
|
13
|
+
export class ImportRecords extends Map {}
|
|
14
|
+
export class PythonModuleScope extends PythonLexicalScope {
|
|
18
15
|
#importedSymbols = shallowReactive(new Map());
|
|
19
16
|
get importedSymbols() {
|
|
20
17
|
return this.#importedSymbols;
|
|
@@ -28,20 +25,15 @@ export class PythonModuleScope extends CustomOutputScope {
|
|
|
28
25
|
if (existing) {
|
|
29
26
|
return existing;
|
|
30
27
|
}
|
|
31
|
-
if (targetModule.kind !== "module") {
|
|
32
|
-
throw new Error("Cannot import symbol that isn't in module scope");
|
|
33
|
-
}
|
|
34
28
|
if (!this.importedModules.has(targetModule)) {
|
|
35
29
|
this.importedModules.set(targetModule, {
|
|
36
30
|
symbols: new Set()
|
|
37
31
|
});
|
|
38
32
|
}
|
|
39
|
-
const localSymbol =
|
|
33
|
+
const localSymbol = new PythonOutputSymbol(targetSymbol.name, this.symbols, {
|
|
40
34
|
binder: this.binder,
|
|
41
|
-
scope: this,
|
|
42
35
|
aliasTarget: targetSymbol
|
|
43
|
-
}
|
|
44
|
-
targetSymbol.copyTo(localSymbol);
|
|
36
|
+
});
|
|
45
37
|
this.importedSymbols.set(targetSymbol, localSymbol);
|
|
46
38
|
this.importedModules.get(targetModule).symbols?.add({
|
|
47
39
|
local: localSymbol,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { OutputSymbol, OutputSymbolOptions } from "@alloy-js/core";
|
|
2
|
-
|
|
3
|
-
export interface CreatePythonSymbolOptions extends OutputSymbolOptions {
|
|
1
|
+
import { OutputSpace, OutputSymbol, OutputSymbolOptions } from "@alloy-js/core";
|
|
2
|
+
export interface PythonOutputSymbolOptions extends OutputSymbolOptions {
|
|
4
3
|
module?: string;
|
|
5
4
|
}
|
|
6
|
-
export interface CreatePythonSymbolFunctionOptions extends
|
|
5
|
+
export interface CreatePythonSymbolFunctionOptions extends PythonOutputSymbolOptions {
|
|
7
6
|
name: string;
|
|
8
7
|
}
|
|
9
8
|
/**
|
|
@@ -11,9 +10,13 @@ export interface CreatePythonSymbolFunctionOptions extends CreatePythonSymbolOpt
|
|
|
11
10
|
*/
|
|
12
11
|
export declare class PythonOutputSymbol extends OutputSymbol {
|
|
13
12
|
#private;
|
|
14
|
-
|
|
13
|
+
static readonly memberSpaces: readonly ["static", "instance"];
|
|
14
|
+
constructor(name: string, spaces: OutputSpace[] | OutputSpace | undefined, options: PythonOutputSymbolOptions);
|
|
15
15
|
get module(): string | undefined;
|
|
16
|
-
|
|
17
|
-
get
|
|
16
|
+
get staticMembers(): import("@alloy-js/core").OutputMemberSpace;
|
|
17
|
+
get instanceMembers(): import("@alloy-js/core").OutputMemberSpace;
|
|
18
|
+
get isStaticMemberSymbol(): boolean;
|
|
19
|
+
get isInstanceMemberSymbol(): boolean;
|
|
20
|
+
copy(): PythonOutputSymbol;
|
|
18
21
|
}
|
|
19
22
|
//# sourceMappingURL=python-output-symbol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/python-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"python-output-symbol.d.ts","sourceRoot":"","sources":["../../../src/symbols/python-output-symbol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iCACf,SAAQ,yBAAyB;IACjC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;;IAClD,MAAM,CAAC,QAAQ,CAAC,YAAY,kCAAmC;gBAG7D,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,EAAE,GAAG,WAAW,GAAG,SAAS,EAC/C,OAAO,EAAE,yBAAyB;IASpC,IAAI,MAAM,uBAET;IAED,IAAI,aAAa,+CAEhB;IAED,IAAI,eAAe,+CAElB;IAED,IAAI,oBAAoB,YAEvB;IAED,IAAI,sBAAsB,YAEzB;IAED,IAAI;CAYL"}
|
|
@@ -3,8 +3,9 @@ import { OutputSymbol } from "@alloy-js/core";
|
|
|
3
3
|
* Represents an 'exported' symbol from a .py file. Class, enum, interface etc.
|
|
4
4
|
*/
|
|
5
5
|
export class PythonOutputSymbol extends OutputSymbol {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
static memberSpaces = ["static", "instance"];
|
|
7
|
+
constructor(name, spaces, options) {
|
|
8
|
+
super(name, spaces, options);
|
|
8
9
|
this.#module = options.module ?? undefined;
|
|
9
10
|
}
|
|
10
11
|
|
|
@@ -13,10 +14,26 @@ export class PythonOutputSymbol extends OutputSymbol {
|
|
|
13
14
|
get module() {
|
|
14
15
|
return this.#module;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
this
|
|
17
|
+
get staticMembers() {
|
|
18
|
+
return this.memberSpaceFor("static");
|
|
18
19
|
}
|
|
19
|
-
get
|
|
20
|
-
return
|
|
20
|
+
get instanceMembers() {
|
|
21
|
+
return this.memberSpaceFor("instance");
|
|
22
|
+
}
|
|
23
|
+
get isStaticMemberSymbol() {
|
|
24
|
+
return !this.isInstanceMemberSymbol;
|
|
25
|
+
}
|
|
26
|
+
get isInstanceMemberSymbol() {
|
|
27
|
+
return this.spaces.some(s => s.key === "instance");
|
|
28
|
+
}
|
|
29
|
+
copy() {
|
|
30
|
+
const copy = new PythonOutputSymbol(this.name, undefined, {
|
|
31
|
+
binder: this.binder,
|
|
32
|
+
aliasTarget: this.aliasTarget,
|
|
33
|
+
module: this.module,
|
|
34
|
+
metadata: this.metadata
|
|
35
|
+
});
|
|
36
|
+
this.initializeCopy(copy);
|
|
37
|
+
return copy;
|
|
21
38
|
}
|
|
22
39
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Refkey } from "@alloy-js/core";
|
|
1
|
+
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
import { PythonOutputSymbol } from "./index.js";
|
|
3
|
-
export declare function ref(refkey: Refkey): () => [
|
|
3
|
+
export declare function ref(refkey: Refkey): () => [Children, PythonOutputSymbol | undefined];
|
|
4
4
|
//# sourceMappingURL=reference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.
|
|
1
|
+
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,MAAM,EAIP,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAGL,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,GAAG,CACjB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,QAAQ,EAAE,kBAAkB,GAAG,SAAS,CAAC,CAmDlD"}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { memo, resolve, untrack, useContext } from "@alloy-js/core";
|
|
3
|
+
import { MemberExpression } from "../components/MemberExpression.js";
|
|
2
4
|
import { PythonSourceFileContext } from "../components/SourceFile.js";
|
|
5
|
+
import { PythonModuleScope } from "./index.js";
|
|
3
6
|
export function ref(refkey) {
|
|
4
7
|
const sourceFile = useContext(PythonSourceFileContext);
|
|
5
8
|
const resolveResult = resolve(refkey);
|
|
6
|
-
const currentScope = useMemberScope();
|
|
7
9
|
return memo(() => {
|
|
8
10
|
if (resolveResult.value === undefined) {
|
|
9
11
|
return ["<Unresolved Symbol>", undefined];
|
|
10
12
|
}
|
|
11
13
|
const {
|
|
12
|
-
|
|
14
|
+
commonScope,
|
|
15
|
+
lexicalDeclaration,
|
|
16
|
+
symbol,
|
|
13
17
|
pathDown,
|
|
14
18
|
memberPath
|
|
15
19
|
} = resolveResult.value;
|
|
16
20
|
|
|
17
|
-
// if we resolved a instance member, check if we should be able to access
|
|
18
|
-
// it.
|
|
19
|
-
if (targetDeclaration.flags & OutputSymbolFlags.InstanceMember) {
|
|
20
|
-
if (currentScope?.instanceMembers !== targetDeclaration.scope) {
|
|
21
|
-
throw new Error("Cannot resolve member symbols from a different member scope");
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
21
|
// Where the target declaration is relative to the referencing scope.
|
|
26
22
|
// * module: target symbol is in a different module
|
|
27
23
|
// * local: target symbol is within the current module
|
|
28
|
-
const targetLocation = pathDown[0]
|
|
24
|
+
const targetLocation = pathDown[0] instanceof PythonModuleScope ? "module" : "local";
|
|
29
25
|
let localSymbol;
|
|
30
26
|
if (targetLocation === "module") {
|
|
31
|
-
|
|
32
|
-
// or from other files.
|
|
33
|
-
const symbolPath = [...pathDown.slice(1).map(s => s.owner), targetDeclaration];
|
|
34
|
-
const importSymbol = symbolPath[0];
|
|
35
|
-
localSymbol = untrack(() => sourceFile.scope.addImport(importSymbol, pathDown[0]));
|
|
27
|
+
localSymbol = untrack(() => sourceFile.scope.addImport(lexicalDeclaration, pathDown[0]));
|
|
36
28
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
const parts = [];
|
|
30
|
+
if (commonScope && commonScope.isMemberScope) {
|
|
31
|
+
// we are referencing a member of a type we are inside
|
|
32
|
+
if (lexicalDeclaration.isInstanceMemberSymbol) {
|
|
33
|
+
parts.push(_$createComponent(MemberExpression.Part, {
|
|
34
|
+
id: "self"
|
|
35
|
+
}));
|
|
36
|
+
} else {
|
|
37
|
+
parts.push(_$createComponent(MemberExpression.Part, {
|
|
38
|
+
get symbol() {
|
|
39
|
+
return commonScope.ownerSymbol;
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
parts.push(_$createComponent(MemberExpression.Part, {
|
|
44
|
+
symbol: lexicalDeclaration
|
|
45
|
+
}));
|
|
42
46
|
} else {
|
|
43
|
-
|
|
47
|
+
parts.push(_$createComponent(MemberExpression.Part, {
|
|
48
|
+
symbol: localSymbol ?? lexicalDeclaration
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
for (const part of memberPath) {
|
|
52
|
+
parts.push(_$createComponent(MemberExpression.Part, {
|
|
53
|
+
symbol: part
|
|
54
|
+
}));
|
|
44
55
|
}
|
|
56
|
+
return [_$createComponent(MemberExpression, {
|
|
57
|
+
children: parts
|
|
58
|
+
}), localSymbol ?? symbol];
|
|
45
59
|
});
|
|
46
|
-
}
|
|
47
|
-
function buildMemberExpression(path) {
|
|
48
|
-
let memberExpr = "";
|
|
49
|
-
const base = path[0];
|
|
50
|
-
if (base.flags & OutputSymbolFlags.InstanceMember) {
|
|
51
|
-
memberExpr += "self";
|
|
52
|
-
} else {
|
|
53
|
-
memberExpr += base.name;
|
|
54
|
-
path = path.slice(1);
|
|
55
|
-
}
|
|
56
|
-
for (const sym of path) {
|
|
57
|
-
memberExpr += `.${sym.name}`;
|
|
58
|
-
}
|
|
59
|
-
return memberExpr;
|
|
60
60
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { PythonLexicalScope } from "./python-lexical-scope.js";
|
|
1
2
|
import { PythonMemberScope } from "./python-member-scope.js";
|
|
2
3
|
import { PythonModuleScope } from "./python-module-scope.js";
|
|
3
|
-
export type PythonOutputScope = PythonModuleScope | PythonMemberScope;
|
|
4
|
+
export type PythonOutputScope = PythonLexicalScope | PythonModuleScope | PythonMemberScope;
|
|
4
5
|
export declare function usePythonScope(): PythonOutputScope;
|
|
6
|
+
export declare function usePythonLexicalScope(): PythonLexicalScope | PythonModuleScope;
|
|
5
7
|
//# sourceMappingURL=scopes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,MAAM,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"scopes.d.ts","sourceRoot":"","sources":["../../../src/symbols/scopes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,MAAM,MAAM,iBAAiB,GACzB,kBAAkB,GAClB,iBAAiB,GACjB,iBAAiB,CAAC;AAEtB,wBAAgB,cAAc,IACP,iBAAiB,CACvC;AAED,wBAAgB,qBAAqB,2CAQpC"}
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { useScope } from "@alloy-js/core";
|
|
2
|
+
import { PythonLexicalScope } from "./python-lexical-scope.js";
|
|
2
3
|
export function usePythonScope() {
|
|
3
4
|
return useScope();
|
|
5
|
+
}
|
|
6
|
+
export function usePythonLexicalScope() {
|
|
7
|
+
const scope = usePythonScope();
|
|
8
|
+
if (!(scope instanceof PythonLexicalScope)) {
|
|
9
|
+
throw new Error("Expected a PythonLexicalScope, but got " + scope.constructor.name);
|
|
10
|
+
}
|
|
11
|
+
return scope;
|
|
4
12
|
}
|