@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
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { StatementList } from "@alloy-js/core";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as ts from "../src/index.js";
|
|
6
|
+
import { toSourceText } from "./utils.js";
|
|
7
|
+
it("renders an interface declaration with documentation", () => {
|
|
8
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
9
|
+
name: "Person",
|
|
10
|
+
doc: "Interface representing a person",
|
|
11
|
+
get children() {
|
|
12
|
+
return _$createComponent(StatementList, {
|
|
13
|
+
get children() {
|
|
14
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
15
|
+
name: "name",
|
|
16
|
+
type: "string"
|
|
17
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
18
|
+
name: "age",
|
|
19
|
+
type: "number"
|
|
20
|
+
})];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}));
|
|
25
|
+
expect(res).toEqual(d`
|
|
26
|
+
/**
|
|
27
|
+
* Interface representing a person
|
|
28
|
+
*/
|
|
29
|
+
interface Person {
|
|
30
|
+
name: string;
|
|
31
|
+
age: number;
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
it("renders an interface declaration with docs from a string array with single element", () => {
|
|
36
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
37
|
+
name: "Person",
|
|
38
|
+
doc: ["Interface representing a person"],
|
|
39
|
+
get children() {
|
|
40
|
+
return _$createComponent(StatementList, {
|
|
41
|
+
get children() {
|
|
42
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
43
|
+
name: "name",
|
|
44
|
+
type: "string"
|
|
45
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
46
|
+
name: "age",
|
|
47
|
+
type: "number"
|
|
48
|
+
})];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
expect(res).toEqual(d`
|
|
54
|
+
/**
|
|
55
|
+
* Interface representing a person
|
|
56
|
+
*/
|
|
57
|
+
interface Person {
|
|
58
|
+
name: string;
|
|
59
|
+
age: number;
|
|
60
|
+
}
|
|
61
|
+
`);
|
|
62
|
+
});
|
|
63
|
+
it("renders an interface declaration with docs from a string array", () => {
|
|
64
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
65
|
+
name: "Person",
|
|
66
|
+
doc: ["Interface representing a person", "This should be another paragraph"],
|
|
67
|
+
get children() {
|
|
68
|
+
return _$createComponent(StatementList, {
|
|
69
|
+
get children() {
|
|
70
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
71
|
+
name: "name",
|
|
72
|
+
type: "string"
|
|
73
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
74
|
+
name: "age",
|
|
75
|
+
type: "number"
|
|
76
|
+
})];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}));
|
|
81
|
+
expect(res).toEqual(d`
|
|
82
|
+
/**
|
|
83
|
+
* Interface representing a person
|
|
84
|
+
*
|
|
85
|
+
* This should be another paragraph
|
|
86
|
+
*/
|
|
87
|
+
interface Person {
|
|
88
|
+
name: string;
|
|
89
|
+
age: number;
|
|
90
|
+
}
|
|
91
|
+
`);
|
|
92
|
+
});
|
|
93
|
+
it("renders an interface declaration with documented properties", () => {
|
|
94
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
95
|
+
"export": true,
|
|
96
|
+
name: "APIResponse",
|
|
97
|
+
doc: "Standard API response format",
|
|
98
|
+
get children() {
|
|
99
|
+
return _$createComponent(StatementList, {
|
|
100
|
+
get children() {
|
|
101
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
102
|
+
name: "success",
|
|
103
|
+
type: "boolean",
|
|
104
|
+
doc: "Wether or not the request completed successfully"
|
|
105
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
106
|
+
name: "data",
|
|
107
|
+
type: "unknown",
|
|
108
|
+
doc: "the response payload"
|
|
109
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
110
|
+
name: "error",
|
|
111
|
+
optional: true,
|
|
112
|
+
type: "string"
|
|
113
|
+
})];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
expect(res).toEqual(d`
|
|
119
|
+
/**
|
|
120
|
+
* Standard API response format
|
|
121
|
+
*/
|
|
122
|
+
export interface APIResponse {
|
|
123
|
+
/**
|
|
124
|
+
* Wether or not the request completed successfully
|
|
125
|
+
*/
|
|
126
|
+
success: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* the response payload
|
|
129
|
+
*/
|
|
130
|
+
data: unknown;
|
|
131
|
+
error?: string;
|
|
132
|
+
}
|
|
133
|
+
`);
|
|
134
|
+
});
|
|
135
|
+
it("renders an interface declaration with array documented properties ", () => {
|
|
136
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
137
|
+
"export": true,
|
|
138
|
+
name: "APIResponse",
|
|
139
|
+
doc: "Standard API response format",
|
|
140
|
+
get children() {
|
|
141
|
+
return _$createComponent(StatementList, {
|
|
142
|
+
get children() {
|
|
143
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
144
|
+
name: "success",
|
|
145
|
+
type: "boolean",
|
|
146
|
+
doc: ["Wether or not the request completed successfully", "This is another paragraph"]
|
|
147
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
148
|
+
name: "data",
|
|
149
|
+
type: "unknown",
|
|
150
|
+
doc: "the response payload"
|
|
151
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
152
|
+
name: "error",
|
|
153
|
+
optional: true,
|
|
154
|
+
type: "string"
|
|
155
|
+
})];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}));
|
|
160
|
+
expect(res).toEqual(d`
|
|
161
|
+
/**
|
|
162
|
+
* Standard API response format
|
|
163
|
+
*/
|
|
164
|
+
export interface APIResponse {
|
|
165
|
+
/**
|
|
166
|
+
* Wether or not the request completed successfully
|
|
167
|
+
*
|
|
168
|
+
* This is another paragraph
|
|
169
|
+
*/
|
|
170
|
+
success: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* the response payload
|
|
173
|
+
*/
|
|
174
|
+
data: unknown;
|
|
175
|
+
error?: string;
|
|
176
|
+
}
|
|
177
|
+
`);
|
|
178
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.test.d.ts","sourceRoot":"","sources":["../../test/interface.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interface.test.d.ts","sourceRoot":"","sources":["../../test/interface.test.tsx"],"names":[],"mappings":"AAMA,OAAO,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { NamePolicyContext, refkey, StatementList } from "@alloy-js/core";
|
|
3
|
+
import "@alloy-js/core/testing";
|
|
4
|
+
import { d } from "@alloy-js/core/testing";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import * as ts from "../src/components/index.js";
|
|
7
|
+
import { Reference } from "../src/components/Reference.js";
|
|
8
|
+
import { createTSNamePolicy } from "../src/name-policy.js";
|
|
9
|
+
import { toSourceText } from "./utils.js";
|
|
10
|
+
it("declares interfaces", () => {
|
|
11
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
12
|
+
name: "Foo"
|
|
13
|
+
}));
|
|
14
|
+
expect(res).toEqual(d`
|
|
15
|
+
interface Foo {}
|
|
16
|
+
`);
|
|
17
|
+
});
|
|
18
|
+
it("accepts export and default", () => {
|
|
19
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
20
|
+
name: "Foo",
|
|
21
|
+
"export": true,
|
|
22
|
+
"default": true
|
|
23
|
+
}));
|
|
24
|
+
expect(res).toEqual(d`
|
|
25
|
+
export default interface Foo {}
|
|
26
|
+
`);
|
|
27
|
+
});
|
|
28
|
+
it("creates extends", () => {
|
|
29
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
30
|
+
name: "Foo",
|
|
31
|
+
"extends": "string"
|
|
32
|
+
}));
|
|
33
|
+
expect(res).toEqual(d`
|
|
34
|
+
interface Foo extends string {}
|
|
35
|
+
`);
|
|
36
|
+
});
|
|
37
|
+
it("can create members", () => {
|
|
38
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
39
|
+
name: "Foo",
|
|
40
|
+
get refkey() {
|
|
41
|
+
return refkey("Foo");
|
|
42
|
+
},
|
|
43
|
+
get children() {
|
|
44
|
+
return _$createComponent(StatementList, {
|
|
45
|
+
get children() {
|
|
46
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
47
|
+
name: "member",
|
|
48
|
+
type: "string"
|
|
49
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
50
|
+
name: "circular",
|
|
51
|
+
get type() {
|
|
52
|
+
return _$createComponent(Reference, {
|
|
53
|
+
get refkey() {
|
|
54
|
+
return refkey("Foo");
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
59
|
+
indexer: "str: string",
|
|
60
|
+
type: "number"
|
|
61
|
+
})];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
expect(res).toEqual(d`
|
|
67
|
+
interface Foo {
|
|
68
|
+
member: string;
|
|
69
|
+
circular: Foo;
|
|
70
|
+
[str: string]: number;
|
|
71
|
+
}
|
|
72
|
+
`);
|
|
73
|
+
});
|
|
74
|
+
it("can create optional members", () => {
|
|
75
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
76
|
+
name: "Foo",
|
|
77
|
+
get refkey() {
|
|
78
|
+
return refkey("Foo");
|
|
79
|
+
},
|
|
80
|
+
get children() {
|
|
81
|
+
return _$createComponent(StatementList, {
|
|
82
|
+
get children() {
|
|
83
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
84
|
+
name: "member",
|
|
85
|
+
type: "string"
|
|
86
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
87
|
+
optional: true,
|
|
88
|
+
name: "circular",
|
|
89
|
+
get type() {
|
|
90
|
+
return _$createComponent(Reference, {
|
|
91
|
+
get refkey() {
|
|
92
|
+
return refkey("Foo");
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
97
|
+
indexer: "str: string",
|
|
98
|
+
type: "number"
|
|
99
|
+
})];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
expect(res).toEqual(d`
|
|
105
|
+
interface Foo {
|
|
106
|
+
member: string;
|
|
107
|
+
circular?: Foo;
|
|
108
|
+
[str: string]: number;
|
|
109
|
+
}
|
|
110
|
+
`);
|
|
111
|
+
});
|
|
112
|
+
it("can create readonly members", () => {
|
|
113
|
+
const res = toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
114
|
+
name: "Foo",
|
|
115
|
+
get refkey() {
|
|
116
|
+
return refkey("Foo");
|
|
117
|
+
},
|
|
118
|
+
get children() {
|
|
119
|
+
return _$createComponent(StatementList, {
|
|
120
|
+
get children() {
|
|
121
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
122
|
+
readonly: true,
|
|
123
|
+
name: "member",
|
|
124
|
+
type: "string"
|
|
125
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
126
|
+
name: "circular",
|
|
127
|
+
get type() {
|
|
128
|
+
return _$createComponent(Reference, {
|
|
129
|
+
get refkey() {
|
|
130
|
+
return refkey("Foo");
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}), _$createComponent(ts.InterfaceMember, {
|
|
135
|
+
indexer: "str: string",
|
|
136
|
+
type: "number"
|
|
137
|
+
})];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}));
|
|
142
|
+
expect(res).toEqual(d`
|
|
143
|
+
interface Foo {
|
|
144
|
+
readonly member: string;
|
|
145
|
+
circular: Foo;
|
|
146
|
+
[str: string]: number;
|
|
147
|
+
}
|
|
148
|
+
`);
|
|
149
|
+
});
|
|
150
|
+
it("can reference member", () => {
|
|
151
|
+
const ref = refkey("Foo");
|
|
152
|
+
const res = toSourceText([_$createComponent(ts.InterfaceDeclaration, {
|
|
153
|
+
name: "Foo",
|
|
154
|
+
get children() {
|
|
155
|
+
return _$createComponent(ts.InterfaceMember, {
|
|
156
|
+
name: "prop",
|
|
157
|
+
type: "string",
|
|
158
|
+
refkey: ref
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}), _$createIntrinsic("line", {}), _$createComponent(ts.InterfaceDeclaration, {
|
|
162
|
+
name: "Bar",
|
|
163
|
+
get children() {
|
|
164
|
+
return _$createComponent(ts.InterfaceMember, {
|
|
165
|
+
name: "ref",
|
|
166
|
+
get type() {
|
|
167
|
+
return _$createComponent(Reference, {
|
|
168
|
+
refkey: ref
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
})]);
|
|
174
|
+
expect(res).toEqual(d`
|
|
175
|
+
interface Foo {
|
|
176
|
+
prop: string
|
|
177
|
+
}
|
|
178
|
+
interface Bar {
|
|
179
|
+
ref: Foo["prop"]
|
|
180
|
+
}
|
|
181
|
+
`);
|
|
182
|
+
});
|
|
183
|
+
describe("interface expressions", () => {
|
|
184
|
+
it("basic", () => {
|
|
185
|
+
const res = toSourceText(_$createComponent(ts.InterfaceExpression, {
|
|
186
|
+
get children() {
|
|
187
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
188
|
+
name: "member",
|
|
189
|
+
type: "string"
|
|
190
|
+
}), ";"];
|
|
191
|
+
}
|
|
192
|
+
}));
|
|
193
|
+
expect(res).toEqual(d`
|
|
194
|
+
{
|
|
195
|
+
member: string;
|
|
196
|
+
}
|
|
197
|
+
`);
|
|
198
|
+
});
|
|
199
|
+
it("nested", () => {
|
|
200
|
+
const res = toSourceText(_$createComponent(ts.InterfaceExpression, {
|
|
201
|
+
get children() {
|
|
202
|
+
return _$createComponent(ts.InterfaceMember, {
|
|
203
|
+
name: "outer",
|
|
204
|
+
get children() {
|
|
205
|
+
return _$createComponent(ts.InterfaceExpression, {
|
|
206
|
+
get children() {
|
|
207
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
208
|
+
name: "inner",
|
|
209
|
+
type: "string"
|
|
210
|
+
}), ";"];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}));
|
|
217
|
+
expect(res).toEqual(d`
|
|
218
|
+
{
|
|
219
|
+
outer: {
|
|
220
|
+
inner: string;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
`);
|
|
224
|
+
});
|
|
225
|
+
it("can reference member when nested in a declaration", () => {
|
|
226
|
+
const ref = refkey("Foo");
|
|
227
|
+
const res = toSourceText([_$createComponent(ts.InterfaceDeclaration, {
|
|
228
|
+
name: "Foo",
|
|
229
|
+
get children() {
|
|
230
|
+
return _$createComponent(ts.InterfaceMember, {
|
|
231
|
+
name: "outer",
|
|
232
|
+
get children() {
|
|
233
|
+
return _$createComponent(ts.InterfaceExpression, {
|
|
234
|
+
get children() {
|
|
235
|
+
return _$createComponent(ts.InterfaceMember, {
|
|
236
|
+
name: "inner",
|
|
237
|
+
type: "string",
|
|
238
|
+
refkey: ref
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}), _$createIntrinsic("line", {}), _$createComponent(ts.InterfaceDeclaration, {
|
|
246
|
+
name: "Bar",
|
|
247
|
+
get children() {
|
|
248
|
+
return _$createComponent(ts.InterfaceMember, {
|
|
249
|
+
name: "ref",
|
|
250
|
+
get type() {
|
|
251
|
+
return _$createComponent(Reference, {
|
|
252
|
+
refkey: ref
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
})]);
|
|
258
|
+
expect(res).toEqual(d`
|
|
259
|
+
interface Foo {
|
|
260
|
+
outer: {
|
|
261
|
+
inner: string
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
interface Bar {
|
|
265
|
+
ref: Foo["outer"]["inner"]
|
|
266
|
+
}
|
|
267
|
+
`);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
it("supports the naming policy", () => {
|
|
271
|
+
const policy = createTSNamePolicy();
|
|
272
|
+
const res = toSourceText(_$createComponent(NamePolicyContext.Provider, {
|
|
273
|
+
value: policy,
|
|
274
|
+
get children() {
|
|
275
|
+
return _$createComponent(ts.InterfaceDeclaration, {
|
|
276
|
+
name: "interface_name",
|
|
277
|
+
get children() {
|
|
278
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
279
|
+
name: "member_property",
|
|
280
|
+
type: "string"
|
|
281
|
+
}), ";"];
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}));
|
|
286
|
+
expect(res).toEqual(d`
|
|
287
|
+
interface InterfaceName {
|
|
288
|
+
memberProperty: string;
|
|
289
|
+
}
|
|
290
|
+
`);
|
|
291
|
+
});
|
|
292
|
+
it("handles invalid identifier names", () => {
|
|
293
|
+
const res = toSourceText(_$createComponent(ts.InterfaceExpression, {
|
|
294
|
+
get children() {
|
|
295
|
+
return [_$createComponent(ts.InterfaceMember, {
|
|
296
|
+
name: "invalid-name",
|
|
297
|
+
type: "string"
|
|
298
|
+
}), ";"];
|
|
299
|
+
}
|
|
300
|
+
}));
|
|
301
|
+
expect(res).toEqual(d`
|
|
302
|
+
{
|
|
303
|
+
"invalid-name": string;
|
|
304
|
+
}
|
|
305
|
+
`);
|
|
306
|
+
});
|
|
307
|
+
describe("method members", () => {
|
|
308
|
+
it("render basic", () => {
|
|
309
|
+
expect(toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
310
|
+
name: "Foo",
|
|
311
|
+
get children() {
|
|
312
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
313
|
+
name: "foo"
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}))).toBe(d`
|
|
317
|
+
interface Foo {
|
|
318
|
+
foo(): void
|
|
319
|
+
}
|
|
320
|
+
`);
|
|
321
|
+
});
|
|
322
|
+
it("render in interface", () => {
|
|
323
|
+
expect(toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
324
|
+
name: "Foo",
|
|
325
|
+
get children() {
|
|
326
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
327
|
+
name: "foo"
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}))).toBe(d`
|
|
331
|
+
interface Foo {
|
|
332
|
+
foo(): void
|
|
333
|
+
}
|
|
334
|
+
`);
|
|
335
|
+
});
|
|
336
|
+
it("can be an async function", () => {
|
|
337
|
+
expect(toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
338
|
+
name: "Foo",
|
|
339
|
+
get children() {
|
|
340
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
341
|
+
async: true,
|
|
342
|
+
name: "foo"
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}))).toBe(d`
|
|
346
|
+
interface Foo {
|
|
347
|
+
foo(): Promise<void>
|
|
348
|
+
}
|
|
349
|
+
`);
|
|
350
|
+
});
|
|
351
|
+
it("can be an async function with returnType", () => {
|
|
352
|
+
expect(toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
353
|
+
name: "Foo",
|
|
354
|
+
get children() {
|
|
355
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
356
|
+
async: true,
|
|
357
|
+
name: "foo",
|
|
358
|
+
returnType: "Foo"
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}))).toBe(d`
|
|
362
|
+
interface Foo {
|
|
363
|
+
foo(): Promise<Foo>
|
|
364
|
+
}
|
|
365
|
+
`);
|
|
366
|
+
});
|
|
367
|
+
it("can be an async function with returnType element", () => {
|
|
368
|
+
function Foo(_props) {
|
|
369
|
+
return ["Foo"];
|
|
370
|
+
}
|
|
371
|
+
expect(toSourceText(_$createComponent(ts.InterfaceDeclaration, {
|
|
372
|
+
name: "Foo",
|
|
373
|
+
get children() {
|
|
374
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
375
|
+
async: true,
|
|
376
|
+
name: "foo",
|
|
377
|
+
get returnType() {
|
|
378
|
+
return _$createComponent(Foo, {});
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}))).toBe(d`
|
|
383
|
+
interface Foo {
|
|
384
|
+
foo(): Promise<Foo>
|
|
385
|
+
}
|
|
386
|
+
`);
|
|
387
|
+
});
|
|
388
|
+
it("supports parameters by element", () => {
|
|
389
|
+
const decl = _$createComponent(ts.InterfaceDeclaration, {
|
|
390
|
+
name: "Foo",
|
|
391
|
+
get children() {
|
|
392
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
393
|
+
name: "foo",
|
|
394
|
+
get children() {
|
|
395
|
+
return _$createComponent(ts.InterfaceMethod.Parameters, {
|
|
396
|
+
children: "a, b"
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
expect(toSourceText(decl)).toBe(d`
|
|
403
|
+
interface Foo {
|
|
404
|
+
foo(a, b): void
|
|
405
|
+
}
|
|
406
|
+
`);
|
|
407
|
+
});
|
|
408
|
+
it("supports type parameters by descriptor object", () => {
|
|
409
|
+
const decl = _$createComponent(ts.InterfaceDeclaration, {
|
|
410
|
+
name: "Foo",
|
|
411
|
+
get children() {
|
|
412
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
413
|
+
name: "foo",
|
|
414
|
+
typeParameters: [{
|
|
415
|
+
name: "a",
|
|
416
|
+
extends: "any"
|
|
417
|
+
}, {
|
|
418
|
+
name: "b",
|
|
419
|
+
extends: "any"
|
|
420
|
+
}]
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
expect(toSourceText(decl)).toBe(d`
|
|
425
|
+
interface Foo {
|
|
426
|
+
foo<a extends any, b extends any>(): void
|
|
427
|
+
}
|
|
428
|
+
`);
|
|
429
|
+
});
|
|
430
|
+
it("supports type parameters by descriptor array", () => {
|
|
431
|
+
const decl = _$createComponent(ts.InterfaceDeclaration, {
|
|
432
|
+
name: "Foo",
|
|
433
|
+
get children() {
|
|
434
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
435
|
+
name: "foo",
|
|
436
|
+
typeParameters: ["a", "b"]
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
expect(toSourceText(decl)).toBe(d`
|
|
441
|
+
interface Foo {
|
|
442
|
+
foo<a, b>(): void
|
|
443
|
+
}
|
|
444
|
+
`);
|
|
445
|
+
});
|
|
446
|
+
it("supports type parameters by element", () => {
|
|
447
|
+
const decl = _$createComponent(ts.InterfaceDeclaration, {
|
|
448
|
+
name: "Foo",
|
|
449
|
+
get children() {
|
|
450
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
451
|
+
name: "foo",
|
|
452
|
+
get children() {
|
|
453
|
+
return _$createComponent(ts.InterfaceMethod.TypeParameters, {
|
|
454
|
+
children: "a, b"
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
expect(toSourceText(decl)).toBe(d`
|
|
461
|
+
interface Foo {
|
|
462
|
+
foo<a, b>(): void
|
|
463
|
+
}
|
|
464
|
+
`);
|
|
465
|
+
});
|
|
466
|
+
describe("symbols", () => {
|
|
467
|
+
it("create optional parameters", () => {
|
|
468
|
+
const paramDesc = {
|
|
469
|
+
name: "foo",
|
|
470
|
+
refkey: refkey(),
|
|
471
|
+
type: "any",
|
|
472
|
+
optional: true
|
|
473
|
+
};
|
|
474
|
+
const decl = _$createComponent(ts.InterfaceDeclaration, {
|
|
475
|
+
name: "Foo",
|
|
476
|
+
get children() {
|
|
477
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
478
|
+
name: "foo",
|
|
479
|
+
parameters: [paramDesc]
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
expect(toSourceText(decl)).toBe(d`
|
|
484
|
+
interface Foo {
|
|
485
|
+
foo(foo?: any): void
|
|
486
|
+
}
|
|
487
|
+
`);
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
});
|