@alloy-js/typescript 0.11.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 +13 -0
- 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 +14 -2
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +13 -3
- package/dist/src/components/FunctionType.d.ts +7 -8
- package/dist/src/components/FunctionType.d.ts.map +1 -1
- package/dist/src/components/FunctionType.js +29 -25
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +9 -2
- 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 +8 -4
- package/dist/src/components/JSDocComment.js +1 -1
- package/dist/src/components/MemberDeclaration.d.ts +4 -0
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +1 -1
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +3 -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 +7 -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 +3 -2
- 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/VarDeclaration.d.ts +1 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +9 -3
- 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 +1 -0
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +1 -0
- 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/parameter-descriptor.d.ts +6 -0
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- 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 +11 -5
- 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 +10 -3
- 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 +1 -0
- package/dist/test/class.test.js +4 -4
- package/dist/test/enum-jsdoc.test.js +6 -6
- package/dist/test/function-declaration-jsdoc.test.js +3 -3
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/imports.test.js +208 -2
- package/dist/test/interface-jsdoc.test.js +9 -9
- package/dist/test/jsdoc.test.js +5 -5
- package/dist/test/jsdocparam.test.js +8 -8
- package/dist/test/member-expression.test.js +218 -2
- package/dist/test/var-declaration-jsdoc.test.js +3 -3
- package/dist/test/var-declaration.test.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/ClassDeclaration.tsx +19 -3
- package/src/components/FunctionBase.tsx +14 -3
- package/src/components/FunctionType.tsx +45 -40
- package/src/components/ImportStatement.tsx +30 -3
- package/src/components/Interface.tsx +41 -34
- package/src/components/JSDocComment.tsx +1 -1
- package/src/components/MemberDeclaration.tsx +7 -1
- 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 +1 -0
- package/src/components/stc/index.ts +1 -0
- package/src/context/type-ref-context.tsx +19 -0
- package/src/parameter-descriptor.ts +7 -0
- package/src/symbols/reference.ts +17 -5
- package/src/symbols/ts-module-scope.ts +19 -4
- package/src/symbols/ts-output-symbol.ts +1 -0
- package/temp/api.json +613 -220
- package/test/class.test.tsx +4 -4
- package/test/enum-jsdoc.test.tsx +6 -6
- package/test/function-declaration-jsdoc.test.tsx +3 -3
- package/test/imports.test.tsx +165 -1
- package/test/interface-jsdoc.test.tsx +9 -9
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog - @alloy-js/typescript
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- [#121](https://github.com/alloy-framework/alloy/pull/121) JS Doc comment close with `*/` instead of `**/`
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- [#117](https://github.com/alloy-framework/alloy/pull/117) Add nullish to TS Symbol flags
|
|
12
|
+
- [#125](https://github.com/alloy-framework/alloy/pull/125) Automatically enter a type context when inside of interface, function type, type declaration, etc. This allow referenced used in there to automatically add the `type` keyword in the import
|
|
13
|
+
- [#124](https://github.com/alloy-framework/alloy/pull/124) Add `type` prop on `Reference` component to mark this reference as a type only reference allowing imports to be specialized in type import
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
## 0.11.0
|
|
4
17
|
|
|
5
18
|
### Bug Fixes
|
|
@@ -48,10 +48,12 @@ export interface ClassMemberProps {
|
|
|
48
48
|
static?: boolean;
|
|
49
49
|
children?: Children;
|
|
50
50
|
doc?: Children;
|
|
51
|
+
nullish?: boolean;
|
|
51
52
|
}
|
|
52
53
|
export declare function ClassMember(props: ClassMemberProps): Children;
|
|
53
54
|
export interface ClassFieldProps extends ClassMemberProps {
|
|
54
55
|
type?: Children;
|
|
56
|
+
optional?: boolean;
|
|
55
57
|
children?: Children;
|
|
56
58
|
}
|
|
57
59
|
export declare function ClassField(props: ClassFieldProps): Children;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKR,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAe,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"ClassDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/ClassDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKR,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAe,MAAM,mBAAmB,CAAC;AAMtE,MAAM,WAAW,qBAAsB,SAAQ,oBAAoB;IACjE,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,YA6B5D;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAuDlD;AAED,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAiBhD;AAED,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB,EAAE,kBAAkB;IAC5E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,YAwBlD"}
|
|
@@ -9,6 +9,7 @@ import { Declaration } from "./Declaration.js";
|
|
|
9
9
|
import { JSDoc } from "./JSDoc.js";
|
|
10
10
|
import { JSDocParams } from "./JSDocParam.js";
|
|
11
11
|
import { PropertyName } from "./PropertyName.js";
|
|
12
|
+
import { TypeRefContext } from "./TypeRefContext.js";
|
|
12
13
|
/**
|
|
13
14
|
* Create a TypeScript class declaration.
|
|
14
15
|
*
|
|
@@ -99,12 +100,16 @@ export function ClassMember(props) {
|
|
|
99
100
|
const memberScope = useMemberScope();
|
|
100
101
|
scope = props.static ? memberScope.staticMembers : memberScope.instanceMembers;
|
|
101
102
|
}
|
|
103
|
+
let tsFlags = props.jsPrivate ? TSSymbolFlags.PrivateMember : TSSymbolFlags.None;
|
|
104
|
+
if (props.nullish) {
|
|
105
|
+
tsFlags |= TSSymbolFlags.Nullish;
|
|
106
|
+
}
|
|
102
107
|
const sym = createTSSymbol({
|
|
103
108
|
name,
|
|
104
109
|
scope,
|
|
105
110
|
refkey: props.refkey,
|
|
106
111
|
flags,
|
|
107
|
-
tsFlags
|
|
112
|
+
tsFlags
|
|
108
113
|
});
|
|
109
114
|
return [_$createComponent(Show, {
|
|
110
115
|
get when() {
|
|
@@ -125,9 +130,16 @@ export function ClassMember(props) {
|
|
|
125
130
|
})];
|
|
126
131
|
}
|
|
127
132
|
export function ClassField(props) {
|
|
128
|
-
const
|
|
133
|
+
const optionality = props.optional ? "?" : "";
|
|
134
|
+
const typeSection = props.type && [optionality, ": ", _$createComponent(TypeRefContext, {
|
|
135
|
+
get children() {
|
|
136
|
+
return props.type;
|
|
137
|
+
}
|
|
138
|
+
})];
|
|
129
139
|
const initializerSection = props.children && [" = ", _$memo(() => props.children)];
|
|
140
|
+
const nullish = props.nullish ?? props.optional;
|
|
130
141
|
return _$createComponent(ClassMember, _$mergeProps(props, {
|
|
142
|
+
nullish: nullish,
|
|
131
143
|
get children() {
|
|
132
144
|
return [_$createComponent(PropertyName, {}), typeSection, initializerSection];
|
|
133
145
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionBase.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionBase.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,KAAK,EAEV,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"FunctionBase.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionBase.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,KAAK,EAEV,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAYrE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,oCAAoC;AACpC,MAAM,WAAW,uBAAuB;IACtC,iBAAiB;IACjB,QAAQ,CAAC,UAAU,CAAC,EAAE,mBAAmB,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,mBAAmB;IACnB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,iEAAiE;AACjE,MAAM,WAAW,2BAA2B;IAC1C,iBAAiB;IACjB,QAAQ,CAAC,UAAU,CAAC,EAAE,mBAAmB,EAAE,GAAG,MAAM,EAAE,CAAC;IACvD,mBAAmB;IACnB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAED,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,iBAAiB;IACjB,UAAU,CAAC,EAAE,uBAAuB,EAAE,GAAG,MAAM,EAAE,CAAC;IAClD,mBAAmB;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,YAAY,sIAKxB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,kJAmB9B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,0JAmBlC,CAAC;AA+FF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,0IAkC1B,CAAC;AAkBF,wBAAgB,aAAa,CAC3B,UAAU,EAAE,QAAQ,GAAG,SAAS,EAChC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAqB,YAKhD"}
|
|
@@ -2,6 +2,7 @@ import { createComponent as _$createComponent, createIntrinsic as _$createIntrin
|
|
|
2
2
|
import { Block, code, For, Indent, onCleanup, Show, taggedComponent } from "@alloy-js/core";
|
|
3
3
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
4
4
|
import { createTSSymbol, TSSymbolFlags } from "../symbols/index.js";
|
|
5
|
+
import { TypeRefContext } from "./TypeRefContext.js";
|
|
5
6
|
const functionParametersTag = Symbol();
|
|
6
7
|
const typeParametersTag = Symbol();
|
|
7
8
|
const functionBodyTag = Symbol();
|
|
@@ -101,7 +102,11 @@ function parameter(param) {
|
|
|
101
102
|
get children() {
|
|
102
103
|
return _$createIntrinsic("indent", {
|
|
103
104
|
get children() {
|
|
104
|
-
return [": ", _$
|
|
105
|
+
return [": ", _$createComponent(TypeRefContext, {
|
|
106
|
+
get children() {
|
|
107
|
+
return param.type;
|
|
108
|
+
}
|
|
109
|
+
})];
|
|
105
110
|
}
|
|
106
111
|
});
|
|
107
112
|
}
|
|
@@ -127,10 +132,11 @@ function normalizeAndDeclareParameters(parameters, flags = TSSymbolFlags.Paramet
|
|
|
127
132
|
});
|
|
128
133
|
} else {
|
|
129
134
|
return parameters.map(param => {
|
|
135
|
+
const nullishFlag = param.nullish ?? param.optional ? TSSymbolFlags.Nullish : TSSymbolFlags.None;
|
|
130
136
|
const symbol = createTSSymbol({
|
|
131
137
|
name: namePolicy.getName(param.name, flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter"),
|
|
132
138
|
refkey: param.refkey,
|
|
133
|
-
tsFlags: flags,
|
|
139
|
+
tsFlags: flags | nullishFlag,
|
|
134
140
|
metadata: param.metadata
|
|
135
141
|
});
|
|
136
142
|
return {
|
|
@@ -190,7 +196,11 @@ function typeParameter(param) {
|
|
|
190
196
|
get children() {
|
|
191
197
|
return [" ", "extends", _$createIntrinsic("indent", {
|
|
192
198
|
get children() {
|
|
193
|
-
return [" ", _$
|
|
199
|
+
return [" ", _$createComponent(TypeRefContext, {
|
|
200
|
+
get children() {
|
|
201
|
+
return param.extends;
|
|
202
|
+
}
|
|
203
|
+
})];
|
|
194
204
|
}
|
|
195
205
|
})];
|
|
196
206
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { CallSignatureProps } from "./CallSignature.jsx";
|
|
3
3
|
/**
|
|
4
|
-
* Options for {@link
|
|
4
|
+
* Options for {@link FunctionType} component.
|
|
5
5
|
*/
|
|
6
6
|
export interface FunctionTypeProps extends CallSignatureProps {
|
|
7
7
|
/** If the method is async */
|
|
@@ -28,12 +28,11 @@ export interface FunctionTypeProps extends CallSignatureProps {
|
|
|
28
28
|
* 2. As raw content via the `parametersChildren` or `typeParametersChildren`
|
|
29
29
|
* props.
|
|
30
30
|
* 3. As a child of this component via the
|
|
31
|
-
* {@link
|
|
32
|
-
* {@link
|
|
31
|
+
* {@link FunctionType.Parameters} or
|
|
32
|
+
* {@link FunctionType.TypeParameters} components.
|
|
33
33
|
*/
|
|
34
|
-
export declare
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
34
|
+
export declare const FunctionType: ((props: FunctionTypeProps) => Children) & {
|
|
35
|
+
TypeParameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").TypeParametersProps>, "tag">>;
|
|
36
|
+
Parameters: import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps> & Required<Pick<import("@alloy-js/core").Component<import("./FunctionBase.jsx").FunctionTypeParametersProps>, "tag">>;
|
|
37
|
+
};
|
|
39
38
|
//# sourceMappingURL=FunctionType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FunctionType.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionType.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"FunctionType.d.ts","sourceRoot":"","sources":["../../../src/components/FunctionType.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAEtD,OAAO,EAAiB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAWxE;;GAEG;AACH,MAAM,WAAW,iBAAkB,SAAQ,kBAAkB;IAC3D,6BAA6B;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,qCAAqC;IACrC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC;IACxB,kBAAkB;IAClB,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC9B;AAuCD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY;;;CAGvB,CAAC"}
|
|
@@ -5,32 +5,13 @@ import { CallSignature } from "./CallSignature.js";
|
|
|
5
5
|
import { FunctionParameters, FunctionTypeParameters, getReturnType, TypeParameters } from "./FunctionBase.js";
|
|
6
6
|
import { JSDoc } from "./JSDoc.js";
|
|
7
7
|
import { JSDocParams } from "./JSDocParam.js";
|
|
8
|
+
import { ensureTypeRefContext } from "./TypeRefContext.js";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
|
-
* Options for {@link
|
|
11
|
+
* Options for {@link FunctionType} component.
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
* A TypeScript function declaration.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* (foo: string, bar: number) => void
|
|
19
|
-
* ```
|
|
20
|
-
* @remarks
|
|
21
|
-
*
|
|
22
|
-
* Providing parameters and type parameters can be accomplished in one of three
|
|
23
|
-
* ways:
|
|
24
|
-
*
|
|
25
|
-
* 1. As an array of {@link TypeParameterDescriptor}s or
|
|
26
|
-
* {@link TypeParameterDescriptor}s.
|
|
27
|
-
* 2. As raw content via the `parametersChildren` or `typeParametersChildren`
|
|
28
|
-
* props.
|
|
29
|
-
* 3. As a child of this component via the
|
|
30
|
-
* {@link (FunctionType:namespace).Parameters} or
|
|
31
|
-
* {@link (FunctionType:namespace).TypeParameters} components.
|
|
32
|
-
*/
|
|
33
|
-
export function FunctionType(props) {
|
|
14
|
+
const FunctionTypeComponent = ensureTypeRefContext(props => {
|
|
34
15
|
const children = childrenArray(() => props.children);
|
|
35
16
|
const typeParametersChildren = findKeyedChild(children, TypeParameters.tag) ?? undefined;
|
|
36
17
|
const parametersChildren = findKeyedChild(children, FunctionParameters.tag) ?? undefined;
|
|
@@ -68,6 +49,29 @@ export function FunctionType(props) {
|
|
|
68
49
|
})), " => ", returnType];
|
|
69
50
|
}
|
|
70
51
|
})];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A TypeScript function declaration.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* (foo: string, bar: number) => void
|
|
60
|
+
* ```
|
|
61
|
+
* @remarks
|
|
62
|
+
*
|
|
63
|
+
* Providing parameters and type parameters can be accomplished in one of three
|
|
64
|
+
* ways:
|
|
65
|
+
*
|
|
66
|
+
* 1. As an array of {@link TypeParameterDescriptor}s or
|
|
67
|
+
* {@link TypeParameterDescriptor}s.
|
|
68
|
+
* 2. As raw content via the `parametersChildren` or `typeParametersChildren`
|
|
69
|
+
* props.
|
|
70
|
+
* 3. As a child of this component via the
|
|
71
|
+
* {@link FunctionType.Parameters} or
|
|
72
|
+
* {@link FunctionType.TypeParameters} components.
|
|
73
|
+
*/
|
|
74
|
+
export const FunctionType = Object.assign(FunctionTypeComponent, {
|
|
75
|
+
TypeParameters,
|
|
76
|
+
Parameters: FunctionTypeParameters
|
|
77
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportStatement.d.ts","sourceRoot":"","sources":["../../../src/components/ImportStatement.tsx"],"names":[],"mappings":"AAOA,OAAO,EACL,cAAc,EACd,aAAa,
|
|
1
|
+
{"version":3,"file":"ImportStatement.d.ts","sourceRoot":"","sources":["../../../src/components/ImportStatement.tsx"],"names":[],"mappings":"AAOA,OAAO,EACL,cAAc,EACd,aAAa,EAGd,MAAM,qBAAqB,CAAC;AAI7B,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,6CA0C5D;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC9B;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAkD1D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { mapJoin, memo, SourceDirectoryContext, useContext } from "@alloy-js/core";
|
|
3
3
|
import { relative } from "pathe";
|
|
4
|
+
import { TSSymbolFlags } from "../symbols/index.js";
|
|
4
5
|
import { modulePath } from "../utils.js";
|
|
5
6
|
import { usePackage } from "./PackageDirectory.js";
|
|
6
7
|
export function ImportStatements(props) {
|
|
@@ -57,9 +58,14 @@ export function ImportStatement(props) {
|
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
if (namedImportSymbols.length > 0) {
|
|
61
|
+
const allNamedImportsAreTypes = namedImportSymbols.every(nis => nis.local.tsFlags & TSSymbolFlags.TypeSymbol);
|
|
62
|
+
if (allNamedImportsAreTypes) {
|
|
63
|
+
parts.push("type ");
|
|
64
|
+
}
|
|
60
65
|
parts.push("{ ");
|
|
61
66
|
parts.push(mapJoin(() => namedImportSymbols, nis => _$createComponent(ImportBinding, {
|
|
62
|
-
importedSymbol: nis
|
|
67
|
+
importedSymbol: nis,
|
|
68
|
+
inTypeImport: allNamedImportsAreTypes
|
|
63
69
|
}), {
|
|
64
70
|
joiner: ", "
|
|
65
71
|
}));
|
|
@@ -81,5 +87,6 @@ function ImportBinding(props) {
|
|
|
81
87
|
return `${targetName} as ${localName}`;
|
|
82
88
|
}
|
|
83
89
|
});
|
|
84
|
-
|
|
90
|
+
const prefix = memo(() => !props.inTypeImport && props.importedSymbol.local.tsFlags & TSSymbolFlags.TypeSymbol ? "type " : "");
|
|
91
|
+
return [prefix, text];
|
|
85
92
|
}
|
|
@@ -12,17 +12,18 @@ export interface InterfaceDeclarationProps extends BaseDeclarationProps {
|
|
|
12
12
|
* `default` boolean props determine whether and how this symbol is exported
|
|
13
13
|
* from the package.
|
|
14
14
|
*/
|
|
15
|
-
export declare
|
|
15
|
+
export declare const InterfaceDeclaration: (props: InterfaceDeclarationProps) => Children;
|
|
16
16
|
export interface InterfaceExpressionProps {
|
|
17
17
|
children?: Children;
|
|
18
18
|
}
|
|
19
|
-
export declare
|
|
19
|
+
export declare const InterfaceExpression: (props: InterfaceExpressionProps) => Children;
|
|
20
20
|
export interface InterfaceMemberProps {
|
|
21
21
|
name?: string;
|
|
22
22
|
indexer?: Children;
|
|
23
23
|
type?: Children;
|
|
24
24
|
children?: Children;
|
|
25
25
|
optional?: boolean;
|
|
26
|
+
nullish?: boolean;
|
|
26
27
|
readonly?: boolean;
|
|
27
28
|
doc?: Children;
|
|
28
29
|
refkey?: Refkey | Refkey[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interface.d.ts","sourceRoot":"","sources":["../../../src/components/Interface.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"Interface.d.ts","sourceRoot":"","sources":["../../../src/components/Interface.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAIR,MAAM,EAKP,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAOrE,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,gDAmBhC,CAAC;AAEF,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,mBAAmB,+CAmB/B,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,QAAQ,CAAC;IACnB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,YAkD1D"}
|
|
@@ -5,6 +5,7 @@ import { Declaration } from "./Declaration.js";
|
|
|
5
5
|
import { JSDoc } from "./JSDoc.js";
|
|
6
6
|
import { MemberDeclaration } from "./MemberDeclaration.js";
|
|
7
7
|
import { PropertyName } from "./PropertyName.js";
|
|
8
|
+
import { ensureTypeRefContext } from "./TypeRefContext.js";
|
|
8
9
|
/**
|
|
9
10
|
* Create a TypeScript interface declaration.
|
|
10
11
|
*
|
|
@@ -14,7 +15,7 @@ import { PropertyName } from "./PropertyName.js";
|
|
|
14
15
|
* `default` boolean props determine whether and how this symbol is exported
|
|
15
16
|
* from the package.
|
|
16
17
|
*/
|
|
17
|
-
export
|
|
18
|
+
export const InterfaceDeclaration = ensureTypeRefContext(props => {
|
|
18
19
|
const extendsPart = props.extends ? [" extends ", _$memo(() => props.extends)] : "";
|
|
19
20
|
const flags = OutputSymbolFlags.StaticMemberContainer;
|
|
20
21
|
return [_$createComponent(Show, {
|
|
@@ -40,8 +41,8 @@ export function InterfaceDeclaration(props) {
|
|
|
40
41
|
})];
|
|
41
42
|
}
|
|
42
43
|
}))];
|
|
43
|
-
}
|
|
44
|
-
export
|
|
44
|
+
});
|
|
45
|
+
export const InterfaceExpression = ensureTypeRefContext(props => {
|
|
45
46
|
const parentMemberSym = useMemberDeclaration();
|
|
46
47
|
if (parentMemberSym) {
|
|
47
48
|
parentMemberSym.binder.addStaticMembersToSymbol(parentMemberSym);
|
|
@@ -64,7 +65,7 @@ export function InterfaceExpression(props) {
|
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
});
|
|
67
|
-
}
|
|
68
|
+
});
|
|
68
69
|
/**
|
|
69
70
|
* Create a TypeScript interface member.
|
|
70
71
|
*
|
|
@@ -93,6 +94,9 @@ export function InterfaceMember(props) {
|
|
|
93
94
|
get flags() {
|
|
94
95
|
return OutputSymbolFlags.StaticMember;
|
|
95
96
|
},
|
|
97
|
+
get nullish() {
|
|
98
|
+
return props.nullish ?? props.optional;
|
|
99
|
+
},
|
|
96
100
|
get refkey() {
|
|
97
101
|
return props.refkey;
|
|
98
102
|
},
|
|
@@ -25,6 +25,10 @@ export interface MemberDeclarationProps extends Omit<MemberDeclarationPropsWithI
|
|
|
25
25
|
* The symbol to use for this memberdeclaration.
|
|
26
26
|
*/
|
|
27
27
|
symbol?: TSOutputSymbol;
|
|
28
|
+
/**
|
|
29
|
+
* Whether this member can be null or undefined.
|
|
30
|
+
*/
|
|
31
|
+
nullish?: boolean;
|
|
28
32
|
}
|
|
29
33
|
export declare function MemberDeclaration(props: Readonly<MemberDeclarationProps>): import("@alloy-js/core").Children;
|
|
30
34
|
//# sourceMappingURL=MemberDeclaration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemberDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/MemberDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAC9B,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAmB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAEL,cAAc,EAEf,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,8BAA8B,EAAE,MAAM,CAAC;IACpD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"MemberDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/MemberDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAC9B,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAmB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAEL,cAAc,EAEf,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,8BAA8B,EAAE,MAAM,CAAC;IACpD;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAE9B;;OAEG;IACH,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,CAAC,sBAAsB,CAAC,qCA2BxE"}
|
|
@@ -8,7 +8,7 @@ export function MemberDeclaration(props) {
|
|
|
8
8
|
sym = props.symbol;
|
|
9
9
|
} else {
|
|
10
10
|
const namePolicy = useTSNamePolicy();
|
|
11
|
-
let tsFlags = TSSymbolFlags.None;
|
|
11
|
+
let tsFlags = props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None;
|
|
12
12
|
if (props.kind === "type") {
|
|
13
13
|
tsFlags |= TSSymbolFlags.TypeSymbol;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MemberExpression.d.ts","sourceRoot":"","sources":["../../../src/components/MemberExpression.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKR,YAAY,EAGZ,MAAM,EAGP,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"MemberExpression.d.ts","sourceRoot":"","sources":["../../../src/components/MemberExpression.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAKR,YAAY,EAGZ,MAAM,EAGP,MAAM,gBAAgB,CAAC;AAIxB,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,QAAQ,CAAC;CACpB;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,QAAQ,CA4HvE;yBA5He,gBAAgB;sBAmLS,yBAAyB;;AAhClE,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createIntrinsic as _$createIntrinsic, memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { childrenArray, computed, For, isComponentCreator, ref, toRef, useBinder } from "@alloy-js/core";
|
|
3
|
+
import { TSSymbolFlags } from "../symbols/ts-output-symbol.js";
|
|
3
4
|
import { isValidJSIdentifier } from "../utils.js";
|
|
4
5
|
/**
|
|
5
6
|
* Create a member expression from parts. Each part can provide one of
|
|
@@ -53,7 +54,7 @@ export function MemberExpression(props) {
|
|
|
53
54
|
const symbolRef = binder.getSymbolForRefkey(partProps.refkey);
|
|
54
55
|
part.base = computed(() => {
|
|
55
56
|
if (symbolRef.value) {
|
|
56
|
-
part.nullish.value = !!symbolRef.value.
|
|
57
|
+
part.nullish.value = !!(symbolRef.value.tsFlags & TSSymbolFlags.Nullish);
|
|
57
58
|
part.accessStyle.value = accessStyleForMemberName(symbolRef.value.name);
|
|
58
59
|
return symbolRef.value.name;
|
|
59
60
|
} else {
|
|
@@ -61,7 +62,7 @@ export function MemberExpression(props) {
|
|
|
61
62
|
}
|
|
62
63
|
});
|
|
63
64
|
} else if (partProps.symbol) {
|
|
64
|
-
part.nullish.value = !!partProps.symbol.
|
|
65
|
+
part.nullish.value = !!(partProps.symbol.tsFlags & TSSymbolFlags.Nullish);
|
|
65
66
|
part.accessStyle = computed(() => {
|
|
66
67
|
return accessStyleForMemberName(partProps.symbol.name);
|
|
67
68
|
});
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Refkey } from "@alloy-js/core";
|
|
2
2
|
export interface ReferenceProps {
|
|
3
3
|
refkey: Refkey;
|
|
4
|
+
/**
|
|
5
|
+
* Whether this is a reference to a type.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This affect things like import where `type` keyword might be used.
|
|
9
|
+
*/
|
|
10
|
+
type?: boolean;
|
|
4
11
|
}
|
|
5
|
-
export declare function Reference({ refkey }: ReferenceProps): import("@alloy-js/core").Children;
|
|
12
|
+
export declare function Reference({ refkey, type }: ReferenceProps): import("@alloy-js/core").Children;
|
|
6
13
|
//# sourceMappingURL=Reference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Reference.d.ts","sourceRoot":"","sources":["../../../src/components/Reference.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Reference.d.ts","sourceRoot":"","sources":["../../../src/components/Reference.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,wBAAgB,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,cAAc,qCAKzD"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { isTypeRefContext } from "../context/type-ref-context.js";
|
|
1
2
|
import { ref } from "../symbols/index.js";
|
|
2
3
|
export function Reference({
|
|
3
|
-
refkey
|
|
4
|
+
refkey,
|
|
5
|
+
type
|
|
4
6
|
}) {
|
|
5
|
-
const
|
|
7
|
+
const inTypeRef = isTypeRefContext();
|
|
8
|
+
const reference = ref(refkey, {
|
|
9
|
+
type: type ?? inTypeRef
|
|
10
|
+
});
|
|
6
11
|
return [reference];
|
|
7
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseDeclarationProps } from "./Declaration.js";
|
|
2
2
|
export interface TypeDeclarationProps extends BaseDeclarationProps {
|
|
3
3
|
}
|
|
4
|
-
export declare
|
|
4
|
+
export declare const TypeDeclaration: (props: TypeDeclarationProps) => import("@alloy-js/core").Children;
|
|
5
5
|
//# sourceMappingURL=TypeDeclaration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/TypeDeclaration.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"TypeDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/TypeDeclaration.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAIrE,MAAM,WAAW,oBAAqB,SAAQ,oBAAoB;CAAG;AAErE,eAAO,MAAM,eAAe,oEAc3B,CAAC"}
|
|
@@ -2,7 +2,8 @@ import { createComponent as _$createComponent, createIntrinsic as _$createIntrin
|
|
|
2
2
|
import { Name, Show } from "@alloy-js/core";
|
|
3
3
|
import { Declaration } from "./Declaration.js";
|
|
4
4
|
import { JSDoc } from "./JSDoc.js";
|
|
5
|
-
|
|
5
|
+
import { ensureTypeRefContext } from "./TypeRefContext.js";
|
|
6
|
+
export const TypeDeclaration = ensureTypeRefContext(props => {
|
|
6
7
|
return [_$createComponent(Show, {
|
|
7
8
|
get when() {
|
|
8
9
|
return Boolean(props.doc);
|
|
@@ -20,4 +21,4 @@ export function TypeDeclaration(props) {
|
|
|
20
21
|
return ["type ", _$createComponent(Name, {}), " = ", _$memo(() => props.children), ";"];
|
|
21
22
|
}
|
|
22
23
|
}))];
|
|
23
|
-
}
|
|
24
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Children } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
export interface TypeRefContextProps {
|
|
3
|
+
/**
|
|
4
|
+
* Children
|
|
5
|
+
*/
|
|
6
|
+
children: Children;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Set the current context of reference to be type reference.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* References used inside the children of this component will be treated as type reference {@link Reference}.
|
|
13
|
+
*
|
|
14
|
+
* Prefer using {@link ensureTypeRefContext} when wrapping the whole component to reduce tree nodes.
|
|
15
|
+
*/
|
|
16
|
+
export declare const TypeRefContext: ({ children }: TypeRefContextProps) => Children;
|
|
17
|
+
/** Ensure the current component is inside a type ref context.
|
|
18
|
+
* If not it will wrap in a {@link TypeRefContext} component.
|
|
19
|
+
* If yes it will not add an extra node and return the original component.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ensureTypeRefContext<A extends unknown[]>(fn: (...args: A) => Children): (...args: A) => Children;
|
|
22
|
+
//# sourceMappingURL=TypeRefContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeRefContext.d.ts","sourceRoot":"","sources":["../../../src/components/TypeRefContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAM3D,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,cAAc,mBAAmB,aAM/D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,OAAO,EAAE,EACtD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,QAAQ,GAC3B,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,QAAQ,CAa1B"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { isTypeRefContext, TypeRefContext as TypeRefContextDef } from "../context/type-ref-context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Set the current context of reference to be type reference.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* References used inside the children of this component will be treated as type reference {@link Reference}.
|
|
8
|
+
*
|
|
9
|
+
* Prefer using {@link ensureTypeRefContext} when wrapping the whole component to reduce tree nodes.
|
|
10
|
+
*/
|
|
11
|
+
export const TypeRefContext = ({
|
|
12
|
+
children
|
|
13
|
+
}) => {
|
|
14
|
+
return _$createComponent(TypeRefContextDef.Provider, {
|
|
15
|
+
value: {
|
|
16
|
+
type: true
|
|
17
|
+
},
|
|
18
|
+
children: children
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Ensure the current component is inside a type ref context.
|
|
23
|
+
* If not it will wrap in a {@link TypeRefContext} component.
|
|
24
|
+
* If yes it will not add an extra node and return the original component.
|
|
25
|
+
*/
|
|
26
|
+
export function ensureTypeRefContext(fn) {
|
|
27
|
+
return (...args) => {
|
|
28
|
+
const ref = isTypeRefContext();
|
|
29
|
+
if (!ref) {
|
|
30
|
+
return _$createComponent(TypeRefContextDef.Provider, {
|
|
31
|
+
value: {
|
|
32
|
+
type: true
|
|
33
|
+
},
|
|
34
|
+
get children() {
|
|
35
|
+
return fn(...args);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return fn(...args);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -6,6 +6,7 @@ export interface VarDeclarationProps extends BaseDeclarationProps {
|
|
|
6
6
|
var?: boolean;
|
|
7
7
|
initializer?: Children;
|
|
8
8
|
type?: Children;
|
|
9
|
+
nullish?: boolean;
|
|
9
10
|
}
|
|
10
11
|
export declare function VarDeclaration(props: VarDeclarationProps): Children;
|
|
11
12
|
//# sourceMappingURL=VarDeclaration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VarDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/VarDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKT,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"VarDeclaration.d.ts","sourceRoot":"","sources":["../../../src/components/VarDeclaration.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKT,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAIxD,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAC/D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,YAoCxD"}
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { AssignmentContext, Declaration as CoreDeclaration, createAssignmentContext, Name, Show } from "@alloy-js/core";
|
|
3
3
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
4
|
-
import { createTSSymbol } from "../symbols/index.js";
|
|
4
|
+
import { createTSSymbol, TSSymbolFlags } from "../symbols/index.js";
|
|
5
5
|
import { JSDoc } from "./JSDoc.js";
|
|
6
|
+
import { TypeRefContext } from "./TypeRefContext.js";
|
|
6
7
|
export function VarDeclaration(props) {
|
|
7
8
|
const keyword = props.var ? "var" : props.let ? "let" : "const";
|
|
8
|
-
const type = props.type ?
|
|
9
|
+
const type = props.type ? _$createComponent(TypeRefContext, {
|
|
10
|
+
get children() {
|
|
11
|
+
return [": ", _$memo(() => props.type)];
|
|
12
|
+
}
|
|
13
|
+
}) : undefined;
|
|
9
14
|
const name = useTSNamePolicy().getName(props.name, "variable");
|
|
10
15
|
const sym = createTSSymbol({
|
|
11
16
|
name: name,
|
|
12
17
|
refkey: props.refkey,
|
|
13
18
|
default: props.default,
|
|
14
19
|
export: props.export,
|
|
15
|
-
metadata: props.metadata
|
|
20
|
+
metadata: props.metadata,
|
|
21
|
+
tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None
|
|
16
22
|
});
|
|
17
23
|
const assignmentContext = createAssignmentContext(sym);
|
|
18
24
|
return [_$createComponent(Show, {
|
|
@@ -32,6 +32,7 @@ export * from "./SourceFile.js";
|
|
|
32
32
|
export * from "./SwitchStatement.jsx";
|
|
33
33
|
export * from "./TsConfigJson.js";
|
|
34
34
|
export * from "./TypeDeclaration.js";
|
|
35
|
+
export * from "./TypeRefContext.jsx";
|
|
35
36
|
export * from "./ValueExpression.js";
|
|
36
37
|
export * from "./VarDeclaration.js";
|
|
37
38
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,GACjC,MAAM,mBAAmB,CAAC;AAC3B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,GACjC,MAAM,mBAAmB,CAAC;AAC3B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|