@alloy-js/typescript 0.5.0 → 0.7.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/components/ArrayExpression.d.ts +1 -1
- package/dist/src/components/ArrayExpression.d.ts.map +1 -1
- package/dist/src/components/ArrayExpression.js +18 -28
- package/dist/src/components/ArrayExpression.js.map +1 -1
- package/dist/src/components/BarrelFile.d.ts.map +1 -1
- package/dist/src/components/BarrelFile.js +11 -9
- package/dist/src/components/BarrelFile.js.map +1 -1
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +8 -9
- package/dist/src/components/ClassDeclaration.js.map +1 -1
- package/dist/src/components/CommaList.d.ts +12 -0
- package/dist/src/components/CommaList.d.ts.map +1 -0
- package/dist/src/components/CommaList.js +19 -0
- package/dist/src/components/CommaList.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +4 -0
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +3 -2
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +21 -18
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/ExportStatement.js +3 -1
- package/dist/src/components/ExportStatement.js.map +1 -1
- package/dist/src/components/FunctionCallExpression.d.ts +2 -2
- package/dist/src/components/FunctionCallExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionCallExpression.js +26 -9
- package/dist/src/components/FunctionCallExpression.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts +10 -2
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +136 -33
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +25 -31
- package/dist/src/components/ImportStatement.js.map +1 -1
- package/dist/src/components/Interface.d.ts +1 -1
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +5 -5
- package/dist/src/components/Interface.js.map +1 -1
- package/dist/src/components/JSDoc.d.ts +10 -0
- package/dist/src/components/JSDoc.d.ts.map +1 -0
- package/dist/src/components/JSDoc.js +24 -0
- package/dist/src/components/JSDoc.js.map +1 -0
- package/dist/src/components/JSDocComment.d.ts +11 -0
- package/dist/src/components/JSDocComment.d.ts.map +1 -0
- package/dist/src/components/JSDocComment.js +16 -0
- package/dist/src/components/JSDocComment.js.map +1 -0
- package/dist/src/components/JSDocExample.d.ts +12 -0
- package/dist/src/components/JSDocExample.d.ts.map +1 -0
- package/dist/src/components/JSDocExample.js +26 -0
- package/dist/src/components/JSDocExample.js.map +1 -0
- package/dist/src/components/JSDocParagraph.d.ts +10 -0
- package/dist/src/components/JSDocParagraph.d.ts.map +1 -0
- package/dist/src/components/JSDocParagraph.js +23 -0
- package/dist/src/components/JSDocParagraph.js.map +1 -0
- package/dist/src/components/MemberChainExpression.d.ts +11 -0
- package/dist/src/components/MemberChainExpression.d.ts.map +1 -0
- package/dist/src/components/MemberChainExpression.js +100 -0
- package/dist/src/components/MemberChainExpression.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts +1 -1
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +45 -42
- package/dist/src/components/ObjectExpression.js.map +1 -1
- package/dist/src/components/PackageDirectory.d.ts +1 -3
- package/dist/src/components/PackageDirectory.d.ts.map +1 -1
- package/dist/src/components/PackageDirectory.js +9 -16
- package/dist/src/components/PackageDirectory.js.map +1 -1
- package/dist/src/components/PackageJson.d.ts +39 -0
- package/dist/src/components/PackageJson.d.ts.map +1 -1
- package/dist/src/components/PackageJson.js +30 -12
- package/dist/src/components/PackageJson.js.map +1 -1
- package/dist/src/components/Reference.js +1 -1
- package/dist/src/components/Reference.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +13 -6
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/TsConfigJson.d.ts.map +1 -1
- package/dist/src/components/TsConfigJson.js.map +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js.map +1 -1
- package/dist/src/components/ValueExpression.d.ts.map +1 -1
- package/dist/src/components/ValueExpression.js.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +5 -4
- package/dist/src/components/VarDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +2 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +21 -21
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +1 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +5 -2
- package/dist/src/symbols/reference.js.map +1 -1
- 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 +4 -1
- package/dist/src/symbols/ts-output-symbol.js.map +1 -1
- package/dist/src/symbols/ts-package-scope.d.ts +0 -15
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +0 -8
- package/dist/src/symbols/ts-package-scope.js.map +1 -1
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/jsdoc.test.d.ts +2 -0
- package/dist/test/jsdoc.test.d.ts.map +1 -0
- package/dist/test/member-chain.test.d.ts +2 -0
- package/dist/test/member-chain.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/values.test.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -5
- package/src/components/ArrayExpression.tsx +22 -32
- package/src/components/BarrelFile.tsx +7 -13
- package/src/components/ClassDeclaration.tsx +33 -28
- package/src/components/CommaList.tsx +23 -0
- package/src/components/Declaration.tsx +14 -5
- package/src/components/EnumDeclaration.tsx +23 -16
- package/src/components/EnumMember.tsx +7 -4
- package/src/components/ExportStatement.tsx +9 -2
- package/src/components/FunctionCallExpression.tsx +18 -9
- package/src/components/FunctionDeclaration.tsx +173 -56
- package/src/components/ImportStatement.tsx +6 -9
- package/src/components/Interface.tsx +20 -13
- package/src/components/JSDoc.tsx +28 -0
- package/src/components/JSDocComment.tsx +23 -0
- package/src/components/JSDocExample.tsx +30 -0
- package/src/components/JSDocParagraph.tsx +35 -0
- package/src/components/MemberChainExpression.tsx +91 -0
- package/src/components/ObjectExpression.tsx +53 -48
- package/src/components/PackageDirectory.tsx +22 -30
- package/src/components/PackageJson.tsx +91 -29
- package/src/components/SourceFile.tsx +15 -8
- package/src/components/TsConfigJson.tsx +5 -3
- package/src/components/TypeDeclaration.tsx +5 -3
- package/src/components/ValueExpression.tsx +3 -1
- package/src/components/VarDeclaration.tsx +13 -7
- package/src/components/index.ts +2 -1
- package/src/components/stc/index.ts +1 -1
- package/src/symbols/reference.ts +7 -4
- package/src/symbols/ts-output-symbol.ts +6 -2
- package/src/symbols/ts-package-scope.ts +0 -28
- package/temp/api.json +802 -395
- package/test/array.test.tsx +40 -7
- package/test/basic.test.tsx +26 -21
- package/test/class.test.tsx +65 -53
- package/test/enum.test.tsx +18 -13
- package/test/externals.test.tsx +6 -7
- package/test/function-call-expression.test.tsx +39 -17
- package/test/function-declaration.test.tsx +96 -78
- package/test/imports.test.tsx +115 -75
- package/test/interface.test.tsx +32 -22
- package/test/jsdoc.test.tsx +154 -0
- package/test/member-chain.test.tsx +124 -0
- package/test/name-policy.test.tsx +33 -26
- package/test/package-external.test.tsx +106 -7
- package/test/package.test.tsx +57 -5
- package/test/reference.test.tsx +2 -6
- package/test/utils.tsx +3 -1
- package/test/value-expression.test.tsx +2 -6
- package/test/values.test.tsx +67 -73
- package/test/var-declaration.test.tsx +11 -5
- package/test/vitest.d.ts +6 -1
- package/tsconfig.json +8 -1
- package/dist/src/components/Block.d.ts +0 -6
- package/dist/src/components/Block.d.ts.map +0 -1
- package/dist/src/components/Block.js +0 -11
- package/dist/src/components/Block.js.map +0 -1
- package/src/components/Block.tsx +0 -12
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Props, refkey } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { StatementList } from "../../core/src/components/StatementList.jsx";
|
|
4
5
|
import {
|
|
5
6
|
FunctionDeclaration,
|
|
6
7
|
ParameterDescriptor,
|
|
@@ -10,55 +11,36 @@ import { toSourceText } from "./utils.js";
|
|
|
10
11
|
|
|
11
12
|
it("works", () => {
|
|
12
13
|
expect(toSourceText(<FunctionDeclaration name="foo" />)).toBe(d`
|
|
13
|
-
function foo() {
|
|
14
|
-
|
|
15
|
-
}
|
|
14
|
+
function foo() {}
|
|
16
15
|
`);
|
|
17
16
|
});
|
|
18
17
|
|
|
19
18
|
it("can be exported", () => {
|
|
20
19
|
expect(toSourceText(<FunctionDeclaration export name="foo" />)).toBe(d`
|
|
21
|
-
export function foo() {
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
`);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("can be a default export", () => {
|
|
28
|
-
expect(toSourceText(<FunctionDeclaration export default name="foo" />))
|
|
29
|
-
.toBe(d`
|
|
30
|
-
export default function foo() {
|
|
31
|
-
|
|
32
|
-
}
|
|
20
|
+
export function foo() {}
|
|
33
21
|
`);
|
|
34
22
|
});
|
|
35
23
|
|
|
36
24
|
it("can be a default export", () => {
|
|
37
25
|
expect(toSourceText(<FunctionDeclaration export default name="foo" />))
|
|
38
26
|
.toBe(d`
|
|
39
|
-
export default function foo() {
|
|
40
|
-
|
|
41
|
-
}
|
|
27
|
+
export default function foo() {}
|
|
42
28
|
`);
|
|
43
29
|
});
|
|
44
30
|
|
|
45
31
|
it("can be an async function", () => {
|
|
46
32
|
expect(toSourceText(<FunctionDeclaration async export name="foo" />)).toBe(d`
|
|
47
|
-
export async function foo() {
|
|
48
|
-
|
|
49
|
-
}
|
|
33
|
+
export async function foo() {}
|
|
50
34
|
`);
|
|
51
35
|
});
|
|
52
36
|
|
|
53
37
|
it("can be an async function with returnType", () => {
|
|
54
38
|
expect(
|
|
55
39
|
toSourceText(
|
|
56
|
-
<FunctionDeclaration async export name="foo" returnType="Foo"/>,
|
|
40
|
+
<FunctionDeclaration async export name="foo" returnType="Foo" />,
|
|
57
41
|
),
|
|
58
42
|
).toBe(d`
|
|
59
|
-
export async function foo(): Promise<Foo> {
|
|
60
|
-
|
|
61
|
-
}
|
|
43
|
+
export async function foo(): Promise<Foo> {}
|
|
62
44
|
`);
|
|
63
45
|
});
|
|
64
46
|
|
|
@@ -68,92 +50,126 @@ it("can be an async function with returnType element", () => {
|
|
|
68
50
|
}
|
|
69
51
|
expect(
|
|
70
52
|
toSourceText(
|
|
71
|
-
<FunctionDeclaration async export name="foo" returnType={<Foo />}/>,
|
|
53
|
+
<FunctionDeclaration async export name="foo" returnType={<Foo />} />,
|
|
72
54
|
),
|
|
73
55
|
).toBe(d`
|
|
74
|
-
export async function foo(): Promise<Foo> {
|
|
75
|
-
|
|
76
|
-
}
|
|
56
|
+
export async function foo(): Promise<Foo> {}
|
|
77
57
|
`);
|
|
78
58
|
});
|
|
79
59
|
|
|
80
60
|
it("supports parameters by element", () => {
|
|
81
|
-
const decl =
|
|
61
|
+
const decl = (
|
|
82
62
|
<FunctionDeclaration name="foo">
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// line break, which is not significant but we don't know that at transform
|
|
89
|
-
// time. Ideally the renderer would take care of this - I think it's the same
|
|
90
|
-
// problem as handling removal of linebreaks when the only contents of a line
|
|
91
|
-
// are something undefined, e.g. how
|
|
92
|
-
//
|
|
93
|
-
// <>a
|
|
94
|
-
// {undefined}
|
|
95
|
-
// b</>
|
|
96
|
-
//
|
|
97
|
-
// should render to
|
|
98
|
-
//
|
|
99
|
-
// a
|
|
100
|
-
// b
|
|
101
|
-
//
|
|
102
|
-
// so in principle this can be fixed later.
|
|
63
|
+
return a + b;
|
|
64
|
+
<FunctionDeclaration.Parameters>a, b</FunctionDeclaration.Parameters>
|
|
65
|
+
</FunctionDeclaration>
|
|
66
|
+
);
|
|
67
|
+
|
|
103
68
|
expect(toSourceText(decl)).toBe(d`
|
|
104
69
|
function foo(a, b) {
|
|
105
70
|
return a + b;
|
|
106
|
-
|
|
107
71
|
}
|
|
108
72
|
`);
|
|
109
73
|
});
|
|
110
74
|
|
|
75
|
+
it("supports type parameters by descriptor object", () => {
|
|
76
|
+
const decl = (
|
|
77
|
+
<FunctionDeclaration
|
|
78
|
+
name="foo"
|
|
79
|
+
typeParameters={{ a: "any", b: "any" }}
|
|
80
|
+
></FunctionDeclaration>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
expect(toSourceText(decl)).toBe(d`
|
|
84
|
+
function foo<a extends any, b extends any>() {}
|
|
85
|
+
`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("supports type parameters by descriptor array", () => {
|
|
89
|
+
const decl = (
|
|
90
|
+
<FunctionDeclaration
|
|
91
|
+
name="foo"
|
|
92
|
+
typeParameters={["a", "b"]}
|
|
93
|
+
></FunctionDeclaration>
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
expect(toSourceText(decl)).toBe(d`
|
|
97
|
+
function foo<a, b>() {}
|
|
98
|
+
`);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("supports type parameters by element", () => {
|
|
102
|
+
const decl = (
|
|
103
|
+
<FunctionDeclaration name="foo">
|
|
104
|
+
<FunctionDeclaration.TypeParameters>
|
|
105
|
+
a, b
|
|
106
|
+
</FunctionDeclaration.TypeParameters>
|
|
107
|
+
</FunctionDeclaration>
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
expect(toSourceText(decl)).toBe(d`
|
|
111
|
+
function foo<a, b>() {}
|
|
112
|
+
`);
|
|
113
|
+
});
|
|
114
|
+
|
|
111
115
|
describe("symbols", () => {
|
|
112
116
|
it("creates a nested scope", () => {
|
|
113
117
|
const innerRefkey = refkey();
|
|
114
118
|
const outerRefkey = refkey();
|
|
115
|
-
const decl =
|
|
116
|
-
|
|
119
|
+
const decl = (
|
|
120
|
+
<StatementList>
|
|
117
121
|
<FunctionDeclaration name="foo">
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
<StatementList>
|
|
123
|
+
{innerRefkey}
|
|
124
|
+
<VarDeclaration name="refme" refkey={innerRefkey}>
|
|
125
|
+
1
|
|
126
|
+
</VarDeclaration>
|
|
127
|
+
</StatementList>
|
|
128
|
+
</FunctionDeclaration>
|
|
129
|
+
<VarDeclaration name="refme" refkey={outerRefkey}>
|
|
130
|
+
2
|
|
131
|
+
</VarDeclaration>
|
|
122
132
|
{outerRefkey}
|
|
123
|
-
|
|
133
|
+
</StatementList>
|
|
134
|
+
);
|
|
124
135
|
expect(toSourceText(decl)).toBe(d`
|
|
125
136
|
function foo() {
|
|
126
|
-
refme
|
|
137
|
+
refme;
|
|
127
138
|
const refme = 1;
|
|
128
139
|
};
|
|
129
140
|
const refme = 2;
|
|
130
|
-
refme
|
|
141
|
+
refme;
|
|
131
142
|
`);
|
|
132
143
|
});
|
|
133
144
|
|
|
134
145
|
it("throws an error when trying to access a symbol in a nested function scope", () => {
|
|
135
146
|
const innerRefkey = refkey();
|
|
136
|
-
const decl =
|
|
147
|
+
const decl = (
|
|
137
148
|
<>
|
|
138
149
|
<FunctionDeclaration name="foo">
|
|
139
|
-
<VarDeclaration name="refme" refkey={innerRefkey}>
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
150
|
+
<VarDeclaration name="refme" refkey={innerRefkey}>
|
|
151
|
+
1
|
|
152
|
+
</VarDeclaration>
|
|
153
|
+
</FunctionDeclaration>
|
|
154
|
+
;{innerRefkey}
|
|
155
|
+
</>
|
|
156
|
+
);
|
|
143
157
|
expect(() => toSourceText(decl)).toThrow(/Cannot reference a symbol/);
|
|
144
158
|
});
|
|
145
159
|
|
|
146
160
|
it("creates symbols for parameters", () => {
|
|
147
161
|
const rk = refkey();
|
|
148
162
|
|
|
149
|
-
const decl =
|
|
163
|
+
const decl = (
|
|
150
164
|
<>
|
|
151
|
-
<FunctionDeclaration
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
165
|
+
<FunctionDeclaration
|
|
166
|
+
name="foo"
|
|
167
|
+
parameters={{ sym: { type: "any", refkey: rk } }}
|
|
168
|
+
>
|
|
169
|
+
<FunctionDeclaration name="bar">{rk}</FunctionDeclaration>
|
|
155
170
|
</FunctionDeclaration>
|
|
156
|
-
|
|
171
|
+
</>
|
|
172
|
+
);
|
|
157
173
|
|
|
158
174
|
expect(toSourceText(decl)).toBe(d`
|
|
159
175
|
function foo(sym: any) {
|
|
@@ -165,12 +181,13 @@ describe("symbols", () => {
|
|
|
165
181
|
});
|
|
166
182
|
|
|
167
183
|
it("creates symbols for parameters and addresses conflicts", () => {
|
|
168
|
-
const decl =
|
|
184
|
+
const decl = (
|
|
169
185
|
<>
|
|
170
|
-
<FunctionDeclaration name="foo" parameters={{conflict: "any"}}>
|
|
171
|
-
<VarDeclaration name="conflict">1</VarDeclaration
|
|
186
|
+
<FunctionDeclaration name="foo" parameters={{ conflict: "any" }}>
|
|
187
|
+
<VarDeclaration name="conflict">1</VarDeclaration>;
|
|
172
188
|
</FunctionDeclaration>
|
|
173
|
-
|
|
189
|
+
</>
|
|
190
|
+
);
|
|
174
191
|
|
|
175
192
|
expect(toSourceText(decl)).toBe(d`
|
|
176
193
|
function foo(conflict: any) {
|
|
@@ -185,12 +202,13 @@ describe("symbols", () => {
|
|
|
185
202
|
type: "any",
|
|
186
203
|
optional: true,
|
|
187
204
|
};
|
|
188
|
-
const decl =
|
|
205
|
+
const decl = (
|
|
189
206
|
<>
|
|
190
|
-
<FunctionDeclaration name="foo" parameters={{foo: paramDesc}}>
|
|
207
|
+
<FunctionDeclaration name="foo" parameters={{ foo: paramDesc }}>
|
|
191
208
|
console.log(foo);
|
|
192
209
|
</FunctionDeclaration>
|
|
193
|
-
|
|
210
|
+
</>
|
|
211
|
+
);
|
|
194
212
|
|
|
195
213
|
expect(toSourceText(decl)).toBe(d`
|
|
196
214
|
function foo(foo?: any) {
|
package/test/imports.test.tsx
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Output,
|
|
3
|
+
SourceDirectory,
|
|
4
|
+
StatementList,
|
|
5
|
+
refkey,
|
|
6
|
+
render,
|
|
7
|
+
} from "@alloy-js/core";
|
|
2
8
|
import "@alloy-js/core/testing";
|
|
3
9
|
import { it } from "vitest";
|
|
4
10
|
import * as ts from "../src/components/index.js";
|
|
@@ -10,7 +16,12 @@ it("works with default imports", () => {
|
|
|
10
16
|
const res = render(
|
|
11
17
|
<Output>
|
|
12
18
|
<ts.SourceFile path="test1.ts">
|
|
13
|
-
<ts.FunctionDeclaration
|
|
19
|
+
<ts.FunctionDeclaration
|
|
20
|
+
export
|
|
21
|
+
default
|
|
22
|
+
name="asdf"
|
|
23
|
+
refkey={refkey("test")}
|
|
24
|
+
/>
|
|
14
25
|
</ts.SourceFile>
|
|
15
26
|
|
|
16
27
|
<ts.SourceFile path="test2.ts">
|
|
@@ -21,9 +32,7 @@ it("works with default imports", () => {
|
|
|
21
32
|
|
|
22
33
|
assertFileContents(res, {
|
|
23
34
|
"test1.ts": `
|
|
24
|
-
export default function asdf() {
|
|
25
|
-
|
|
26
|
-
}
|
|
35
|
+
export default function asdf() {}
|
|
27
36
|
`,
|
|
28
37
|
"test2.ts": `
|
|
29
38
|
import asdf from "./test1.js";
|
|
@@ -37,7 +46,7 @@ it("works with named imports", () => {
|
|
|
37
46
|
const res = render(
|
|
38
47
|
<Output>
|
|
39
48
|
<ts.SourceFile path="test1.ts">
|
|
40
|
-
<ts.FunctionDeclaration export name="test" />
|
|
49
|
+
<ts.FunctionDeclaration export name="test" refkey={refkey("test")} />
|
|
41
50
|
</ts.SourceFile>
|
|
42
51
|
|
|
43
52
|
<ts.SourceFile path="test2.ts">
|
|
@@ -48,9 +57,7 @@ it("works with named imports", () => {
|
|
|
48
57
|
|
|
49
58
|
assertFileContents(res, {
|
|
50
59
|
"test1.ts": `
|
|
51
|
-
export function test() {
|
|
52
|
-
|
|
53
|
-
}
|
|
60
|
+
export function test() {}
|
|
54
61
|
`,
|
|
55
62
|
"test2.ts": `
|
|
56
63
|
import { test } from "./test1.js";
|
|
@@ -64,12 +71,18 @@ it("works with default and named imports", () => {
|
|
|
64
71
|
const res = render(
|
|
65
72
|
<Output>
|
|
66
73
|
<ts.SourceFile path="test1.ts">
|
|
67
|
-
<ts.FunctionDeclaration
|
|
68
|
-
|
|
74
|
+
<ts.FunctionDeclaration
|
|
75
|
+
export
|
|
76
|
+
default
|
|
77
|
+
name="test1"
|
|
78
|
+
refkey={refkey("test1")}
|
|
79
|
+
/>
|
|
80
|
+
<hbr />
|
|
81
|
+
<ts.FunctionDeclaration export name="test2" refkey={refkey("test2")} />
|
|
69
82
|
</ts.SourceFile>
|
|
70
83
|
|
|
71
84
|
<ts.SourceFile path="test2.ts">
|
|
72
|
-
const v1 = <Reference refkey={refkey("test1")}
|
|
85
|
+
const v1 = <Reference refkey={refkey("test1")} />;<hbr />
|
|
73
86
|
const v2 = <Reference refkey={refkey("test2")} />;
|
|
74
87
|
</ts.SourceFile>
|
|
75
88
|
</Output>,
|
|
@@ -77,12 +90,8 @@ it("works with default and named imports", () => {
|
|
|
77
90
|
|
|
78
91
|
assertFileContents(res, {
|
|
79
92
|
"test1.ts": `
|
|
80
|
-
export default function test1() {
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
export function test2() {
|
|
84
|
-
|
|
85
|
-
}
|
|
93
|
+
export default function test1() {}
|
|
94
|
+
export function test2() {}
|
|
86
95
|
`,
|
|
87
96
|
"test2.ts": `
|
|
88
97
|
import test1, { test2 } from "./test1.js";
|
|
@@ -97,41 +106,57 @@ it("works with default and named imports and name conflicts", () => {
|
|
|
97
106
|
const res = render(
|
|
98
107
|
<Output nameConflictResolver={tsNameConflictResolver}>
|
|
99
108
|
<ts.SourceFile path="test1.ts">
|
|
100
|
-
<ts.FunctionDeclaration
|
|
101
|
-
|
|
109
|
+
<ts.FunctionDeclaration
|
|
110
|
+
export
|
|
111
|
+
default
|
|
112
|
+
name="test1"
|
|
113
|
+
refkey={refkey("test1")}
|
|
114
|
+
/>
|
|
115
|
+
<br />
|
|
116
|
+
<ts.FunctionDeclaration export name="test2" refkey={refkey("test2")} />
|
|
102
117
|
</ts.SourceFile>
|
|
103
118
|
|
|
104
119
|
<ts.SourceFile path="test2.ts">
|
|
105
|
-
<ts.FunctionDeclaration
|
|
120
|
+
<ts.FunctionDeclaration
|
|
121
|
+
export
|
|
122
|
+
default
|
|
123
|
+
name="test1"
|
|
124
|
+
refkey={refkey("test3")}
|
|
125
|
+
/>
|
|
126
|
+
<br />
|
|
106
127
|
<ts.FunctionDeclaration export name="test2" refkey={refkey("test4")} />
|
|
107
128
|
</ts.SourceFile>
|
|
108
129
|
|
|
109
130
|
<ts.SourceFile path="test3.ts">
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
131
|
+
<StatementList>
|
|
132
|
+
<>
|
|
133
|
+
const v1 = <Reference refkey={refkey("test1")} />
|
|
134
|
+
</>
|
|
135
|
+
<>
|
|
136
|
+
const v1_1 = <Reference refkey={refkey("test2")} />
|
|
137
|
+
</>
|
|
138
|
+
<>
|
|
139
|
+
const v2 = <Reference refkey={refkey("test3")} />
|
|
140
|
+
</>
|
|
141
|
+
<>
|
|
142
|
+
const v3 = <Reference refkey={refkey("test3")} />
|
|
143
|
+
</>
|
|
144
|
+
<>
|
|
145
|
+
const v4 = <Reference refkey={refkey("test4")} />
|
|
146
|
+
</>
|
|
147
|
+
</StatementList>
|
|
115
148
|
</ts.SourceFile>
|
|
116
149
|
</Output>,
|
|
117
150
|
);
|
|
118
151
|
|
|
119
152
|
assertFileContents(res, {
|
|
120
153
|
"test1.ts": `
|
|
121
|
-
export default function test1() {
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
export function test2() {
|
|
125
|
-
|
|
126
|
-
}
|
|
154
|
+
export default function test1() {}
|
|
155
|
+
export function test2() {}
|
|
127
156
|
`,
|
|
128
157
|
"test2.ts": `
|
|
129
|
-
export default function test1() {
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
export function test2() {
|
|
133
|
-
|
|
134
|
-
}
|
|
158
|
+
export default function test1() {}
|
|
159
|
+
export function test2() {}
|
|
135
160
|
`,
|
|
136
161
|
"test3.ts": `
|
|
137
162
|
import test1_1, { test2 as test2_1 } from "./test1.js";
|
|
@@ -150,22 +175,49 @@ it("works with default and named imports and name conflicts and references in ne
|
|
|
150
175
|
const res = render(
|
|
151
176
|
<Output nameConflictResolver={tsNameConflictResolver}>
|
|
152
177
|
<ts.SourceFile path="test1.ts">
|
|
153
|
-
<ts.FunctionDeclaration
|
|
154
|
-
|
|
178
|
+
<ts.FunctionDeclaration
|
|
179
|
+
export
|
|
180
|
+
default
|
|
181
|
+
name="test1"
|
|
182
|
+
refkey={refkey("test1")}
|
|
183
|
+
/>
|
|
184
|
+
<hbr />
|
|
185
|
+
<ts.FunctionDeclaration export name="test2" refkey={refkey("test2")} />
|
|
155
186
|
</ts.SourceFile>
|
|
156
187
|
|
|
157
188
|
<ts.SourceFile path="test2.ts">
|
|
158
|
-
<ts.FunctionDeclaration
|
|
189
|
+
<ts.FunctionDeclaration
|
|
190
|
+
export
|
|
191
|
+
default
|
|
192
|
+
name="test1"
|
|
193
|
+
refkey={refkey("test3")}
|
|
194
|
+
/>
|
|
195
|
+
<hbr />
|
|
159
196
|
<ts.FunctionDeclaration export name="test2" refkey={refkey("test4")} />
|
|
160
197
|
</ts.SourceFile>
|
|
161
198
|
|
|
162
199
|
<ts.SourceFile path="test3.ts">
|
|
163
|
-
|
|
164
|
-
|
|
200
|
+
<StatementList>
|
|
201
|
+
<>
|
|
202
|
+
const v1 = <Reference refkey={refkey("test1")} />
|
|
203
|
+
</>
|
|
204
|
+
<>
|
|
205
|
+
const v1_1 = <Reference refkey={refkey("test2")} />
|
|
206
|
+
</>
|
|
207
|
+
</StatementList>
|
|
208
|
+
<hbr />
|
|
165
209
|
<ts.FunctionDeclaration name="foo">
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
210
|
+
<StatementList>
|
|
211
|
+
<>
|
|
212
|
+
const v2 = <Reference refkey={refkey("test3")} />
|
|
213
|
+
</>
|
|
214
|
+
<>
|
|
215
|
+
const v3 = <Reference refkey={refkey("test3")} />
|
|
216
|
+
</>
|
|
217
|
+
<>
|
|
218
|
+
const v4 = <Reference refkey={refkey("test4")} />
|
|
219
|
+
</>
|
|
220
|
+
</StatementList>
|
|
169
221
|
</ts.FunctionDeclaration>
|
|
170
222
|
</ts.SourceFile>
|
|
171
223
|
</Output>,
|
|
@@ -173,20 +225,12 @@ it("works with default and named imports and name conflicts and references in ne
|
|
|
173
225
|
|
|
174
226
|
assertFileContents(res, {
|
|
175
227
|
"test1.ts": `
|
|
176
|
-
export default function test1() {
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
export function test2() {
|
|
180
|
-
|
|
181
|
-
}
|
|
228
|
+
export default function test1() {}
|
|
229
|
+
export function test2() {}
|
|
182
230
|
`,
|
|
183
231
|
"test2.ts": `
|
|
184
|
-
export default function test1() {
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
export function test2() {
|
|
188
|
-
|
|
189
|
-
}
|
|
232
|
+
export default function test1() {}
|
|
233
|
+
export function test2() {}
|
|
190
234
|
`,
|
|
191
235
|
"test3.ts": `
|
|
192
236
|
import test1_1, { test2 as test2_1 } from "./test1.js";
|
|
@@ -208,14 +252,15 @@ it("works with imports from different directories", () => {
|
|
|
208
252
|
<Output>
|
|
209
253
|
<SourceDirectory path="src">
|
|
210
254
|
<ts.SourceFile path="test1.ts">
|
|
211
|
-
<ts.FunctionDeclaration export name="test" />
|
|
212
|
-
|
|
255
|
+
<ts.FunctionDeclaration export name="test" refkey={refkey("test")} />
|
|
256
|
+
<hbr />
|
|
257
|
+
const v = <Reference refkey={refkey("test2")} />;
|
|
213
258
|
</ts.SourceFile>
|
|
214
259
|
</SourceDirectory>
|
|
215
260
|
|
|
216
261
|
<ts.SourceFile path="test2.ts">
|
|
217
|
-
const v = <Reference refkey={refkey("test")}
|
|
218
|
-
<ts.FunctionDeclaration export name="test2" />
|
|
262
|
+
const v = <Reference refkey={refkey("test")} />;<hbr />
|
|
263
|
+
<ts.FunctionDeclaration export name="test2" refkey={refkey("test2")} />
|
|
219
264
|
</ts.SourceFile>
|
|
220
265
|
</Output>,
|
|
221
266
|
);
|
|
@@ -224,18 +269,14 @@ it("works with imports from different directories", () => {
|
|
|
224
269
|
"src/test1.ts": `
|
|
225
270
|
import { test2 } from "../test2.js";
|
|
226
271
|
|
|
227
|
-
export function test() {
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
const v = test2
|
|
272
|
+
export function test() {}
|
|
273
|
+
const v = test2;
|
|
231
274
|
`,
|
|
232
275
|
"test2.ts": `
|
|
233
276
|
import { test } from "./src/test1.js";
|
|
234
277
|
|
|
235
278
|
const v = test;
|
|
236
|
-
export function test2() {
|
|
237
|
-
|
|
238
|
-
}
|
|
279
|
+
export function test2() {}
|
|
239
280
|
`,
|
|
240
281
|
});
|
|
241
282
|
});
|
|
@@ -245,13 +286,14 @@ it("handles conflicts with local declarations", () => {
|
|
|
245
286
|
<Output nameConflictResolver={tsNameConflictResolver}>
|
|
246
287
|
<SourceDirectory path="src">
|
|
247
288
|
<ts.SourceFile path="test1.ts">
|
|
248
|
-
<ts.FunctionDeclaration export name="test" />
|
|
249
|
-
|
|
289
|
+
<ts.FunctionDeclaration export name="test" refkey={refkey("test")} />
|
|
290
|
+
<hbr />
|
|
291
|
+
const v = <Reference refkey={refkey("test2")} />;
|
|
250
292
|
</ts.SourceFile>
|
|
251
293
|
</SourceDirectory>
|
|
252
294
|
|
|
253
295
|
<ts.SourceFile path="test2.ts">
|
|
254
|
-
const v = <Reference refkey={refkey("test")}
|
|
296
|
+
const v = <Reference refkey={refkey("test")} />;<hbr />
|
|
255
297
|
<ts.FunctionDeclaration export name="test" />
|
|
256
298
|
</ts.SourceFile>
|
|
257
299
|
</Output>,
|
|
@@ -262,9 +304,7 @@ it("handles conflicts with local declarations", () => {
|
|
|
262
304
|
import { test as test_1 } from "./src/test1.js";
|
|
263
305
|
|
|
264
306
|
const v = test_1;
|
|
265
|
-
export function test() {
|
|
266
|
-
|
|
267
|
-
}
|
|
307
|
+
export function test() {}
|
|
268
308
|
`,
|
|
269
309
|
});
|
|
270
310
|
});
|