@alloy-js/typescript 0.10.0 → 0.12.0
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 +28 -0
- package/dist/src/builtins/node.js +1 -2
- package/dist/src/components/ArrayExpression.js +2 -5
- package/dist/src/components/ArrowFunction.d.ts +40 -0
- package/dist/src/components/ArrowFunction.d.ts.map +1 -0
- package/dist/src/components/ArrowFunction.js +67 -0
- package/dist/src/components/BarrelFile.js +1 -2
- package/dist/src/components/BlockScope.js +2 -4
- package/dist/src/components/CallSignature.js +2 -4
- package/dist/src/components/ClassDeclaration.d.ts +2 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +16 -8
- package/dist/src/components/CommaList.js +2 -5
- package/dist/src/components/Declaration.js +3 -5
- package/dist/src/components/EnumDeclaration.js +2 -5
- package/dist/src/components/EnumMember.js +2 -4
- package/dist/src/components/ExportStatement.js +1 -2
- package/dist/src/components/FunctionBase.d.ts +60 -0
- package/dist/src/components/FunctionBase.d.ts.map +1 -0
- package/dist/src/components/FunctionBase.js +217 -0
- package/dist/src/components/FunctionCallExpression.js +2 -5
- package/dist/src/components/FunctionDeclaration.d.ts +3 -18
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +9 -157
- package/dist/src/components/FunctionExpression.d.ts +39 -0
- package/dist/src/components/FunctionExpression.d.ts.map +1 -0
- package/dist/src/components/FunctionExpression.js +66 -0
- package/dist/src/components/FunctionType.d.ts +38 -0
- package/dist/src/components/FunctionType.d.ts.map +1 -0
- package/dist/src/components/FunctionType.js +77 -0
- package/dist/src/components/IfStatement.js +2 -4
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +10 -4
- package/dist/src/components/Interface.d.ts +3 -2
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +40 -15
- package/dist/src/components/InterfaceMethod.d.ts +43 -0
- package/dist/src/components/InterfaceMethod.d.ts.map +1 -0
- package/dist/src/components/InterfaceMethod.js +87 -0
- package/dist/src/components/JSDoc.js +1 -2
- package/dist/src/components/JSDocComment.js +3 -5
- package/dist/src/components/JSDocExample.js +2 -5
- package/dist/src/components/JSDocParam.js +2 -5
- package/dist/src/components/MemberChainExpression.js +2 -4
- package/dist/src/components/MemberDeclaration.d.ts +34 -0
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -0
- package/dist/src/components/MemberDeclaration.js +29 -0
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +5 -7
- package/dist/src/components/ObjectExpression.js +2 -5
- package/dist/src/components/PackageDirectory.js +2 -5
- package/dist/src/components/PackageJson.js +1 -2
- package/dist/src/components/PropertyName.js +1 -2
- package/dist/src/components/Reference.d.ts +8 -1
- package/dist/src/components/Reference.d.ts.map +1 -1
- package/dist/src/components/Reference.js +8 -4
- package/dist/src/components/SingleLineCommentBlock.js +2 -4
- package/dist/src/components/SourceFile.js +2 -4
- package/dist/src/components/SwitchStatement.js +2 -5
- package/dist/src/components/TsConfigJson.js +1 -2
- package/dist/src/components/TypeDeclaration.d.ts +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js +4 -7
- package/dist/src/components/TypeRefContext.d.ts +22 -0
- package/dist/src/components/TypeRefContext.d.ts.map +1 -0
- package/dist/src/components/TypeRefContext.js +41 -0
- package/dist/src/components/ValueExpression.js +1 -2
- package/dist/src/components/VarDeclaration.d.ts +1 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +11 -8
- package/dist/src/components/index.d.ts +7 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +7 -1
- package/dist/src/components/stc/index.d.ts +8 -0
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +9 -2
- package/dist/src/context/private-scope.js +1 -2
- package/dist/src/context/type-ref-context.d.ts +15 -0
- package/dist/src/context/type-ref-context.d.ts.map +1 -0
- package/dist/src/context/type-ref-context.js +12 -0
- package/dist/src/create-package.js +1 -2
- package/dist/src/index.js +1 -2
- package/dist/src/name-conflict-resolver.js +1 -2
- package/dist/src/name-policy.js +1 -2
- package/dist/src/parameter-descriptor.d.ts +33 -17
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/src/source-directory-data.js +1 -2
- package/dist/src/symbols/index.js +1 -2
- package/dist/src/symbols/reference.d.ts +4 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +13 -8
- package/dist/src/symbols/scopes.js +1 -2
- package/dist/src/symbols/ts-member-scope.js +1 -2
- package/dist/src/symbols/ts-module-scope.d.ts +4 -1
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +11 -5
- package/dist/src/symbols/ts-output-symbol.d.ts +2 -1
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +2 -2
- package/dist/src/symbols/ts-package-scope.js +1 -2
- package/dist/src/utils.js +1 -2
- package/dist/test/array.test.js +105 -0
- package/dist/test/arrow-function.test.d.ts +2 -0
- package/dist/test/arrow-function.test.d.ts.map +1 -0
- package/dist/test/arrow-function.test.js +194 -0
- package/dist/test/barrel.test.js +53 -0
- package/dist/test/basic.test.js +91 -0
- package/dist/test/block-scope.test.js +30 -0
- package/dist/test/class.test.js +438 -0
- package/dist/test/enum-jsdoc.test.js +88 -0
- package/dist/test/enum.test.js +247 -0
- package/dist/test/externals.test.js +145 -0
- package/dist/test/function-call-expression.test.js +87 -0
- package/dist/test/function-declaration-jsdoc.test.js +91 -0
- package/dist/test/function-declaration.test.js +228 -0
- package/dist/test/function-expression.test.d.ts +2 -0
- package/dist/test/function-expression.test.d.ts.map +1 -0
- package/dist/test/function-expression.test.js +194 -0
- package/dist/test/function-type.test.d.ts +2 -0
- package/dist/test/function-type.test.d.ts.map +1 -0
- package/dist/test/function-type.test.js +122 -0
- package/dist/test/if-statement.test.js +25 -0
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/imports.test.js +640 -0
- package/dist/test/interface-jsdoc.test.js +178 -0
- package/dist/test/interface.test.d.ts.map +1 -1
- package/dist/test/interface.test.js +490 -0
- package/dist/test/jscomment.test.js +70 -0
- package/dist/test/jsdoc.test.js +134 -0
- package/dist/test/jsdocparam.test.js +164 -0
- package/dist/test/member-chain.test.js +141 -0
- package/dist/test/member-expression.test.js +575 -0
- package/dist/test/name-conflict.test.js +108 -0
- package/dist/test/name-policy.test.js +122 -0
- package/dist/test/package-external.test.js +196 -0
- package/dist/test/package-json.test.js +93 -0
- package/dist/test/package.test.js +136 -0
- package/dist/test/reference.test.js +81 -0
- package/dist/test/source-file.test.js +36 -0
- package/dist/test/switch-statement.test.js +61 -0
- package/dist/test/utils.js +45 -0
- package/dist/test/value-expression.test.js +30 -0
- package/dist/test/values.test.js +351 -0
- package/dist/test/var-declaration-jsdoc.test.js +50 -0
- package/dist/test/var-declaration.test.js +63 -0
- package/dist/test/vitest.d.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -18
- package/src/components/ArrowFunction.tsx +87 -0
- package/src/components/ClassDeclaration.tsx +19 -3
- package/src/components/Declaration.tsx +1 -1
- package/src/components/FunctionBase.tsx +282 -0
- package/src/components/FunctionDeclaration.tsx +13 -195
- package/src/components/FunctionExpression.tsx +86 -0
- package/src/components/FunctionType.tsx +93 -0
- package/src/components/ImportStatement.tsx +30 -3
- package/src/components/Interface.tsx +58 -23
- package/src/components/InterfaceMethod.tsx +96 -0
- package/src/components/JSDocComment.tsx +1 -1
- package/src/components/MemberDeclaration.tsx +76 -0
- package/src/components/MemberExpression.tsx +7 -2
- package/src/components/Reference.tsx +12 -2
- package/src/components/TypeDeclaration.tsx +16 -13
- package/src/components/TypeRefContext.tsx +49 -0
- package/src/components/VarDeclaration.tsx +6 -2
- package/src/components/index.ts +11 -0
- package/src/components/stc/index.ts +8 -0
- package/src/context/type-ref-context.tsx +19 -0
- package/src/parameter-descriptor.ts +35 -17
- package/src/symbols/reference.ts +21 -6
- package/src/symbols/ts-module-scope.ts +19 -4
- package/src/symbols/ts-output-symbol.ts +1 -0
- package/temp/api.json +4999 -2681
- package/test/arrow-function.test.tsx +188 -0
- package/test/class.test.tsx +5 -6
- package/test/enum-jsdoc.test.tsx +6 -6
- package/test/function-call-expression.test.tsx +1 -2
- package/test/function-declaration-jsdoc.test.tsx +3 -3
- package/test/function-declaration.test.tsx +1 -2
- package/test/function-expression.test.tsx +195 -0
- package/test/function-type.test.tsx +118 -0
- package/test/imports.test.tsx +165 -1
- package/test/interface-jsdoc.test.tsx +9 -9
- package/test/interface.test.tsx +256 -6
- package/test/jsdoc.test.tsx +5 -5
- package/test/jsdocparam.test.tsx +8 -8
- package/test/member-expression.test.tsx +171 -2
- package/test/var-declaration-jsdoc.test.tsx +3 -3
- package/test/var-declaration.test.tsx +1 -1
- package/tsdoc-metadata.json +1 -1
- package/babel.config.cjs +0 -4
- package/dist/src/builtins/index.js.map +0 -1
- package/dist/src/builtins/node.js.map +0 -1
- package/dist/src/components/ArrayExpression.js.map +0 -1
- package/dist/src/components/BarrelFile.js.map +0 -1
- package/dist/src/components/BlockScope.js.map +0 -1
- package/dist/src/components/CallSignature.js.map +0 -1
- package/dist/src/components/ClassDeclaration.js.map +0 -1
- package/dist/src/components/CommaList.js.map +0 -1
- package/dist/src/components/Declaration.js.map +0 -1
- package/dist/src/components/EnumDeclaration.js.map +0 -1
- package/dist/src/components/EnumMember.js.map +0 -1
- package/dist/src/components/ExportStatement.js.map +0 -1
- package/dist/src/components/FunctionCallExpression.js.map +0 -1
- package/dist/src/components/FunctionDeclaration.js.map +0 -1
- package/dist/src/components/IfStatement.js.map +0 -1
- package/dist/src/components/ImportStatement.js.map +0 -1
- package/dist/src/components/Interface.js.map +0 -1
- package/dist/src/components/JSDoc.js.map +0 -1
- package/dist/src/components/JSDocComment.js.map +0 -1
- package/dist/src/components/JSDocExample.js.map +0 -1
- package/dist/src/components/JSDocParam.js.map +0 -1
- package/dist/src/components/MemberChainExpression.js.map +0 -1
- package/dist/src/components/MemberExpression.js.map +0 -1
- package/dist/src/components/ObjectExpression.js.map +0 -1
- package/dist/src/components/PackageDirectory.js.map +0 -1
- package/dist/src/components/PackageJson.js.map +0 -1
- package/dist/src/components/PropertyName.js.map +0 -1
- package/dist/src/components/Reference.js.map +0 -1
- package/dist/src/components/SingleLineCommentBlock.js.map +0 -1
- package/dist/src/components/SourceFile.js.map +0 -1
- package/dist/src/components/SwitchStatement.js.map +0 -1
- package/dist/src/components/TsConfigJson.js.map +0 -1
- package/dist/src/components/TypeDeclaration.js.map +0 -1
- package/dist/src/components/ValueExpression.js.map +0 -1
- package/dist/src/components/VarDeclaration.js.map +0 -1
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/components/stc/index.js.map +0 -1
- package/dist/src/context/index.js.map +0 -1
- package/dist/src/context/private-scope.js.map +0 -1
- package/dist/src/create-package.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/name-conflict-resolver.js.map +0 -1
- package/dist/src/name-policy.js.map +0 -1
- package/dist/src/parameter-descriptor.js.map +0 -1
- package/dist/src/source-directory-data.js.map +0 -1
- package/dist/src/symbols/index.js.map +0 -1
- package/dist/src/symbols/reference.js.map +0 -1
- package/dist/src/symbols/scopes.js.map +0 -1
- package/dist/src/symbols/ts-member-scope.js.map +0 -1
- package/dist/src/symbols/ts-module-scope.js.map +0 -1
- package/dist/src/symbols/ts-output-symbol.js.map +0 -1
- package/dist/src/symbols/ts-package-scope.js.map +0 -1
- package/dist/src/utils.js.map +0 -1
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
Show,
|
|
8
8
|
} from "@alloy-js/core";
|
|
9
9
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
10
|
-
import { createTSSymbol } from "../symbols/index.js";
|
|
10
|
+
import { createTSSymbol, TSSymbolFlags } from "../symbols/index.js";
|
|
11
11
|
import { BaseDeclarationProps } from "./Declaration.js";
|
|
12
12
|
import { JSDoc } from "./JSDoc.jsx";
|
|
13
|
+
import { TypeRefContext } from "./TypeRefContext.jsx";
|
|
13
14
|
|
|
14
15
|
export interface VarDeclarationProps extends BaseDeclarationProps {
|
|
15
16
|
const?: boolean;
|
|
@@ -17,6 +18,7 @@ export interface VarDeclarationProps extends BaseDeclarationProps {
|
|
|
17
18
|
var?: boolean;
|
|
18
19
|
initializer?: Children;
|
|
19
20
|
type?: Children;
|
|
21
|
+
nullish?: boolean;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export function VarDeclaration(props: VarDeclarationProps) {
|
|
@@ -24,7 +26,8 @@ export function VarDeclaration(props: VarDeclarationProps) {
|
|
|
24
26
|
props.var ? "var"
|
|
25
27
|
: props.let ? "let"
|
|
26
28
|
: "const";
|
|
27
|
-
const type =
|
|
29
|
+
const type =
|
|
30
|
+
props.type ? <TypeRefContext>: {props.type}</TypeRefContext> : undefined;
|
|
28
31
|
const name = useTSNamePolicy().getName(props.name, "variable");
|
|
29
32
|
const sym = createTSSymbol({
|
|
30
33
|
name: name,
|
|
@@ -32,6 +35,7 @@ export function VarDeclaration(props: VarDeclarationProps) {
|
|
|
32
35
|
default: props.default,
|
|
33
36
|
export: props.export,
|
|
34
37
|
metadata: props.metadata,
|
|
38
|
+
tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None,
|
|
35
39
|
});
|
|
36
40
|
|
|
37
41
|
const assignmentContext = createAssignmentContext(sym);
|
package/src/components/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "../parameter-descriptor.js";
|
|
2
2
|
export * from "./ArrayExpression.js";
|
|
3
|
+
export * from "./ArrowFunction.jsx";
|
|
3
4
|
export * from "./BarrelFile.js";
|
|
4
5
|
export * from "./BlockScope.js";
|
|
5
6
|
export * from "./CallSignature.jsx";
|
|
@@ -9,10 +10,19 @@ export * from "./Declaration.js";
|
|
|
9
10
|
export * from "./EnumDeclaration.js";
|
|
10
11
|
export * from "./EnumMember.js";
|
|
11
12
|
export * from "./ExportStatement.js";
|
|
13
|
+
export {
|
|
14
|
+
type FunctionBodyProps,
|
|
15
|
+
type FunctionParametersProps,
|
|
16
|
+
type FunctionTypeParametersProps,
|
|
17
|
+
} from "./FunctionBase.js";
|
|
12
18
|
export * from "./FunctionCallExpression.js";
|
|
13
19
|
export * from "./FunctionDeclaration.js";
|
|
20
|
+
export * from "./FunctionExpression.js";
|
|
21
|
+
export * from "./FunctionType.jsx";
|
|
22
|
+
export * from "./IfStatement.jsx";
|
|
14
23
|
export * from "./ImportStatement.js";
|
|
15
24
|
export * from "./Interface.js";
|
|
25
|
+
export * from "./InterfaceMethod.jsx";
|
|
16
26
|
export * from "./JSDoc.jsx";
|
|
17
27
|
export * from "./JSDocComment.jsx";
|
|
18
28
|
export * from "./JSDocExample.jsx";
|
|
@@ -26,5 +36,6 @@ export * from "./SourceFile.js";
|
|
|
26
36
|
export * from "./SwitchStatement.jsx";
|
|
27
37
|
export * from "./TsConfigJson.js";
|
|
28
38
|
export * from "./TypeDeclaration.js";
|
|
39
|
+
export * from "./TypeRefContext.jsx";
|
|
29
40
|
export * from "./ValueExpression.js";
|
|
30
41
|
export * from "./VarDeclaration.js";
|
|
@@ -2,6 +2,7 @@ import { stc } from "@alloy-js/core";
|
|
|
2
2
|
import * as base from "../index.js";
|
|
3
3
|
|
|
4
4
|
export const ArrayExpression = stc(base.ArrayExpression);
|
|
5
|
+
export const ArrowFunction = stc(base.ArrowFunction);
|
|
5
6
|
export const BarrelFile = stc(base.BarrelFile);
|
|
6
7
|
export const CallSignature = stc(base.CallSignature);
|
|
7
8
|
export const ClassDeclaration = stc(base.ClassDeclaration);
|
|
@@ -15,11 +16,16 @@ export const EnumMember = stc(base.EnumMember);
|
|
|
15
16
|
export const ExportStatement = stc(base.ExportStatement);
|
|
16
17
|
export const FunctionCallExpression = stc(base.FunctionCallExpression);
|
|
17
18
|
export const FunctionDeclaration = stc(base.FunctionDeclaration);
|
|
19
|
+
export const FunctionExpression = stc(base.FunctionExpression);
|
|
20
|
+
export const IfStatement = stc(base.IfStatement);
|
|
21
|
+
export const ElseClause = stc(base.ElseClause);
|
|
22
|
+
export const ElseIfClause = stc(base.ElseIfClause);
|
|
18
23
|
export const ImportStatement = stc(base.ImportStatement);
|
|
19
24
|
export const ImportStatements = stc(base.ImportStatements);
|
|
20
25
|
export const InterfaceDeclaration = stc(base.InterfaceDeclaration);
|
|
21
26
|
export const InterfaceExpression = stc(base.InterfaceExpression);
|
|
22
27
|
export const InterfaceMember = stc(base.InterfaceMember);
|
|
28
|
+
export const InterfaceMethod = stc(base.InterfaceMethod);
|
|
23
29
|
export const JSDoc = stc(base.JSDoc);
|
|
24
30
|
export const JSDocExample = stc(base.JSDocExample);
|
|
25
31
|
export const JSDocComment = stc(base.JSDocComment);
|
|
@@ -34,6 +40,8 @@ export const SourceFile = stc(base.SourceFile);
|
|
|
34
40
|
export const SwitchStatement = stc(base.SwitchStatement);
|
|
35
41
|
export const CaseClause = stc(base.CaseClause);
|
|
36
42
|
export const TSConfigJson = stc(base.TSConfigJson);
|
|
43
|
+
export const FunctionType = stc(base.FunctionType);
|
|
37
44
|
export const TypeDeclaration = stc(base.TypeDeclaration);
|
|
45
|
+
export const TypeRefContext = stc(base.TypeRefContext);
|
|
38
46
|
export const ValueExpression = stc(base.ValueExpression);
|
|
39
47
|
export const VarDeclaration = stc(base.VarDeclaration);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComponentContext, createContext, useContext } from "@alloy-js/core";
|
|
2
|
+
|
|
3
|
+
interface TypeRefContext {
|
|
4
|
+
/** If in a type context */
|
|
5
|
+
type?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Provides scopes for instance and static private members.
|
|
10
|
+
*/
|
|
11
|
+
export const TypeRefContext: ComponentContext<TypeRefContext> =
|
|
12
|
+
createContext<TypeRefContext>();
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @returns 'true' if in a type context, 'false' if in a value context.
|
|
16
|
+
*/
|
|
17
|
+
export function isTypeRefContext(): boolean {
|
|
18
|
+
return useContext(TypeRefContext)?.type ?? false;
|
|
19
|
+
}
|
|
@@ -1,45 +1,63 @@
|
|
|
1
1
|
import { Children, Refkey } from "@alloy-js/core";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Common properties for ParameterDescriptor and FunctionTypeParameterDescriptor.
|
|
5
5
|
*/
|
|
6
|
-
export interface
|
|
6
|
+
export interface ParameterDescriptorBase {
|
|
7
7
|
/**
|
|
8
8
|
* The name of the parameter.
|
|
9
9
|
*/
|
|
10
|
-
name: string;
|
|
10
|
+
readonly name: string;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The type of the parameter.
|
|
14
14
|
*/
|
|
15
|
-
type?: Children;
|
|
15
|
+
readonly type?: Children;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* The
|
|
18
|
+
* The refkey for this parameter.
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
readonly refkey?: Refkey | Refkey[];
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Whether the parameter is optional.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
readonly optional?: boolean;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Whether the parameter is
|
|
28
|
+
* Whether the parameter is can be null or undefined.
|
|
29
|
+
* when optional is true, this will be set to true by default,
|
|
30
|
+
* but explicitly setting this to false will override that.
|
|
29
31
|
*/
|
|
30
|
-
|
|
32
|
+
readonly nullish?: boolean;
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* Arbitrary metadata for the parameter symbol.
|
|
34
36
|
*/
|
|
35
|
-
metadata?: Record<string, unknown>;
|
|
37
|
+
readonly metadata?: Record<string, unknown>;
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* Documentation for the parameter.
|
|
39
41
|
*/
|
|
40
|
-
doc?: Children;
|
|
42
|
+
readonly doc?: Children;
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Information for a TypeScript function parameter.
|
|
47
|
+
*/
|
|
48
|
+
export interface ParameterDescriptor extends ParameterDescriptorBase {
|
|
49
|
+
/**
|
|
50
|
+
* The default value of the parameter.
|
|
51
|
+
*/
|
|
52
|
+
readonly default?: Children;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Information for a TypeScript type function parameter.
|
|
57
|
+
*/
|
|
58
|
+
export interface FunctionTypeParameterDescriptor
|
|
59
|
+
extends ParameterDescriptorBase {}
|
|
60
|
+
|
|
43
61
|
/**
|
|
44
62
|
* Information for a TypeScript generic type parameter.
|
|
45
63
|
*/
|
|
@@ -47,25 +65,25 @@ export interface TypeParameterDescriptor {
|
|
|
47
65
|
/**
|
|
48
66
|
* The name of the type parameter.
|
|
49
67
|
*/
|
|
50
|
-
name: string;
|
|
68
|
+
readonly name: string;
|
|
51
69
|
|
|
52
70
|
/**
|
|
53
71
|
* The extends constraint for the type parameter.
|
|
54
72
|
*/
|
|
55
|
-
extends?: Children;
|
|
73
|
+
readonly extends?: Children;
|
|
56
74
|
|
|
57
75
|
/**
|
|
58
76
|
* The default type of the type parameter.
|
|
59
77
|
*/
|
|
60
|
-
default?: Children;
|
|
78
|
+
readonly default?: Children;
|
|
61
79
|
|
|
62
80
|
/**
|
|
63
81
|
* A refkey or array of refkeys for this type parameter.
|
|
64
82
|
*/
|
|
65
|
-
refkey?: Refkey | Refkey[];
|
|
83
|
+
readonly refkey?: Refkey | Refkey[];
|
|
66
84
|
|
|
67
85
|
/**
|
|
68
86
|
* Arbitrary metadata for the type parameter symbol.
|
|
69
87
|
*/
|
|
70
|
-
metadata?: Record<string, unknown>;
|
|
88
|
+
readonly metadata?: Record<string, unknown>;
|
|
71
89
|
}
|
package/src/symbols/reference.ts
CHANGED
|
@@ -20,7 +20,10 @@ import { TSModuleScope } from "./ts-module-scope.js";
|
|
|
20
20
|
import { TSOutputSymbol, TSSymbolFlags } from "./ts-output-symbol.js";
|
|
21
21
|
import { TSPackageScope } from "./ts-package-scope.js";
|
|
22
22
|
|
|
23
|
-
export
|
|
23
|
+
export interface RefOptions {
|
|
24
|
+
type?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export function ref(refkey: Refkey, options?: RefOptions): () => string {
|
|
24
27
|
const sourceFile = useContext(SourceFileContext);
|
|
25
28
|
const resolveResult = resolve<TSOutputScope, TSOutputSymbol>(
|
|
26
29
|
refkey as Refkey,
|
|
@@ -103,8 +106,13 @@ export function ref(refkey: Refkey): () => string {
|
|
|
103
106
|
];
|
|
104
107
|
|
|
105
108
|
const importSymbol = symbolPath[0];
|
|
109
|
+
|
|
106
110
|
localSymbol = untrack(() =>
|
|
107
|
-
sourceFile!.scope.addImport(
|
|
111
|
+
sourceFile!.scope.addImport(
|
|
112
|
+
importSymbol,
|
|
113
|
+
pathDown[0] as TSModuleScope,
|
|
114
|
+
{ type: options?.type },
|
|
115
|
+
),
|
|
108
116
|
);
|
|
109
117
|
}
|
|
110
118
|
|
|
@@ -131,14 +139,21 @@ function buildMemberExpression(path: TSOutputSymbol[]) {
|
|
|
131
139
|
path = path.slice(1);
|
|
132
140
|
}
|
|
133
141
|
|
|
142
|
+
let prevNullish = base.tsFlags & TSSymbolFlags.Nullish;
|
|
134
143
|
for (const sym of path) {
|
|
144
|
+
const optional = prevNullish ? "?" : "";
|
|
135
145
|
if (sym.tsFlags & TSSymbolFlags.PrivateMember) {
|
|
136
|
-
memberExpr +=
|
|
137
|
-
} else if (
|
|
138
|
-
|
|
146
|
+
memberExpr += `${optional}.#${sym.name}`;
|
|
147
|
+
} else if (
|
|
148
|
+
isValidJSIdentifier(sym.name) &&
|
|
149
|
+
!(sym.tsFlags & TSSymbolFlags.TypeSymbol)
|
|
150
|
+
) {
|
|
151
|
+
memberExpr += `${optional}.${sym.name}`;
|
|
139
152
|
} else {
|
|
140
|
-
|
|
153
|
+
const joiner = sym.tsFlags & TSSymbolFlags.Nullish ? "?." : "";
|
|
154
|
+
memberExpr += `${joiner}[${JSON.stringify(sym.name)}]`;
|
|
141
155
|
}
|
|
156
|
+
prevNullish = sym.tsFlags & TSSymbolFlags.Nullish;
|
|
142
157
|
}
|
|
143
158
|
|
|
144
159
|
return memberExpr;
|
|
@@ -11,6 +11,10 @@ export interface ImportedSymbol {
|
|
|
11
11
|
}
|
|
12
12
|
export type ImportRecords = Map<TSModuleScope, Set<ImportedSymbol>>;
|
|
13
13
|
|
|
14
|
+
export interface AddImportOptions {
|
|
15
|
+
type?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
export interface TSModuleScope extends OutputScope {
|
|
15
19
|
kind: "module";
|
|
16
20
|
exportedSymbols: Map<Refkey, TSOutputSymbol>;
|
|
@@ -19,7 +23,11 @@ export interface TSModuleScope extends OutputScope {
|
|
|
19
23
|
*/
|
|
20
24
|
importedSymbols: Map<TSOutputSymbol, TSOutputSymbol>;
|
|
21
25
|
importedModules: ImportRecords;
|
|
22
|
-
addImport(
|
|
26
|
+
addImport(
|
|
27
|
+
symbol: TSOutputSymbol,
|
|
28
|
+
module: TSModuleScope,
|
|
29
|
+
options?: AddImportOptions,
|
|
30
|
+
): TSOutputSymbol;
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
export function createTSModuleScope(
|
|
@@ -34,9 +42,13 @@ export function createTSModuleScope(
|
|
|
34
42
|
exportedSymbols: new Map(),
|
|
35
43
|
importedSymbols: new Map(),
|
|
36
44
|
importedModules: new Map(),
|
|
37
|
-
addImport(this: TSModuleScope, targetSymbol, targetModule) {
|
|
38
|
-
|
|
39
|
-
|
|
45
|
+
addImport(this: TSModuleScope, targetSymbol, targetModule, options) {
|
|
46
|
+
const existing = this.importedSymbols.get(targetSymbol);
|
|
47
|
+
if (existing) {
|
|
48
|
+
if (!options?.type && existing.tsFlags & TSSymbolFlags.TypeSymbol) {
|
|
49
|
+
existing.tsFlags &= ~TSSymbolFlags.TypeSymbol;
|
|
50
|
+
}
|
|
51
|
+
return existing;
|
|
40
52
|
}
|
|
41
53
|
|
|
42
54
|
if (targetModule.kind !== "module") {
|
|
@@ -54,6 +66,9 @@ export function createTSModuleScope(
|
|
|
54
66
|
refkey: refkey({}),
|
|
55
67
|
tsFlags: TSSymbolFlags.LocalImportSymbol,
|
|
56
68
|
});
|
|
69
|
+
if (options?.type) {
|
|
70
|
+
localSymbol.tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
71
|
+
}
|
|
57
72
|
|
|
58
73
|
this.importedSymbols.set(targetSymbol, localSymbol);
|
|
59
74
|
this.importedModules.get(targetModule)!.add({
|