@alloy-js/typescript 0.20.0-dev.0 → 0.20.0-dev.1
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/node.d.ts +1 -1
- package/dist/src/components/ArrowFunction.d.ts.map +1 -1
- package/dist/src/components/ArrowFunction.js +7 -13
- package/dist/src/components/BlockScope.d.ts.map +1 -1
- package/dist/src/components/BlockScope.js +3 -2
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +20 -30
- package/dist/src/components/Declaration.d.ts +2 -9
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +20 -43
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +5 -9
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +3 -4
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/ExportStatement.js +2 -1
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +15 -12
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +3 -3
- package/dist/src/components/FunctionExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionExpression.js +7 -13
- package/dist/src/components/FunctionType.d.ts.map +1 -1
- package/dist/src/components/FunctionType.js +3 -3
- package/dist/src/components/IfStatement.d.ts.map +1 -1
- package/dist/src/components/IfStatement.js +2 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +3 -4
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +14 -13
- package/dist/src/components/InterfaceMethod.d.ts.map +1 -1
- package/dist/src/components/InterfaceMethod.js +4 -3
- package/dist/src/components/LexicalScope.d.ts +12 -0
- package/dist/src/components/LexicalScope.d.ts.map +1 -0
- package/dist/src/components/LexicalScope.js +24 -0
- package/dist/src/components/MemberDeclaration.d.ts +1 -10
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +3 -7
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +13 -5
- package/dist/src/components/MemberScope.d.ts +15 -0
- package/dist/src/components/MemberScope.d.ts.map +1 -0
- package/dist/src/components/MemberScope.js +17 -0
- package/dist/src/components/NewExpression.d.ts.map +1 -1
- package/dist/src/components/NewExpression.js +5 -5
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +10 -14
- package/dist/src/components/PropertyName.js +1 -2
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +3 -2
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +14 -26
- package/dist/src/context/index.d.ts +1 -1
- package/dist/src/context/index.d.ts.map +1 -1
- package/dist/src/context/index.js +1 -1
- package/dist/src/create-package.d.ts.map +1 -1
- package/dist/src/create-package.js +11 -33
- package/dist/src/symbols/index.d.ts +19 -0
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +72 -1
- 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 +68 -70
- package/dist/src/symbols/scopes.d.ts +5 -8
- package/dist/src/symbols/scopes.d.ts.map +1 -1
- package/dist/src/symbols/scopes.js +26 -0
- package/dist/src/symbols/ts-lexical-scope.d.ts +12 -0
- package/dist/src/symbols/ts-lexical-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-lexical-scope.js +16 -0
- package/dist/src/symbols/ts-member-scope.d.ts +12 -4
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-member-scope.js +15 -6
- package/dist/src/symbols/ts-module-scope.d.ts +8 -3
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +29 -18
- package/dist/src/symbols/ts-output-symbol.d.ts +19 -18
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +60 -37
- package/dist/src/symbols/ts-package-scope.d.ts +1 -1
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +4 -5
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +23 -1
- package/dist/test/class.test.js +4 -4
- package/dist/test/externals.test.js +2 -38
- package/dist/test/reference.test.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/ArrowFunction.tsx +7 -10
- package/src/components/BlockScope.tsx +3 -3
- package/src/components/ClassDeclaration.tsx +19 -44
- package/src/components/Declaration.tsx +22 -53
- package/src/components/EnumDeclaration.tsx +4 -11
- package/src/components/EnumMember.tsx +3 -3
- package/src/components/ExportStatement.tsx +2 -1
- package/src/components/FunctionBase.tsx +33 -28
- package/src/components/FunctionDeclaration.tsx +3 -3
- package/src/components/FunctionExpression.tsx +7 -10
- package/src/components/FunctionType.tsx +3 -3
- package/src/components/IfStatement.tsx +2 -1
- package/src/components/ImportStatement.tsx +4 -8
- package/src/components/Interface.tsx +15 -22
- package/src/components/InterfaceMethod.tsx +4 -4
- package/src/components/LexicalScope.tsx +27 -0
- package/src/components/MemberDeclaration.tsx +8 -20
- package/src/components/MemberExpression.tsx +25 -5
- package/src/components/MemberScope.tsx +29 -0
- package/src/components/NewExpression.tsx +4 -5
- package/src/components/ObjectExpression.tsx +11 -18
- package/src/components/PropertyName.tsx +2 -2
- package/src/components/SourceFile.tsx +3 -1
- package/src/components/VarDeclaration.tsx +14 -28
- package/src/context/index.ts +1 -1
- package/src/create-package.ts +10 -39
- package/src/symbols/index.ts +118 -0
- package/src/symbols/reference.tsx +163 -0
- package/src/symbols/scopes.ts +38 -13
- package/src/symbols/ts-lexical-scope.ts +18 -0
- package/src/symbols/ts-member-scope.ts +23 -6
- package/src/symbols/ts-module-scope.ts +31 -21
- package/src/symbols/ts-output-symbol.ts +111 -49
- package/src/symbols/ts-package-scope.ts +5 -5
- package/src/utils.ts +38 -1
- package/temp/api.json +1641 -713
- package/test/class.test.tsx +10 -4
- package/test/externals.test.tsx +1 -40
- package/test/reference.test.tsx +5 -5
- package/tsdoc-metadata.json +1 -1
- package/dist/src/context/private-scope.d.ts +0 -18
- package/dist/src/context/private-scope.d.ts.map +0 -1
- package/dist/src/context/private-scope.js +0 -8
- package/src/context/private-scope.ts +0 -23
- package/src/symbols/reference.ts +0 -197
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
ImportedSymbol,
|
|
11
11
|
ImportRecords,
|
|
12
12
|
TSPackageScope,
|
|
13
|
-
TSSymbolFlags,
|
|
14
13
|
} from "../symbols/index.js";
|
|
15
14
|
import { modulePath } from "../utils.js";
|
|
16
15
|
import { usePackage } from "./PackageDirectory.js";
|
|
@@ -31,11 +30,7 @@ export function ImportStatements(props: ImportStatementsProps) {
|
|
|
31
30
|
() => imports.value,
|
|
32
31
|
([module, importedSymbols]) => {
|
|
33
32
|
let targetPath: string;
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
(pkg && pkg.scope !== module.parent) ||
|
|
37
|
-
(!pkg && module.parent!.kind !== "global")
|
|
38
|
-
) {
|
|
33
|
+
if (pkg?.scope !== module.parent) {
|
|
39
34
|
// importing from another package, so let's calculate the import.
|
|
40
35
|
const targetPackage = module.parent as TSPackageScope;
|
|
41
36
|
let foundPath: string | false = false;
|
|
@@ -101,7 +96,7 @@ export function ImportStatement(props: ImportStatementProps) {
|
|
|
101
96
|
return a.local.name.localeCompare(b.local.name);
|
|
102
97
|
});
|
|
103
98
|
const allNamedImportsAreTypes = namedImportSymbols.every(
|
|
104
|
-
(nis) => nis.local.
|
|
99
|
+
(nis) => nis.local.isTypeSymbol && !nis.local.isValueSymbol,
|
|
105
100
|
);
|
|
106
101
|
|
|
107
102
|
if (allNamedImportsAreTypes) {
|
|
@@ -150,7 +145,8 @@ function ImportBinding(props: Readonly<ImportBindingProps>) {
|
|
|
150
145
|
const prefix = memo(() =>
|
|
151
146
|
(
|
|
152
147
|
!props.inTypeImport &&
|
|
153
|
-
props.importedSymbol.local.
|
|
148
|
+
props.importedSymbol.local.isTypeSymbol &&
|
|
149
|
+
!props.importedSymbol.local.isValueSymbol
|
|
154
150
|
) ?
|
|
155
151
|
"type "
|
|
156
152
|
: "",
|
|
@@ -7,9 +7,7 @@ import {
|
|
|
7
7
|
emitSymbol,
|
|
8
8
|
findKeyedChild,
|
|
9
9
|
findUnkeyedChildren,
|
|
10
|
-
MemberScope,
|
|
11
10
|
Name,
|
|
12
|
-
OutputSymbolFlags,
|
|
13
11
|
Refkey,
|
|
14
12
|
Show,
|
|
15
13
|
takeSymbols,
|
|
@@ -19,9 +17,11 @@ import { BaseDeclarationProps, Declaration } from "./Declaration.js";
|
|
|
19
17
|
import { JSDoc } from "./JSDoc.jsx";
|
|
20
18
|
|
|
21
19
|
import { TypeParameterDescriptor } from "../parameter-descriptor.js";
|
|
20
|
+
import { useTSLexicalScope, useTSMemberScope } from "../symbols/scopes.js";
|
|
22
21
|
import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
|
|
23
22
|
import { TypeParameters } from "./FunctionBase.jsx";
|
|
24
23
|
import { MemberDeclaration } from "./MemberDeclaration.jsx";
|
|
24
|
+
import { MemberScope } from "./MemberScope.jsx";
|
|
25
25
|
import { PropertyName } from "./PropertyName.jsx";
|
|
26
26
|
import { ensureTypeRefContext } from "./TypeRefContext.jsx";
|
|
27
27
|
|
|
@@ -43,8 +43,8 @@ const _InterfaceDeclaration = ensureTypeRefContext(
|
|
|
43
43
|
const takenSymbols = ExprSlot.ref.value;
|
|
44
44
|
for (const symbol of takenSymbols) {
|
|
45
45
|
// ignore non-transient symbols (likely not the result of an expression).
|
|
46
|
-
if (symbol.
|
|
47
|
-
symbol.
|
|
46
|
+
if (symbol.isTransient) {
|
|
47
|
+
symbol.moveMembersTo(sym);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -65,11 +65,11 @@ const _InterfaceDeclaration = ensureTypeRefContext(
|
|
|
65
65
|
: <TypeParameters parameters={props.typeParameters} />;
|
|
66
66
|
|
|
67
67
|
const extendsPart = props.extends ? <> extends {props.extends}</> : "";
|
|
68
|
-
const flags = OutputSymbolFlags.StaticMemberContainer;
|
|
69
|
-
|
|
70
68
|
const name = useTSNamePolicy().getName(props.name, "interface");
|
|
71
69
|
const filteredChildren = findUnkeyedChildren(children);
|
|
72
|
-
const
|
|
70
|
+
const currentScope = useTSLexicalScope();
|
|
71
|
+
|
|
72
|
+
const sym = new TSOutputSymbol(name, currentScope.types, {
|
|
73
73
|
refkeys: props.refkey,
|
|
74
74
|
default: props.default,
|
|
75
75
|
export: props.export,
|
|
@@ -82,13 +82,7 @@ const _InterfaceDeclaration = ensureTypeRefContext(
|
|
|
82
82
|
<JSDoc children={props.doc} />
|
|
83
83
|
<hbr />
|
|
84
84
|
</Show>
|
|
85
|
-
<Declaration
|
|
86
|
-
{...props}
|
|
87
|
-
nameKind="interface"
|
|
88
|
-
flags={flags}
|
|
89
|
-
kind="type"
|
|
90
|
-
symbol={sym}
|
|
91
|
-
>
|
|
85
|
+
<Declaration {...props} nameKind="interface" kind="type" symbol={sym}>
|
|
92
86
|
interface <Name />
|
|
93
87
|
{sTypeParameters}
|
|
94
88
|
{extendsPart}{" "}
|
|
@@ -122,16 +116,15 @@ export interface InterfaceExpressionProps {
|
|
|
122
116
|
|
|
123
117
|
export const InterfaceExpression = ensureTypeRefContext(
|
|
124
118
|
(props: InterfaceExpressionProps) => {
|
|
125
|
-
const symbol = new TSOutputSymbol("", {
|
|
126
|
-
|
|
127
|
-
OutputSymbolFlags.StaticMemberContainer | OutputSymbolFlags.Transient,
|
|
119
|
+
const symbol = new TSOutputSymbol("", undefined, {
|
|
120
|
+
transient: true,
|
|
128
121
|
});
|
|
129
122
|
|
|
130
123
|
emitSymbol(symbol);
|
|
131
124
|
|
|
132
125
|
return (
|
|
133
126
|
<group>
|
|
134
|
-
<MemberScope
|
|
127
|
+
<MemberScope ownerSymbol={symbol}>
|
|
135
128
|
<Block>{props.children}</Block>
|
|
136
129
|
</MemberScope>
|
|
137
130
|
</group>
|
|
@@ -176,9 +169,9 @@ export function InterfaceMember(props: InterfaceMemberProps) {
|
|
|
176
169
|
const name = namer.getName(props.name!, "interface-member");
|
|
177
170
|
let sym = undefined;
|
|
178
171
|
if (props.name) {
|
|
179
|
-
|
|
172
|
+
const scope = useTSMemberScope();
|
|
173
|
+
sym = new TSOutputSymbol(name, scope.ownerSymbol.staticMembers, {
|
|
180
174
|
refkeys: props.refkey,
|
|
181
|
-
flags: OutputSymbolFlags.StaticMember,
|
|
182
175
|
tsFlags:
|
|
183
176
|
TSSymbolFlags.TypeSymbol |
|
|
184
177
|
((props.nullish ?? props.optional) ?
|
|
@@ -191,8 +184,8 @@ export function InterfaceMember(props: InterfaceMemberProps) {
|
|
|
191
184
|
effect(() => {
|
|
192
185
|
if (taken.size > 1) return;
|
|
193
186
|
const symbol = Array.from(taken)[0];
|
|
194
|
-
if (symbol?.
|
|
195
|
-
symbol.
|
|
187
|
+
if (symbol?.isTransient) {
|
|
188
|
+
symbol.moveMembersTo(sym!);
|
|
196
189
|
}
|
|
197
190
|
});
|
|
198
191
|
} else {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
childrenArray,
|
|
3
3
|
findKeyedChild,
|
|
4
|
-
MemberDeclaration,
|
|
5
4
|
Prose,
|
|
6
5
|
Refkey,
|
|
7
|
-
Scope,
|
|
8
6
|
Show,
|
|
9
7
|
type Children,
|
|
10
8
|
} from "@alloy-js/core";
|
|
@@ -19,6 +17,8 @@ import {
|
|
|
19
17
|
} from "./FunctionBase.jsx";
|
|
20
18
|
import { JSDoc } from "./JSDoc.jsx";
|
|
21
19
|
import { JSDocParams } from "./JSDocParam.jsx";
|
|
20
|
+
import { LexicalScope } from "./LexicalScope.jsx";
|
|
21
|
+
import { MemberDeclaration } from "./MemberDeclaration.jsx";
|
|
22
22
|
|
|
23
23
|
/** Props for {@link (InterfaceMethod:namespace)} component */
|
|
24
24
|
export interface InterfaceMethodProps extends CallSignatureProps {
|
|
@@ -84,9 +84,9 @@ export function InterfaceMethod(props: InterfaceMethodProps) {
|
|
|
84
84
|
</Show>
|
|
85
85
|
<MemberDeclaration static {...props} refkey={props.refkey}>
|
|
86
86
|
{name}
|
|
87
|
-
<
|
|
87
|
+
<LexicalScope name={props.name}>
|
|
88
88
|
<CallSignature {...callSignatureProps} returnType={returnType} />
|
|
89
|
-
</
|
|
89
|
+
</LexicalScope>
|
|
90
90
|
</MemberDeclaration>
|
|
91
91
|
</>
|
|
92
92
|
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Scope, ScopePropsWithInfo, ScopePropsWithValue } from "@alloy-js/core";
|
|
2
|
+
import { createLexicalScope, TSLexicalScope } from "../symbols/index.js";
|
|
3
|
+
|
|
4
|
+
export interface LexicalScopePropsWithScopeValue extends ScopePropsWithValue {}
|
|
5
|
+
export interface LeixcalScopePropsWithScopeInfo extends ScopePropsWithInfo {}
|
|
6
|
+
|
|
7
|
+
export type LexicalScopeProps =
|
|
8
|
+
| LexicalScopePropsWithScopeValue
|
|
9
|
+
| LeixcalScopePropsWithScopeInfo;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A lexical scope for TypeScript, which contains declaration spaces for types
|
|
13
|
+
* and values. Declaration components will create symbols in this scope.
|
|
14
|
+
*/
|
|
15
|
+
export function LexicalScope(props: LexicalScopeProps) {
|
|
16
|
+
let scope;
|
|
17
|
+
if ("value" in props) {
|
|
18
|
+
if (!(props.value instanceof TSLexicalScope)) {
|
|
19
|
+
throw new Error("LexicalScope value must be a TSLexicalScope instance");
|
|
20
|
+
}
|
|
21
|
+
scope = props.value;
|
|
22
|
+
} else {
|
|
23
|
+
scope = createLexicalScope(props.name ?? "Lexical scope", props);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return <Scope value={scope}>{props.children}</Scope>;
|
|
27
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MemberDeclaration as CoreMemberDeclaration,
|
|
3
3
|
MemberDeclarationPropsWithInfo,
|
|
4
|
-
OutputSymbolFlags,
|
|
5
4
|
} from "@alloy-js/core";
|
|
6
5
|
import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
|
|
7
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createStaticMemberSymbol,
|
|
8
|
+
TSOutputSymbol,
|
|
9
|
+
TSSymbolFlags,
|
|
10
|
+
} from "../symbols/index.js";
|
|
8
11
|
|
|
9
12
|
export interface MemberDeclarationProps
|
|
10
13
|
extends Omit<MemberDeclarationPropsWithInfo, "name"> {
|
|
@@ -16,22 +19,11 @@ export interface MemberDeclarationProps
|
|
|
16
19
|
/** Name that shouldn't go through the name policy resolver again. */
|
|
17
20
|
exactName?: string;
|
|
18
21
|
|
|
19
|
-
/**
|
|
20
|
-
* Whether this is a memberdeclaration of a type (e.g. interface, type alias) or a
|
|
21
|
-
* value (e.g. var, const, let).
|
|
22
|
-
*/
|
|
23
|
-
kind?: "type" | "value";
|
|
24
|
-
|
|
25
22
|
/**
|
|
26
23
|
* The name policy kind to apply to the memberdeclaration.
|
|
27
24
|
*/
|
|
28
25
|
nameKind?: TypeScriptElements;
|
|
29
26
|
|
|
30
|
-
/**
|
|
31
|
-
* Flags for the symbol created by this component.
|
|
32
|
-
*/
|
|
33
|
-
flags?: OutputSymbolFlags;
|
|
34
|
-
|
|
35
27
|
/**
|
|
36
28
|
* The symbol to use for this memberdeclaration.
|
|
37
29
|
*/
|
|
@@ -50,18 +42,14 @@ export function MemberDeclaration(props: Readonly<MemberDeclarationProps>) {
|
|
|
50
42
|
} else {
|
|
51
43
|
const namePolicy = useTSNamePolicy();
|
|
52
44
|
|
|
53
|
-
|
|
45
|
+
const tsFlags: TSSymbolFlags =
|
|
54
46
|
props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None;
|
|
55
47
|
|
|
56
|
-
if (props.kind === "type") {
|
|
57
|
-
tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
48
|
const name =
|
|
61
49
|
props.exactName ?? namePolicy.getName(props.name!, props.nameKind!);
|
|
62
|
-
|
|
50
|
+
|
|
51
|
+
sym = createStaticMemberSymbol(name, {
|
|
63
52
|
refkeys: props.refkey,
|
|
64
|
-
flags: props.flags,
|
|
65
53
|
tsFlags,
|
|
66
54
|
metadata: props.metadata,
|
|
67
55
|
});
|
|
@@ -30,8 +30,10 @@ interface PartDescriptorWithIndex extends PartDescriptorBase {
|
|
|
30
30
|
}
|
|
31
31
|
interface PartDescriptorBase {
|
|
32
32
|
accessStyle: "dot" | "bracket";
|
|
33
|
+
jsPrivate: boolean;
|
|
33
34
|
quoteId: boolean;
|
|
34
35
|
nullish: boolean;
|
|
36
|
+
type: boolean;
|
|
35
37
|
args?: Children[];
|
|
36
38
|
}
|
|
37
39
|
|
|
@@ -233,6 +235,18 @@ function createPartDescriptorFromProps(
|
|
|
233
235
|
return false;
|
|
234
236
|
}),
|
|
235
237
|
args: ref<any>(partProps.args === true ? [] : partProps.args),
|
|
238
|
+
jsPrivate: computed(() => {
|
|
239
|
+
return (
|
|
240
|
+
!!symbolSource.value &&
|
|
241
|
+
(symbolSource.value as TSOutputSymbol).isPrivateMemberSymbol
|
|
242
|
+
);
|
|
243
|
+
}),
|
|
244
|
+
type: computed(() => {
|
|
245
|
+
return (
|
|
246
|
+
!!symbolSource.value &&
|
|
247
|
+
(symbolSource.value as TSOutputSymbol).isTypeSymbol
|
|
248
|
+
);
|
|
249
|
+
}),
|
|
236
250
|
};
|
|
237
251
|
|
|
238
252
|
return reactive(part);
|
|
@@ -386,7 +400,9 @@ function formatNonCallChain(parts: PartDescriptor[]): Children {
|
|
|
386
400
|
// Determine if we should use nullish operator from previous part
|
|
387
401
|
const prevPart = parts[i - 1];
|
|
388
402
|
|
|
389
|
-
if (
|
|
403
|
+
if (prevPart.type) {
|
|
404
|
+
expression.push(formatArrayAccess(prevPart, part));
|
|
405
|
+
} else if (part.args !== undefined) {
|
|
390
406
|
// For parts with only args (no name), append function call directly with appropriate nullish operator
|
|
391
407
|
expression.push(formatCallExpr(prevPart, part));
|
|
392
408
|
} else if (part.accessStyle === "dot") {
|
|
@@ -405,12 +421,12 @@ function formatNonCallChain(parts: PartDescriptor[]): Children {
|
|
|
405
421
|
function formatArrayAccess(prevPart: PartDescriptor, part: PartDescriptor) {
|
|
406
422
|
return (
|
|
407
423
|
<group>
|
|
408
|
-
{prevPart.nullish ? "?." : ""}[
|
|
424
|
+
{!prevPart.type && prevPart.nullish ? "?." : ""}[
|
|
409
425
|
<indent>
|
|
410
426
|
<sbr />
|
|
411
|
-
{part.quoteId && '"'}
|
|
427
|
+
{(prevPart.type || part.quoteId) && '"'}
|
|
412
428
|
{isIdPartDescriptor(part) ? part.id : part.index}
|
|
413
|
-
{part.quoteId && '"'}
|
|
429
|
+
{(prevPart.type || part.quoteId) && '"'}
|
|
414
430
|
</indent>
|
|
415
431
|
<sbr />]
|
|
416
432
|
</group>
|
|
@@ -423,7 +439,11 @@ function formatDotAccess(prevPart: PartDescriptor, part: PartDescriptor) {
|
|
|
423
439
|
<indent>
|
|
424
440
|
<sbr />
|
|
425
441
|
{prevPart.nullish ? "?." : "."}
|
|
426
|
-
{isIdPartDescriptor(part) ?
|
|
442
|
+
{isIdPartDescriptor(part) ?
|
|
443
|
+
part.jsPrivate ?
|
|
444
|
+
`#${part.id}`
|
|
445
|
+
: part.id
|
|
446
|
+
: part.index}
|
|
427
447
|
</indent>
|
|
428
448
|
</group>
|
|
429
449
|
);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Children, MemberScope as CoreMemberScope } from "@alloy-js/core";
|
|
2
|
+
import { useTSLexicalScopeIfPresent } from "../symbols/scopes.js";
|
|
3
|
+
import { TSMemberScope } from "../symbols/ts-member-scope.js";
|
|
4
|
+
import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
|
|
5
|
+
|
|
6
|
+
export interface MemberScopeProps {
|
|
7
|
+
children: Children;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The symbol that this member scope will create member symbols on.
|
|
11
|
+
*/
|
|
12
|
+
ownerSymbol: TSOutputSymbol;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A member scope for TypeScript. Member declarations will create symbols
|
|
17
|
+
* in this scope, which will be added to the owner symbol's members.
|
|
18
|
+
*/
|
|
19
|
+
export function MemberScope(props: MemberScopeProps) {
|
|
20
|
+
const memberScope = new TSMemberScope(
|
|
21
|
+
"member-scope",
|
|
22
|
+
useTSLexicalScopeIfPresent(),
|
|
23
|
+
props.ownerSymbol,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<CoreMemberScope value={memberScope}>{props.children}</CoreMemberScope>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
emitSymbol,
|
|
3
3
|
instantiateTakenMembersTo as instantiateTakenSymbolsTo,
|
|
4
|
-
OutputSymbolFlags,
|
|
5
4
|
} from "@alloy-js/core";
|
|
6
|
-
import {
|
|
5
|
+
import { createValueSymbol } from "../symbols/index.js";
|
|
7
6
|
import {
|
|
8
7
|
FunctionCallExpression,
|
|
9
8
|
FunctionCallExpressionProps,
|
|
@@ -12,10 +11,10 @@ import {
|
|
|
12
11
|
export interface NewExpressionProps extends FunctionCallExpressionProps {}
|
|
13
12
|
|
|
14
13
|
export function NewExpression(props: NewExpressionProps) {
|
|
15
|
-
const sym =
|
|
16
|
-
|
|
14
|
+
const sym = createValueSymbol("", {
|
|
15
|
+
transient: true,
|
|
17
16
|
});
|
|
18
|
-
instantiateTakenSymbolsTo(sym);
|
|
17
|
+
instantiateTakenSymbolsTo(sym, "static", "instance");
|
|
19
18
|
emitSymbol(sym);
|
|
20
19
|
return (
|
|
21
20
|
<>
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AssignmentContext,
|
|
3
2
|
Block,
|
|
4
3
|
Children,
|
|
5
4
|
computed,
|
|
6
|
-
createAssignmentContext,
|
|
7
5
|
emitSymbol,
|
|
8
6
|
For,
|
|
9
7
|
Match,
|
|
10
|
-
MemberScope,
|
|
11
8
|
moveTakenMembersTo,
|
|
12
|
-
OutputSymbolFlags,
|
|
13
9
|
Refkey,
|
|
14
10
|
Switch,
|
|
15
11
|
takeSymbols,
|
|
16
12
|
} from "@alloy-js/core";
|
|
17
13
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
18
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
createStaticMemberSymbol,
|
|
16
|
+
createTransientValueSymbol,
|
|
17
|
+
} from "../symbols/index.js";
|
|
18
|
+
import { MemberScope } from "./MemberScope.jsx";
|
|
19
19
|
import { PropertyName } from "./PropertyName.jsx";
|
|
20
20
|
import { ValueExpression } from "./ValueExpression.js";
|
|
21
21
|
|
|
@@ -28,12 +28,10 @@ export interface ObjectExpressionProps {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function ObjectExpression(props: ObjectExpressionProps) {
|
|
31
|
-
const symbol =
|
|
32
|
-
flags:
|
|
33
|
-
OutputSymbolFlags.StaticMemberContainer | OutputSymbolFlags.Transient,
|
|
34
|
-
});
|
|
31
|
+
const symbol = createTransientValueSymbol();
|
|
35
32
|
|
|
36
33
|
emitSymbol(symbol);
|
|
34
|
+
moveTakenMembersTo(symbol);
|
|
37
35
|
|
|
38
36
|
const jsValueProperties = computed(() => {
|
|
39
37
|
const jsValue = props.jsValue;
|
|
@@ -59,7 +57,7 @@ export function ObjectExpression(props: ObjectExpressionProps) {
|
|
|
59
57
|
</Match>
|
|
60
58
|
<Match else>
|
|
61
59
|
<group>
|
|
62
|
-
<MemberScope
|
|
60
|
+
<MemberScope ownerSymbol={symbol}>
|
|
63
61
|
<Block>
|
|
64
62
|
<For each={jsValueProperties} comma softline enderPunctuation>
|
|
65
63
|
{([name, value]) => (
|
|
@@ -108,12 +106,12 @@ export function ObjectProperty(props: ObjectPropertyProps) {
|
|
|
108
106
|
|
|
109
107
|
let sym = undefined;
|
|
110
108
|
if (props.refkey && props.name) {
|
|
111
|
-
sym =
|
|
109
|
+
sym = createStaticMemberSymbol(symbolName!, {
|
|
112
110
|
refkeys: props.refkey,
|
|
113
|
-
flags: OutputSymbolFlags.StaticMember,
|
|
114
111
|
});
|
|
115
112
|
|
|
116
113
|
moveTakenMembersTo(sym);
|
|
114
|
+
emitSymbol(sym);
|
|
117
115
|
} else {
|
|
118
116
|
// noop
|
|
119
117
|
takeSymbols();
|
|
@@ -129,14 +127,9 @@ export function ObjectProperty(props: ObjectPropertyProps) {
|
|
|
129
127
|
value = props.children;
|
|
130
128
|
}
|
|
131
129
|
|
|
132
|
-
const assignmentContext: AssignmentContext | undefined =
|
|
133
|
-
sym ? createAssignmentContext(sym) : undefined;
|
|
134
130
|
return (
|
|
135
131
|
<>
|
|
136
|
-
{name}:{
|
|
137
|
-
<AssignmentContext.Provider value={assignmentContext}>
|
|
138
|
-
{value}
|
|
139
|
-
</AssignmentContext.Provider>
|
|
132
|
+
{name}: {value}
|
|
140
133
|
</>
|
|
141
134
|
);
|
|
142
135
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MemberDeclarationContext, useContext } from "@alloy-js/core";
|
|
2
|
-
import { TSOutputSymbol
|
|
2
|
+
import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
|
|
3
3
|
import { isValidJSIdentifier } from "../utils.js";
|
|
4
4
|
|
|
5
5
|
export interface PropertyNameProps {
|
|
@@ -33,7 +33,7 @@ export function PropertyName(props: PropertyNameProps) {
|
|
|
33
33
|
return "(no member declaration context)";
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (declSymbol.
|
|
36
|
+
if (declSymbol.isPrivateMemberSymbol) {
|
|
37
37
|
return <>#{declSymbol.name}</>;
|
|
38
38
|
} else {
|
|
39
39
|
return <>{quoteIfNeeded(declSymbol.name)}</>;
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
Show,
|
|
7
7
|
SourceDirectoryContext,
|
|
8
8
|
useContext,
|
|
9
|
+
useScope,
|
|
9
10
|
type Children,
|
|
10
11
|
} from "@alloy-js/core";
|
|
11
12
|
|
|
@@ -39,7 +40,8 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
39
40
|
const sdData = getSourceDirectoryData(directoryContext);
|
|
40
41
|
const currentDir = directoryContext.path;
|
|
41
42
|
const path: string = join(currentDir, props.path);
|
|
42
|
-
const
|
|
43
|
+
const parent = useScope();
|
|
44
|
+
const scope = new TSModuleScope(path, parent);
|
|
43
45
|
sdData.modules.add(scope);
|
|
44
46
|
const pkg = useContext(PackageContext);
|
|
45
47
|
if (pkg) {
|
|
@@ -2,13 +2,12 @@ import {
|
|
|
2
2
|
Children,
|
|
3
3
|
Declaration as CoreDeclaration,
|
|
4
4
|
createSymbolSlot,
|
|
5
|
-
effect,
|
|
6
5
|
Name,
|
|
7
|
-
OutputSymbolFlags,
|
|
8
6
|
Show,
|
|
9
7
|
} from "@alloy-js/core";
|
|
10
8
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
11
|
-
import {
|
|
9
|
+
import { createValueSymbol } from "../symbols/index.js";
|
|
10
|
+
import { TSSymbolFlags } from "../symbols/ts-output-symbol.js";
|
|
12
11
|
import { BaseDeclarationProps } from "./Declaration.js";
|
|
13
12
|
import { JSDoc } from "./JSDoc.jsx";
|
|
14
13
|
import { TypeRefContext } from "./TypeRefContext.jsx";
|
|
@@ -25,25 +24,20 @@ export interface VarDeclarationProps extends BaseDeclarationProps {
|
|
|
25
24
|
export function VarDeclaration(props: VarDeclarationProps) {
|
|
26
25
|
const TypeSymbolSlot = createSymbolSlot();
|
|
27
26
|
const ValueTypeSymbolSlot = createSymbolSlot();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const takenSymbols = ValueTypeSymbolSlot.ref.value;
|
|
37
|
-
for (const symbol of takenSymbols) {
|
|
38
|
-
// ignore non-transient symbols (likely not the result of an
|
|
39
|
-
// expression).
|
|
40
|
-
if (symbol.flags & OutputSymbolFlags.Transient) {
|
|
41
|
-
symbol.moveTo(sym);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
27
|
+
const name = useTSNamePolicy().getName(props.name, "variable");
|
|
28
|
+
const sym = createValueSymbol(name, {
|
|
29
|
+
refkeys: props.refkey,
|
|
30
|
+
default: props.default,
|
|
31
|
+
export: props.export,
|
|
32
|
+
metadata: props.metadata,
|
|
33
|
+
tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None,
|
|
34
|
+
type: props.type ? TypeSymbolSlot.firstSymbol : undefined,
|
|
45
35
|
});
|
|
46
36
|
|
|
37
|
+
if (!props.type) {
|
|
38
|
+
ValueTypeSymbolSlot.moveMembersTo(sym);
|
|
39
|
+
}
|
|
40
|
+
|
|
47
41
|
const keyword =
|
|
48
42
|
props.var ? "var"
|
|
49
43
|
: props.let ? "let"
|
|
@@ -54,14 +48,6 @@ export function VarDeclaration(props: VarDeclarationProps) {
|
|
|
54
48
|
: <TypeSymbolSlot>{props.type}</TypeSymbolSlot>
|
|
55
49
|
</TypeRefContext>
|
|
56
50
|
: undefined;
|
|
57
|
-
const name = useTSNamePolicy().getName(props.name, "variable");
|
|
58
|
-
const sym = new TSOutputSymbol(name, {
|
|
59
|
-
refkeys: props.refkey,
|
|
60
|
-
default: props.default,
|
|
61
|
-
export: props.export,
|
|
62
|
-
metadata: props.metadata,
|
|
63
|
-
tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None,
|
|
64
|
-
});
|
|
65
51
|
|
|
66
52
|
return (
|
|
67
53
|
<>
|
package/src/context/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
// type ref context isn't exported because it conflicts with the component of the same name.
|