@alloy-js/typescript 0.16.0 → 0.18.0-dev.3
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/CHANGELOG.md +13 -0
- package/dist/src/builtins/node.d.ts +11 -42
- package/dist/src/builtins/node.d.ts.map +1 -1
- package/dist/src/builtins/node.js +3 -0
- package/dist/src/components/ArrowFunction.d.ts +1 -1
- package/dist/src/components/ArrowFunction.d.ts.map +1 -1
- package/dist/src/components/CallSignature.d.ts +1 -1
- package/dist/src/components/CallSignature.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +5 -7
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +3 -4
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +3 -4
- 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 +1 -1
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.d.ts +1 -1
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +15 -10
- package/dist/src/components/FunctionDeclaration.d.ts +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionExpression.d.ts +1 -1
- package/dist/src/components/FunctionExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionType.d.ts +1 -1
- package/dist/src/components/FunctionType.d.ts.map +1 -1
- package/dist/src/components/IfStatement.d.ts +1 -1
- package/dist/src/components/IfStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/Interface.js +1 -1
- package/dist/src/components/InterfaceMethod.d.ts +1 -2
- package/dist/src/components/InterfaceMethod.d.ts.map +1 -1
- package/dist/src/components/JSDoc.d.ts +1 -1
- package/dist/src/components/JSDoc.d.ts.map +1 -1
- package/dist/src/components/JSDocComment.d.ts +1 -1
- package/dist/src/components/JSDocComment.d.ts.map +1 -1
- package/dist/src/components/JSDocExample.d.ts +1 -1
- package/dist/src/components/JSDocExample.d.ts.map +1 -1
- package/dist/src/components/JSDocParam.d.ts +1 -1
- package/dist/src/components/JSDocParam.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +4 -4
- package/dist/src/components/MemberExpression.d.ts +6 -1
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +38 -14
- package/dist/src/components/NewExpression.d.ts +5 -0
- package/dist/src/components/NewExpression.d.ts.map +1 -0
- package/dist/src/components/NewExpression.js +12 -0
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +17 -18
- package/dist/src/components/PackageDirectory.d.ts.map +1 -1
- package/dist/src/components/PackageDirectory.js +3 -3
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +5 -1
- package/dist/src/components/SingleLineCommentBlock.d.ts +1 -1
- package/dist/src/components/SingleLineCommentBlock.d.ts.map +1 -1
- package/dist/src/components/SourceFile.d.ts +1 -2
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +3 -3
- package/dist/src/components/SwitchStatement.d.ts +1 -1
- package/dist/src/components/SwitchStatement.d.ts.map +1 -1
- package/dist/src/components/TypeRefContext.d.ts +1 -1
- package/dist/src/components/TypeRefContext.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +30 -10
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/stc/index.d.ts +45 -43
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +46 -44
- package/dist/src/create-package.d.ts +63 -19
- package/dist/src/create-package.d.ts.map +1 -1
- package/dist/src/create-package.js +153 -15
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/parameter-descriptor.d.ts +1 -1
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/source-directory-data.d.ts.map +1 -1
- package/dist/src/source-directory-data.js +2 -2
- package/dist/src/symbols/reference.d.ts +2 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +3 -4
- package/dist/src/symbols/scopes.d.ts +1 -4
- package/dist/src/symbols/scopes.d.ts.map +1 -1
- package/dist/src/symbols/ts-member-scope.d.ts +4 -6
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-member-scope.js +8 -10
- package/dist/src/symbols/ts-module-scope.d.ts +8 -11
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +47 -40
- package/dist/src/symbols/ts-output-symbol.d.ts +23 -16
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +88 -27
- package/dist/src/symbols/ts-package-scope.d.ts +18 -14
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +78 -27
- package/dist/src/utils.js +1 -1
- package/dist/test/class.test.js +2 -1
- package/dist/test/externals.test.js +87 -2
- package/dist/test/function-declaration.test.js +74 -3
- package/dist/test/member-expression.test.js +108 -2
- package/dist/test/new-expression.test.d.ts +2 -0
- package/dist/test/new-expression.test.d.ts.map +1 -0
- package/dist/test/new-expression.test.js +62 -0
- package/dist/test/values.test.d.ts.map +1 -1
- package/dist/test/values.test.js +48 -1
- package/dist/test/var-declaration.test.d.ts.map +1 -1
- package/dist/test/var-declaration.test.js +145 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -21
- package/src/builtins/node.ts +4 -0
- package/src/components/ArrowFunction.tsx +1 -1
- package/src/components/CallSignature.tsx +1 -1
- package/src/components/ClassDeclaration.tsx +5 -7
- package/src/components/Declaration.tsx +3 -8
- package/src/components/EnumDeclaration.tsx +3 -4
- package/src/components/EnumMember.tsx +3 -4
- package/src/components/FunctionBase.tsx +26 -19
- package/src/components/FunctionDeclaration.tsx +1 -1
- package/src/components/FunctionExpression.tsx +1 -1
- package/src/components/FunctionType.tsx +1 -1
- package/src/components/IfStatement.tsx +1 -2
- package/src/components/ImportStatement.tsx +0 -1
- package/src/components/Interface.tsx +1 -1
- package/src/components/InterfaceMethod.tsx +1 -1
- package/src/components/JSDoc.tsx +1 -2
- package/src/components/JSDocComment.tsx +1 -1
- package/src/components/JSDocExample.tsx +1 -2
- package/src/components/JSDocParam.tsx +1 -2
- package/src/components/MemberDeclaration.tsx +5 -8
- package/src/components/MemberExpression.tsx +67 -15
- package/src/components/NewExpression.tsx +25 -0
- package/src/components/ObjectExpression.tsx +21 -19
- package/src/components/PackageDirectory.tsx +2 -10
- package/src/components/Reference.tsx +4 -2
- package/src/components/SingleLineCommentBlock.tsx +1 -2
- package/src/components/SourceFile.tsx +3 -6
- package/src/components/SwitchStatement.tsx +1 -2
- package/src/components/TypeRefContext.tsx +1 -1
- package/src/components/VarDeclaration.tsx +34 -11
- package/src/components/index.ts +1 -0
- package/src/components/stc/index.ts +46 -44
- package/src/create-package.ts +276 -37
- package/src/index.ts +2 -0
- package/src/parameter-descriptor.ts +1 -1
- package/src/source-directory-data.ts +2 -2
- package/src/symbols/reference.ts +10 -5
- package/src/symbols/scopes.ts +1 -6
- package/src/symbols/ts-member-scope.ts +8 -23
- package/src/symbols/ts-module-scope.ts +58 -62
- package/src/symbols/ts-output-symbol.ts +108 -50
- package/src/symbols/ts-package-scope.ts +71 -53
- package/src/utils.ts +1 -1
- package/temp/api.json +3743 -3667
- package/test/class.test.tsx +2 -1
- package/test/externals.test.tsx +99 -1
- package/test/function-declaration.test.tsx +75 -2
- package/test/member-expression.test.tsx +93 -2
- package/test/new-expression.test.tsx +42 -0
- package/test/values.test.tsx +34 -0
- package/test/var-declaration.test.tsx +101 -1
- package/tsconfig.json +2 -1
- package/tsdoc-metadata.json +1 -1
- package/LICENSE +0 -7
- package/dist/test/vitest.d.js +0 -1
- package/test/vitest.d.ts +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/typescript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0-dev.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -10,30 +10,31 @@
|
|
|
10
10
|
"import": "./dist/src/components/stc/index.js"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"generate-docs": "api-extractor run",
|
|
15
|
+
"build": "alloy build && pnpm run generate-docs",
|
|
16
|
+
"clean": "rimraf dist/ .temp/",
|
|
17
|
+
"test:watch": "vitest -w",
|
|
18
|
+
"watch": "alloy build --watch",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"prepack": "node ../../scripts/strip-dev-exports.js"
|
|
21
|
+
},
|
|
13
22
|
"keywords": [],
|
|
14
23
|
"author": "brian.terlson@microsoft.com",
|
|
15
24
|
"license": "MIT",
|
|
16
25
|
"dependencies": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
26
|
+
"@alloy-js/core": "~0.17.0 || >= 0.18.0-dev.2",
|
|
27
|
+
"change-case": "catalog:",
|
|
28
|
+
"pathe": "catalog:"
|
|
20
29
|
},
|
|
21
30
|
"devDependencies": {
|
|
22
|
-
"@
|
|
23
|
-
"@rollup
|
|
24
|
-
"
|
|
25
|
-
"typescript": "
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
31
|
+
"@alloy-js/cli": "~0.17.0 || >= 0.18.0-dev.0",
|
|
32
|
+
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.0",
|
|
33
|
+
"@microsoft/api-extractor": "catalog:",
|
|
34
|
+
"@rollup/plugin-typescript": "catalog:",
|
|
35
|
+
"concurrently": "catalog:",
|
|
36
|
+
"typescript": "catalog:",
|
|
37
|
+
"vitest": "catalog:"
|
|
29
38
|
},
|
|
30
|
-
"type": "module"
|
|
31
|
-
|
|
32
|
-
"generate-docs": "api-extractor run",
|
|
33
|
-
"build": "alloy build && pnpm run generate-docs",
|
|
34
|
-
"clean": "rimraf dist/ .temp/",
|
|
35
|
-
"test:watch": "vitest -w",
|
|
36
|
-
"watch": "alloy build --watch",
|
|
37
|
-
"test": "vitest run"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
39
|
+
"type": "module"
|
|
40
|
+
}
|
package/src/builtins/node.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { SymbolCreator } from "@alloy-js/core";
|
|
1
2
|
import { createPackage } from "../create-package.js";
|
|
2
3
|
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5
|
+
type dummy = SymbolCreator;
|
|
6
|
+
|
|
3
7
|
export const path = createPackage({
|
|
4
8
|
name: "node:path",
|
|
5
9
|
version: "22.5.1",
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
findKeyedChild,
|
|
4
4
|
findUnkeyedChildren,
|
|
5
5
|
Scope,
|
|
6
|
+
type Children,
|
|
6
7
|
} from "@alloy-js/core";
|
|
7
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
8
8
|
import { getCallSignatureProps } from "../utils.js";
|
|
9
9
|
import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
|
|
10
10
|
import { Declaration } from "./Declaration.jsx";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import { usePrivateScope } from "../context/private-scope.js";
|
|
16
16
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
17
17
|
import { TSOutputScope } from "../symbols/scopes.js";
|
|
18
|
-
import {
|
|
18
|
+
import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
|
|
19
19
|
import { getCallSignatureProps } from "../utils.js";
|
|
20
20
|
import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
|
|
21
21
|
import { BaseDeclarationProps, Declaration } from "./Declaration.jsx";
|
|
@@ -65,9 +65,8 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
|
65
65
|
const namePolicy = useTSNamePolicy();
|
|
66
66
|
const extendsPart = props.extends && <> extends {props.extends}</>;
|
|
67
67
|
|
|
68
|
-
const sym =
|
|
69
|
-
|
|
70
|
-
refkey: props.refkey,
|
|
68
|
+
const sym = new TSOutputSymbol(namePolicy.getName(props.name!, "class"), {
|
|
69
|
+
refkeys: props.refkey,
|
|
71
70
|
export: props.export,
|
|
72
71
|
default: props.default,
|
|
73
72
|
flags:
|
|
@@ -137,10 +136,9 @@ export function ClassMember(props: ClassMemberProps) {
|
|
|
137
136
|
tsFlags |= TSSymbolFlags.Nullish;
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
const sym =
|
|
141
|
-
name,
|
|
139
|
+
const sym = new TSOutputSymbol(name, {
|
|
142
140
|
scope,
|
|
143
|
-
|
|
141
|
+
refkeys: props.refkey,
|
|
144
142
|
flags,
|
|
145
143
|
tsFlags,
|
|
146
144
|
});
|
|
@@ -6,11 +6,7 @@ import {
|
|
|
6
6
|
Refkey,
|
|
7
7
|
} from "@alloy-js/core";
|
|
8
8
|
import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
|
|
9
|
-
import {
|
|
10
|
-
createTSSymbol,
|
|
11
|
-
TSOutputSymbol,
|
|
12
|
-
TSSymbolFlags,
|
|
13
|
-
} from "../symbols/index.js";
|
|
9
|
+
import { TSOutputSymbol, TSSymbolFlags } from "../symbols/index.js";
|
|
14
10
|
|
|
15
11
|
// imports for documentation
|
|
16
12
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -112,9 +108,8 @@ export function Declaration(props: DeclarationProps) {
|
|
|
112
108
|
tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
113
109
|
}
|
|
114
110
|
|
|
115
|
-
sym =
|
|
116
|
-
|
|
117
|
-
refkey: props.refkey,
|
|
111
|
+
sym = new TSOutputSymbol(namePolicy.getName(props.name!, props.nameKind!), {
|
|
112
|
+
refkeys: props.refkey,
|
|
118
113
|
export: props.export,
|
|
119
114
|
default: props.default,
|
|
120
115
|
flags: props.flags,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
useBinder,
|
|
11
11
|
} from "@alloy-js/core";
|
|
12
12
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
13
|
-
import {
|
|
13
|
+
import { TSOutputSymbol, useTSScope } from "../symbols/index.js";
|
|
14
14
|
import { BaseDeclarationProps } from "./Declaration.js";
|
|
15
15
|
import { EnumMember } from "./EnumMember.jsx";
|
|
16
16
|
import { JSDoc } from "./JSDoc.jsx";
|
|
@@ -28,11 +28,10 @@ export function EnumDeclaration(props: EnumDeclarationProps) {
|
|
|
28
28
|
const name = useTSNamePolicy().getName(props.name, "enum");
|
|
29
29
|
const binder = useBinder();
|
|
30
30
|
const scope = useTSScope();
|
|
31
|
-
const sym =
|
|
31
|
+
const sym = new TSOutputSymbol(name, {
|
|
32
32
|
binder,
|
|
33
33
|
scope,
|
|
34
|
-
|
|
35
|
-
refkey: props.refkey,
|
|
34
|
+
refkeys: props.refkey,
|
|
36
35
|
default: props.default,
|
|
37
36
|
export: props.export,
|
|
38
37
|
flags: OutputSymbolFlags.StaticMemberContainer,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Children, OutputSymbolFlags, Refkey, Show } from "@alloy-js/core";
|
|
2
2
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
3
|
-
import {
|
|
3
|
+
import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
|
|
4
4
|
import { JSDoc } from "./JSDoc.jsx";
|
|
5
5
|
import { PropertyName } from "./PropertyName.jsx";
|
|
6
6
|
import { ValueExpression } from "./ValueExpression.jsx";
|
|
@@ -49,9 +49,8 @@ export function EnumMember(props: EnumMemberProps) {
|
|
|
49
49
|
const name = namer.getName(props.name, "enum-member");
|
|
50
50
|
let sym: TSOutputSymbol | undefined = undefined;
|
|
51
51
|
if (props.refkey) {
|
|
52
|
-
sym =
|
|
53
|
-
|
|
54
|
-
refkey: props.refkey,
|
|
52
|
+
sym = new TSOutputSymbol(name, {
|
|
53
|
+
refkeys: props.refkey,
|
|
55
54
|
flags: OutputSymbolFlags.StaticMember,
|
|
56
55
|
metadata: props.metadata,
|
|
57
56
|
});
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Block,
|
|
3
3
|
code,
|
|
4
|
+
createSymbolSlot,
|
|
4
5
|
For,
|
|
5
6
|
Indent,
|
|
6
7
|
onCleanup,
|
|
7
8
|
Show,
|
|
8
9
|
taggedComponent,
|
|
10
|
+
type Children,
|
|
9
11
|
} from "@alloy-js/core";
|
|
10
|
-
import type { Children } from "@alloy-js/core/jsx-runtime";
|
|
11
12
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
12
13
|
import type {
|
|
13
14
|
FunctionTypeParameterDescriptor,
|
|
14
15
|
ParameterDescriptor,
|
|
15
16
|
} from "../parameter-descriptor.js";
|
|
16
17
|
import { TypeParameterDescriptor } from "../parameter-descriptor.js";
|
|
17
|
-
import {
|
|
18
|
-
createTSSymbol,
|
|
19
|
-
TSOutputSymbol,
|
|
20
|
-
TSSymbolFlags,
|
|
21
|
-
} from "../symbols/index.js";
|
|
18
|
+
import { TSOutputSymbol, TSSymbolFlags } from "../symbols/index.js";
|
|
22
19
|
import { TypeRefContext } from "./TypeRefContext.jsx";
|
|
23
20
|
|
|
24
21
|
const functionParametersTag = Symbol();
|
|
@@ -120,6 +117,10 @@ export const FunctionTypeParameters = taggedComponent(
|
|
|
120
117
|
);
|
|
121
118
|
|
|
122
119
|
function parameter(param: DeclaredParameterDescriptor) {
|
|
120
|
+
const SymbolSlot = createSymbolSlot();
|
|
121
|
+
|
|
122
|
+
SymbolSlot.instantiateInto(param.symbol);
|
|
123
|
+
|
|
123
124
|
return (
|
|
124
125
|
<group>
|
|
125
126
|
<Show when={param.rest}>...</Show>
|
|
@@ -127,7 +128,10 @@ function parameter(param: DeclaredParameterDescriptor) {
|
|
|
127
128
|
<Show when={!!param.optional}>?</Show>
|
|
128
129
|
<Show when={!!param.type}>
|
|
129
130
|
<indent>
|
|
130
|
-
:
|
|
131
|
+
:{" "}
|
|
132
|
+
<SymbolSlot>
|
|
133
|
+
<TypeRefContext>{param.type}</TypeRefContext>
|
|
134
|
+
</SymbolSlot>
|
|
131
135
|
</indent>
|
|
132
136
|
</Show>
|
|
133
137
|
</group>
|
|
@@ -178,11 +182,12 @@ function normalizeAndDeclareParameters(
|
|
|
178
182
|
}
|
|
179
183
|
if (typeof parameters[0] === "string") {
|
|
180
184
|
return (parameters as string[]).map((paramName) => {
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
const name = namePolicy.getName(
|
|
186
|
+
paramName,
|
|
187
|
+
flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const symbol = new TSOutputSymbol(name, {
|
|
186
191
|
tsFlags: flags,
|
|
187
192
|
});
|
|
188
193
|
|
|
@@ -195,15 +200,17 @@ function normalizeAndDeclareParameters(
|
|
|
195
200
|
TSSymbolFlags.Nullish
|
|
196
201
|
: TSSymbolFlags.None;
|
|
197
202
|
|
|
198
|
-
const symbol =
|
|
199
|
-
|
|
203
|
+
const symbol = new TSOutputSymbol(
|
|
204
|
+
namePolicy.getName(
|
|
200
205
|
param.name,
|
|
201
206
|
flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
|
|
202
207
|
),
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
208
|
+
{
|
|
209
|
+
refkeys: param.refkey,
|
|
210
|
+
tsFlags: flags | nullishFlag,
|
|
211
|
+
metadata: param.metadata,
|
|
212
|
+
},
|
|
213
|
+
);
|
|
207
214
|
|
|
208
215
|
return {
|
|
209
216
|
...param,
|
|
@@ -236,7 +243,7 @@ export const TypeParameters = taggedComponent(
|
|
|
236
243
|
|
|
237
244
|
onCleanup(() => {
|
|
238
245
|
for (const param of typeParameters) {
|
|
239
|
-
param.symbol.
|
|
246
|
+
param.symbol.delete();
|
|
240
247
|
}
|
|
241
248
|
});
|
|
242
249
|
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
Prose,
|
|
7
7
|
Scope,
|
|
8
8
|
Show,
|
|
9
|
+
type Children,
|
|
9
10
|
} from "@alloy-js/core";
|
|
10
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
11
11
|
import { getCallSignatureProps } from "../utils.js";
|
|
12
12
|
import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
|
|
13
13
|
import { BaseDeclarationProps, Declaration } from "./Declaration.js";
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
findKeyedChild,
|
|
4
4
|
findUnkeyedChildren,
|
|
5
5
|
Scope,
|
|
6
|
+
type Children,
|
|
6
7
|
} from "@alloy-js/core";
|
|
7
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
8
8
|
import { getCallSignatureProps } from "../utils.js";
|
|
9
9
|
import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
|
|
10
10
|
import { Declaration } from "./Declaration.jsx";
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
Prose,
|
|
5
5
|
Scope,
|
|
6
6
|
Show,
|
|
7
|
+
type Children,
|
|
7
8
|
} from "@alloy-js/core";
|
|
8
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
9
9
|
import { getCallSignatureProps } from "../utils.js";
|
|
10
10
|
import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
|
|
11
11
|
import {
|
|
@@ -61,7 +61,7 @@ export const InterfaceExpression = ensureTypeRefContext(
|
|
|
61
61
|
const parentMemberSym = useMemberDeclaration();
|
|
62
62
|
|
|
63
63
|
if (parentMemberSym) {
|
|
64
|
-
parentMemberSym.
|
|
64
|
+
parentMemberSym.flags |= OutputSymbolFlags.StaticMemberContainer;
|
|
65
65
|
}
|
|
66
66
|
return (
|
|
67
67
|
<group>
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
Refkey,
|
|
7
7
|
Scope,
|
|
8
8
|
Show,
|
|
9
|
+
type Children,
|
|
9
10
|
} from "@alloy-js/core";
|
|
10
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
11
11
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
12
12
|
import { getCallSignatureProps } from "../utils.js";
|
|
13
13
|
import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
|
package/src/components/JSDoc.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { For, Prose, Show } from "@alloy-js/core";
|
|
2
|
-
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
1
|
+
import { For, Prose, Show, type Children } from "@alloy-js/core";
|
|
3
2
|
import { ParameterDescriptor } from "../parameter-descriptor.js";
|
|
4
3
|
|
|
5
4
|
export interface JSDocParamsProps {
|
|
@@ -4,11 +4,7 @@ import {
|
|
|
4
4
|
OutputSymbolFlags,
|
|
5
5
|
} from "@alloy-js/core";
|
|
6
6
|
import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
|
|
7
|
-
import {
|
|
8
|
-
createTSSymbol,
|
|
9
|
-
TSOutputSymbol,
|
|
10
|
-
TSSymbolFlags,
|
|
11
|
-
} from "../symbols/index.js";
|
|
7
|
+
import { TSOutputSymbol, TSSymbolFlags } from "../symbols/index.js";
|
|
12
8
|
|
|
13
9
|
export interface MemberDeclarationProps
|
|
14
10
|
extends Omit<MemberDeclarationPropsWithInfo, "name"> {
|
|
@@ -61,9 +57,10 @@ export function MemberDeclaration(props: Readonly<MemberDeclarationProps>) {
|
|
|
61
57
|
tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
const name =
|
|
61
|
+
props.exactName ?? namePolicy.getName(props.name!, props.nameKind!);
|
|
62
|
+
sym = new TSOutputSymbol(name, {
|
|
63
|
+
refkeys: props.refkey,
|
|
67
64
|
flags: props.flags,
|
|
68
65
|
tsFlags,
|
|
69
66
|
metadata: props.metadata,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ref,
|
|
10
10
|
Refkey,
|
|
11
11
|
Show,
|
|
12
|
+
takeSymbols,
|
|
12
13
|
ToRefs,
|
|
13
14
|
useBinder,
|
|
14
15
|
} from "@alloy-js/core";
|
|
@@ -20,14 +21,22 @@ export interface MemberExpressionProps {
|
|
|
20
21
|
children: Children;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
interface
|
|
24
|
+
interface PartDescriptorWithId extends PartDescriptorBase {
|
|
24
25
|
id: Children;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface PartDescriptorWithIndex extends PartDescriptorBase {
|
|
29
|
+
index: number;
|
|
30
|
+
}
|
|
31
|
+
interface PartDescriptorBase {
|
|
25
32
|
accessStyle: "dot" | "bracket";
|
|
26
33
|
quoteId: boolean;
|
|
27
34
|
nullish: boolean;
|
|
28
35
|
args?: Children[];
|
|
29
36
|
}
|
|
30
37
|
|
|
38
|
+
type PartDescriptor = PartDescriptorWithId | PartDescriptorWithIndex;
|
|
39
|
+
|
|
31
40
|
/**
|
|
32
41
|
* Create a member expression from parts. Each part can provide one of
|
|
33
42
|
* the following:
|
|
@@ -68,6 +77,9 @@ interface PartDescriptor {
|
|
|
68
77
|
export function MemberExpression(props: MemberExpressionProps): Children {
|
|
69
78
|
const children = flattenMemberExpression(childrenArray(() => props.children));
|
|
70
79
|
const parts = childrenToPartDescriptors(children);
|
|
80
|
+
// any symbols emitted from the children won't be relevant to
|
|
81
|
+
// parent scopes. TODO: emit the proper symbol if we know it?
|
|
82
|
+
takeSymbols();
|
|
71
83
|
|
|
72
84
|
if (parts.length === 0) {
|
|
73
85
|
return <></>;
|
|
@@ -154,12 +166,16 @@ function createPartDescriptorFromProps(
|
|
|
154
166
|
id: computed(() => {
|
|
155
167
|
if (partProps.args) {
|
|
156
168
|
return undefined;
|
|
157
|
-
} else if (
|
|
169
|
+
} else if (partProps.children !== undefined) {
|
|
158
170
|
return partProps.children;
|
|
159
171
|
} else if (first && partProps.refkey) {
|
|
160
172
|
return partProps.refkey;
|
|
161
|
-
} else if (partProps.id) {
|
|
162
|
-
return
|
|
173
|
+
} else if (partProps.id !== undefined) {
|
|
174
|
+
return isNumericIdentifier(partProps.id) ?
|
|
175
|
+
partProps.id
|
|
176
|
+
: escapeId(partProps.id);
|
|
177
|
+
} else if (partProps.index !== undefined) {
|
|
178
|
+
return partProps.index;
|
|
163
179
|
} else if (symbolSource.value) {
|
|
164
180
|
return escapeId(symbolSource.value.name);
|
|
165
181
|
} else {
|
|
@@ -167,13 +183,25 @@ function createPartDescriptorFromProps(
|
|
|
167
183
|
}
|
|
168
184
|
}),
|
|
169
185
|
accessStyle: computed(() => {
|
|
170
|
-
if (partProps.
|
|
186
|
+
if (partProps.children !== undefined) {
|
|
187
|
+
if (typeof partProps.children === "string") {
|
|
188
|
+
return partProps.quoteId ? "bracket" : (
|
|
189
|
+
accessStyleForMemberName(partProps.children)
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return "bracket";
|
|
194
|
+
} else if (partProps.args) {
|
|
171
195
|
// not used
|
|
172
196
|
return "dot";
|
|
173
197
|
} else if (partProps.quoteId) {
|
|
174
198
|
return "bracket";
|
|
175
|
-
} else if (partProps.id) {
|
|
176
|
-
return
|
|
199
|
+
} else if (partProps.id !== undefined) {
|
|
200
|
+
return isNumericIdentifier(partProps.id) ? "bracket" : (
|
|
201
|
+
accessStyleForMemberName(partProps.id)
|
|
202
|
+
);
|
|
203
|
+
} else if (partProps.index !== undefined) {
|
|
204
|
+
return "bracket";
|
|
177
205
|
} else if (symbolSource.value) {
|
|
178
206
|
return accessStyleForMemberName(symbolSource.value.name);
|
|
179
207
|
} else {
|
|
@@ -183,8 +211,10 @@ function createPartDescriptorFromProps(
|
|
|
183
211
|
quoteId: computed(() => {
|
|
184
212
|
if (partProps.quoteId) {
|
|
185
213
|
return partProps.quoteId;
|
|
186
|
-
} else if (partProps.id) {
|
|
187
|
-
return
|
|
214
|
+
} else if (partProps.id !== undefined) {
|
|
215
|
+
return isNumericIdentifier(partProps.id) ? false : (
|
|
216
|
+
!isValidJSIdentifier(partProps.id)
|
|
217
|
+
);
|
|
188
218
|
} else if (symbolSource.value) {
|
|
189
219
|
return !isValidJSIdentifier(symbolSource.value.name);
|
|
190
220
|
} else {
|
|
@@ -220,7 +250,7 @@ function escapeId(id: string) {
|
|
|
220
250
|
*/
|
|
221
251
|
function getSymbolForRefkey(refkey: Refkey) {
|
|
222
252
|
const binder = useBinder();
|
|
223
|
-
return binder
|
|
253
|
+
return binder!.getSymbolForRefkey(refkey);
|
|
224
254
|
}
|
|
225
255
|
|
|
226
256
|
/**
|
|
@@ -303,7 +333,9 @@ function formatCallChain(parts: PartDescriptor[]): Children {
|
|
|
303
333
|
for (let partIndex = 0; partIndex < chunk.length; partIndex++) {
|
|
304
334
|
if (chunkIndex === 0 && partIndex === 0) {
|
|
305
335
|
// first part is just gonna be the id
|
|
306
|
-
|
|
336
|
+
const firstPart =
|
|
337
|
+
isIdPartDescriptor(chunk[0]) ? chunk[0].id : chunk[0].index;
|
|
338
|
+
chunkExpression.push(firstPart);
|
|
307
339
|
continue;
|
|
308
340
|
}
|
|
309
341
|
const part = chunk[partIndex];
|
|
@@ -347,7 +379,7 @@ function formatNonCallChain(parts: PartDescriptor[]): Children {
|
|
|
347
379
|
|
|
348
380
|
for (let i = 0; i < parts.length; i++) {
|
|
349
381
|
const part = parts[i];
|
|
350
|
-
const base = part.id;
|
|
382
|
+
const base = isIdPartDescriptor(part) ? part.id : part.index;
|
|
351
383
|
if (i === 0) {
|
|
352
384
|
expression.push(base);
|
|
353
385
|
} else {
|
|
@@ -377,7 +409,7 @@ function formatArrayAccess(prevPart: PartDescriptor, part: PartDescriptor) {
|
|
|
377
409
|
<indent>
|
|
378
410
|
<sbr />
|
|
379
411
|
{part.quoteId && '"'}
|
|
380
|
-
{part.id}
|
|
412
|
+
{isIdPartDescriptor(part) ? part.id : part.index}
|
|
381
413
|
{part.quoteId && '"'}
|
|
382
414
|
</indent>
|
|
383
415
|
<sbr />]
|
|
@@ -391,7 +423,7 @@ function formatDotAccess(prevPart: PartDescriptor, part: PartDescriptor) {
|
|
|
391
423
|
<indent>
|
|
392
424
|
<sbr />
|
|
393
425
|
{prevPart.nullish ? "?." : "."}
|
|
394
|
-
{part.id}
|
|
426
|
+
{isIdPartDescriptor(part) ? part.id : part.index}
|
|
395
427
|
</indent>
|
|
396
428
|
</group>
|
|
397
429
|
);
|
|
@@ -445,7 +477,13 @@ export interface MemberExpressionPartProps {
|
|
|
445
477
|
/**
|
|
446
478
|
* The identifier for this part of the member expression.
|
|
447
479
|
*/
|
|
448
|
-
id?: string;
|
|
480
|
+
id?: string | number;
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* The index for this part of the member expression. This is used when
|
|
484
|
+
* the part is an array access (i.e. `foo[0]`).
|
|
485
|
+
*/
|
|
486
|
+
index?: number;
|
|
449
487
|
|
|
450
488
|
/**
|
|
451
489
|
* Whether the identifier should be quoted or not. Only needed when
|
|
@@ -501,3 +539,17 @@ MemberExpression.Part = function (props: MemberExpressionPartProps) {
|
|
|
501
539
|
* the `MemberExpression` component.
|
|
502
540
|
*/
|
|
503
541
|
};
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Check if the given id is a numeric identifier.
|
|
545
|
+
*
|
|
546
|
+
*/
|
|
547
|
+
function isNumericIdentifier(id: Children) {
|
|
548
|
+
return typeof id === "number";
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function isIdPartDescriptor(
|
|
552
|
+
part: PartDescriptor,
|
|
553
|
+
): part is PartDescriptorWithId {
|
|
554
|
+
return "id" in part;
|
|
555
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
emitSymbol,
|
|
3
|
+
instantiateTakenMembersTo as instantiateTakenSymbolsTo,
|
|
4
|
+
OutputSymbolFlags,
|
|
5
|
+
} from "@alloy-js/core";
|
|
6
|
+
import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
|
|
7
|
+
import {
|
|
8
|
+
FunctionCallExpression,
|
|
9
|
+
FunctionCallExpressionProps,
|
|
10
|
+
} from "./FunctionCallExpression.jsx";
|
|
11
|
+
|
|
12
|
+
export interface NewExpressionProps extends FunctionCallExpressionProps {}
|
|
13
|
+
|
|
14
|
+
export function NewExpression(props: NewExpressionProps) {
|
|
15
|
+
const sym = new TSOutputSymbol("", {
|
|
16
|
+
flags: OutputSymbolFlags.Transient,
|
|
17
|
+
});
|
|
18
|
+
instantiateTakenSymbolsTo(sym);
|
|
19
|
+
emitSymbol(sym);
|
|
20
|
+
return (
|
|
21
|
+
<>
|
|
22
|
+
new <FunctionCallExpression {...props} />
|
|
23
|
+
</>
|
|
24
|
+
);
|
|
25
|
+
}
|