@alloy-js/typescript 0.19.0-dev.4 → 0.19.0-dev.6
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/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +67 -56
- package/dist/src/components/TypeRefContext.d.ts +2 -2
- package/dist/src/components/TypeRefContext.d.ts.map +1 -1
- package/dist/src/components/TypeRefContext.js +5 -5
- package/dist/src/components/interface/expression.test.js +73 -44
- package/dist/test/barrel.test.js +4 -3
- package/dist/test/class.test.js +2 -2
- package/dist/test/name-conflict.test.js +2 -1
- package/dist/test/name-policy.test.js +4 -3
- package/dist/test/new-expression.test.js +13 -10
- package/dist/test/source-file.test.js +3 -2
- package/dist/test/utils.d.ts +5 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +13 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/Interface.tsx +80 -49
- package/src/components/TypeRefContext.tsx +7 -7
- package/src/components/interface/expression.test.tsx +52 -33
- package/temp/api.json +14 -22
- package/test/barrel.test.tsx +4 -3
- package/test/class.test.tsx +2 -2
- package/test/name-conflict.test.tsx +2 -1
- package/test/name-policy.test.tsx +4 -3
- package/test/new-expression.test.tsx +13 -10
- package/test/source-file.test.tsx +3 -2
- package/test/utils.tsx +15 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interface.d.ts","sourceRoot":"","sources":["../../../src/components/Interface.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,
|
|
1
|
+
{"version":3,"file":"Interface.d.ts","sourceRoot":"","sources":["../../../src/components/Interface.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAUR,MAAM,EAGP,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAe,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAOrE,MAAM,WAAW,yBAA0B,SAAQ,oBAAoB;IACrE,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,cAAc,CAAC,EAAE,uBAAuB,EAAE,GAAG,MAAM,EAAE,CAAC;CACvD;AAqED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,YAEpE;yBAFe,oBAAoB;;;AAMpC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,mBAAmB,+CAiB/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,YAoD1D"}
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic, mergeProps as _$mergeProps } from "@alloy-js/core/jsx-runtime";
|
|
2
|
-
import { Block, childrenArray, findKeyedChild, findUnkeyedChildren, MemberScope, Name, OutputSymbolFlags, Show,
|
|
2
|
+
import { Block, childrenArray, createSymbolSlot, effect, emitSymbol, findKeyedChild, findUnkeyedChildren, MemberScope, Name, OutputSymbolFlags, Show, takeSymbols } from "@alloy-js/core";
|
|
3
3
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
4
4
|
import { Declaration } from "./Declaration.js";
|
|
5
5
|
import { JSDoc } from "./JSDoc.js";
|
|
6
|
+
import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
|
|
6
7
|
import { TypeParameters } from "./FunctionBase.js";
|
|
7
8
|
import { MemberDeclaration } from "./MemberDeclaration.js";
|
|
8
9
|
import { PropertyName } from "./PropertyName.js";
|
|
9
10
|
import { ensureTypeRefContext } from "./TypeRefContext.js";
|
|
10
11
|
const _InterfaceDeclaration = ensureTypeRefContext(props => {
|
|
12
|
+
const ExprSlot = createSymbolSlot();
|
|
13
|
+
effect(() => {
|
|
14
|
+
if (ExprSlot.ref.value) {
|
|
15
|
+
const takenSymbols = ExprSlot.ref.value;
|
|
16
|
+
for (const symbol of takenSymbols) {
|
|
17
|
+
// ignore non-transient symbols (likely not the result of an expression).
|
|
18
|
+
if (symbol.flags & OutputSymbolFlags.Transient) {
|
|
19
|
+
symbol.moveTo(sym);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
11
24
|
const children = childrenArray(() => props.children);
|
|
12
25
|
const typeParametersChildren = findKeyedChild(children, TypeParameters.tag) ?? undefined;
|
|
13
26
|
const sTypeParameters = typeParametersChildren ? ["<", typeParametersChildren, ">"] : _$createComponent(TypeParameters, {
|
|
@@ -17,7 +30,15 @@ const _InterfaceDeclaration = ensureTypeRefContext(props => {
|
|
|
17
30
|
});
|
|
18
31
|
const extendsPart = props.extends ? [" extends ", _$memo(() => props.extends)] : "";
|
|
19
32
|
const flags = OutputSymbolFlags.StaticMemberContainer;
|
|
33
|
+
const name = useTSNamePolicy().getName(props.name, "interface");
|
|
20
34
|
const filteredChildren = findUnkeyedChildren(children);
|
|
35
|
+
const sym = new TSOutputSymbol(name, {
|
|
36
|
+
refkeys: props.refkey,
|
|
37
|
+
default: props.default,
|
|
38
|
+
export: props.export,
|
|
39
|
+
metadata: props.metadata,
|
|
40
|
+
tsFlags: TSSymbolFlags.TypeSymbol
|
|
41
|
+
});
|
|
21
42
|
return [_$createComponent(Show, {
|
|
22
43
|
get when() {
|
|
23
44
|
return Boolean(props.doc);
|
|
@@ -33,9 +54,14 @@ const _InterfaceDeclaration = ensureTypeRefContext(props => {
|
|
|
33
54
|
nameKind: "interface",
|
|
34
55
|
flags: flags,
|
|
35
56
|
kind: "type",
|
|
57
|
+
symbol: sym,
|
|
36
58
|
get children() {
|
|
37
|
-
return ["interface ", _$createComponent(Name, {}), sTypeParameters, extendsPart, " ", _$createComponent(
|
|
38
|
-
children
|
|
59
|
+
return ["interface ", _$createComponent(Name, {}), sTypeParameters, extendsPart, " ", _$createComponent(ExprSlot, {
|
|
60
|
+
get children() {
|
|
61
|
+
return _$createComponent(InterfaceExpression, {
|
|
62
|
+
children: filteredChildren
|
|
63
|
+
});
|
|
64
|
+
}
|
|
39
65
|
})];
|
|
40
66
|
}
|
|
41
67
|
}))];
|
|
@@ -55,18 +81,14 @@ export function InterfaceDeclaration(props) {
|
|
|
55
81
|
}
|
|
56
82
|
InterfaceDeclaration.TypeParameters = TypeParameters;
|
|
57
83
|
export const InterfaceExpression = ensureTypeRefContext(props => {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
84
|
+
const symbol = new TSOutputSymbol("", {
|
|
85
|
+
flags: OutputSymbolFlags.StaticMemberContainer | OutputSymbolFlags.Transient
|
|
86
|
+
});
|
|
87
|
+
emitSymbol(symbol);
|
|
62
88
|
return _$createIntrinsic("group", {
|
|
63
89
|
get children() {
|
|
64
|
-
return _$createComponent(
|
|
65
|
-
|
|
66
|
-
"with": MemberScope,
|
|
67
|
-
props: {
|
|
68
|
-
owner: parentMemberSym
|
|
69
|
-
},
|
|
90
|
+
return _$createComponent(MemberScope, {
|
|
91
|
+
owner: symbol,
|
|
70
92
|
get children() {
|
|
71
93
|
return _$createComponent(Block, {
|
|
72
94
|
get children() {
|
|
@@ -96,52 +118,41 @@ export function InterfaceMember(props) {
|
|
|
96
118
|
} else {
|
|
97
119
|
const namer = useTSNamePolicy();
|
|
98
120
|
const name = namer.getName(props.name, "interface-member");
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
get refkey() {
|
|
113
|
-
return props.refkey;
|
|
114
|
-
},
|
|
115
|
-
get children() {
|
|
116
|
-
return [_$createComponent(Show, {
|
|
117
|
-
get when() {
|
|
118
|
-
return Boolean(props.doc);
|
|
119
|
-
},
|
|
120
|
-
get children() {
|
|
121
|
-
return [_$createComponent(JSDoc, {
|
|
122
|
-
get children() {
|
|
123
|
-
return props.doc;
|
|
124
|
-
}
|
|
125
|
-
}), _$createIntrinsic("hbr", {})];
|
|
126
|
-
}
|
|
127
|
-
}), readonly, _$createComponent(PropertyName, {}), optionality, ": ", type];
|
|
121
|
+
let sym = undefined;
|
|
122
|
+
if (props.name) {
|
|
123
|
+
sym = new TSOutputSymbol(name, {
|
|
124
|
+
refkeys: props.refkey,
|
|
125
|
+
flags: OutputSymbolFlags.StaticMember,
|
|
126
|
+
tsFlags: TSSymbolFlags.TypeSymbol | (props.nullish ?? props.optional ? TSSymbolFlags.Nullish : TSSymbolFlags.None)
|
|
127
|
+
});
|
|
128
|
+
const taken = takeSymbols();
|
|
129
|
+
effect(() => {
|
|
130
|
+
if (taken.size > 1) return;
|
|
131
|
+
const symbol = Array.from(taken)[0];
|
|
132
|
+
if (symbol?.flags & OutputSymbolFlags.Transient) {
|
|
133
|
+
symbol.moveTo(sym);
|
|
128
134
|
}
|
|
129
135
|
});
|
|
130
136
|
} else {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return Boolean(props.doc);
|
|
134
|
-
},
|
|
135
|
-
get children() {
|
|
136
|
-
return [_$createComponent(JSDoc, {
|
|
137
|
-
get children() {
|
|
138
|
-
return props.doc;
|
|
139
|
-
}
|
|
140
|
-
}), _$createIntrinsic("hbr", {})];
|
|
141
|
-
}
|
|
142
|
-
}), readonly, _$createComponent(PropertyName, {
|
|
143
|
-
name: name
|
|
144
|
-
}), optionality, ": ", type];
|
|
137
|
+
// noop
|
|
138
|
+
takeSymbols();
|
|
145
139
|
}
|
|
140
|
+
return _$createComponent(MemberDeclaration, {
|
|
141
|
+
symbol: sym,
|
|
142
|
+
get children() {
|
|
143
|
+
return [_$createComponent(Show, {
|
|
144
|
+
get when() {
|
|
145
|
+
return Boolean(props.doc);
|
|
146
|
+
},
|
|
147
|
+
get children() {
|
|
148
|
+
return [_$createComponent(JSDoc, {
|
|
149
|
+
get children() {
|
|
150
|
+
return props.doc;
|
|
151
|
+
}
|
|
152
|
+
}), _$createIntrinsic("hbr", {})];
|
|
153
|
+
}
|
|
154
|
+
}), readonly, _$createComponent(PropertyName, {}), optionality, ": ", type];
|
|
155
|
+
}
|
|
156
|
+
});
|
|
146
157
|
}
|
|
147
158
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Children } from "@alloy-js/core";
|
|
1
|
+
import type { Children, Component } from "@alloy-js/core";
|
|
2
2
|
export interface TypeRefContextProps {
|
|
3
3
|
/**
|
|
4
4
|
* Children
|
|
@@ -18,5 +18,5 @@ export declare const TypeRefContext: ({ children }: TypeRefContextProps) => Chil
|
|
|
18
18
|
* If not it will wrap in a {@link TypeRefContext} component.
|
|
19
19
|
* If yes it will not add an extra node and return the original component.
|
|
20
20
|
*/
|
|
21
|
-
export declare function ensureTypeRefContext<
|
|
21
|
+
export declare function ensureTypeRefContext<TProps>(Comp: Component<TProps>): (props: TProps) => Children;
|
|
22
22
|
//# sourceMappingURL=TypeRefContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeRefContext.d.ts","sourceRoot":"","sources":["../../../src/components/TypeRefContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"TypeRefContext.d.ts","sourceRoot":"","sources":["../../../src/components/TypeRefContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAM1D,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,MAAM,EACzC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,GACtB,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,CAa7B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createComponent as _$createComponent
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { isTypeRefContext, TypeRefContext as TypeRefContextDef } from "../context/type-ref-context.js";
|
|
3
3
|
/**
|
|
4
4
|
* Set the current context of reference to be type reference.
|
|
@@ -23,8 +23,8 @@ export const TypeRefContext = ({
|
|
|
23
23
|
* If not it will wrap in a {@link TypeRefContext} component.
|
|
24
24
|
* If yes it will not add an extra node and return the original component.
|
|
25
25
|
*/
|
|
26
|
-
export function ensureTypeRefContext(
|
|
27
|
-
return
|
|
26
|
+
export function ensureTypeRefContext(Comp) {
|
|
27
|
+
return props => {
|
|
28
28
|
const ref = isTypeRefContext();
|
|
29
29
|
if (!ref) {
|
|
30
30
|
return _$createComponent(TypeRefContextDef.Provider, {
|
|
@@ -32,10 +32,10 @@ export function ensureTypeRefContext(fn) {
|
|
|
32
32
|
type: true
|
|
33
33
|
},
|
|
34
34
|
get children() {
|
|
35
|
-
return
|
|
35
|
+
return _$createComponent(Comp, props);
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
return
|
|
39
|
+
return _$createComponent(Comp, props);
|
|
40
40
|
};
|
|
41
41
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { List } from "@alloy-js/core";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
|
-
import {
|
|
4
|
+
import { TestFile } from "../../../test/utils.js";
|
|
5
|
+
import { InterfaceDeclaration, InterfaceExpression, InterfaceMember } from "../Interface.js";
|
|
5
6
|
it("render expression", () => {
|
|
6
|
-
expect(_$createComponent(
|
|
7
|
+
expect(_$createComponent(TestFile, {
|
|
7
8
|
get children() {
|
|
8
|
-
return _$createComponent(
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
return _$createComponent(InterfaceExpression, {
|
|
10
|
+
get children() {
|
|
11
|
+
return _$createComponent(InterfaceMember, {
|
|
12
|
+
name: "foo",
|
|
13
|
+
type: "string"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
11
16
|
});
|
|
12
17
|
}
|
|
13
18
|
})).toRenderTo(`
|
|
@@ -17,16 +22,20 @@ it("render expression", () => {
|
|
|
17
22
|
`);
|
|
18
23
|
});
|
|
19
24
|
it("render nested", () => {
|
|
20
|
-
expect(_$createComponent(
|
|
25
|
+
expect(_$createComponent(TestFile, {
|
|
21
26
|
get children() {
|
|
22
|
-
return _$createComponent(
|
|
23
|
-
name: "foo",
|
|
27
|
+
return _$createComponent(InterfaceExpression, {
|
|
24
28
|
get children() {
|
|
25
|
-
return _$createComponent(
|
|
29
|
+
return _$createComponent(InterfaceMember, {
|
|
30
|
+
name: "foo",
|
|
26
31
|
get children() {
|
|
27
|
-
return _$createComponent(
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
return _$createComponent(InterfaceExpression, {
|
|
33
|
+
get children() {
|
|
34
|
+
return _$createComponent(InterfaceMember, {
|
|
35
|
+
name: "bar",
|
|
36
|
+
type: "string"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
30
39
|
});
|
|
31
40
|
}
|
|
32
41
|
});
|
|
@@ -42,23 +51,27 @@ it("render nested", () => {
|
|
|
42
51
|
`);
|
|
43
52
|
});
|
|
44
53
|
it("separate expressions don't conflict in name", () => {
|
|
45
|
-
expect(_$createComponent(
|
|
54
|
+
expect(_$createComponent(TestFile, {
|
|
46
55
|
get children() {
|
|
47
|
-
return
|
|
56
|
+
return _$createComponent(List, {
|
|
48
57
|
get children() {
|
|
49
|
-
return _$createComponent(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
return [_$createComponent(InterfaceExpression, {
|
|
59
|
+
get children() {
|
|
60
|
+
return _$createComponent(InterfaceMember, {
|
|
61
|
+
name: "bar",
|
|
62
|
+
type: "string"
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}), _$createComponent(InterfaceExpression, {
|
|
66
|
+
get children() {
|
|
67
|
+
return _$createComponent(InterfaceMember, {
|
|
68
|
+
name: "bar",
|
|
69
|
+
type: "string"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
})];
|
|
60
73
|
}
|
|
61
|
-
})
|
|
74
|
+
});
|
|
62
75
|
}
|
|
63
76
|
})).toRenderTo(`
|
|
64
77
|
{
|
|
@@ -69,31 +82,47 @@ it("separate expressions don't conflict in name", () => {
|
|
|
69
82
|
}
|
|
70
83
|
`);
|
|
71
84
|
});
|
|
72
|
-
it("separate
|
|
73
|
-
expect(_$createComponent(
|
|
85
|
+
it("separate expressions when in interface declaration", () => {
|
|
86
|
+
expect(_$createComponent(TestFile, {
|
|
74
87
|
get children() {
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
return _$createComponent(InterfaceMember, {
|
|
78
|
-
name: "bar",
|
|
79
|
-
type: "string"
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}), _$createComponent(InterfaceExpression, {
|
|
88
|
+
return _$createComponent(InterfaceDeclaration, {
|
|
89
|
+
name: "Test",
|
|
83
90
|
get children() {
|
|
84
91
|
return _$createComponent(InterfaceMember, {
|
|
85
|
-
name: "
|
|
86
|
-
|
|
92
|
+
name: "foo",
|
|
93
|
+
get children() {
|
|
94
|
+
return _$createComponent(List, {
|
|
95
|
+
joiner: " | ",
|
|
96
|
+
get children() {
|
|
97
|
+
return [_$createComponent(InterfaceExpression, {
|
|
98
|
+
get children() {
|
|
99
|
+
return _$createComponent(InterfaceMember, {
|
|
100
|
+
name: "bar",
|
|
101
|
+
type: "string"
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}), _$createComponent(InterfaceExpression, {
|
|
105
|
+
get children() {
|
|
106
|
+
return _$createComponent(InterfaceMember, {
|
|
107
|
+
name: "bar",
|
|
108
|
+
type: "string"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
})];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
87
115
|
});
|
|
88
116
|
}
|
|
89
|
-
})
|
|
117
|
+
});
|
|
90
118
|
}
|
|
91
119
|
})).toRenderTo(`
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
120
|
+
interface Test {
|
|
121
|
+
foo: {
|
|
122
|
+
bar: string
|
|
123
|
+
} | {
|
|
124
|
+
bar: string
|
|
125
|
+
}
|
|
97
126
|
}
|
|
98
127
|
`);
|
|
99
128
|
});
|
package/dist/test/barrel.test.js
CHANGED
|
@@ -4,6 +4,7 @@ import "@alloy-js/core/testing";
|
|
|
4
4
|
import { d } from "@alloy-js/core/testing";
|
|
5
5
|
import { expect, it } from "vitest";
|
|
6
6
|
import * as ts from "../src/components/index.js";
|
|
7
|
+
import { findFile } from "./utils.js";
|
|
7
8
|
it("exports everything from source files within it", () => {
|
|
8
9
|
const res = render(_$createComponent(Output, {
|
|
9
10
|
get children() {
|
|
@@ -23,11 +24,11 @@ it("exports everything from source files within it", () => {
|
|
|
23
24
|
}), _$createComponent(ts.BarrelFile, {})];
|
|
24
25
|
}
|
|
25
26
|
}));
|
|
26
|
-
expect(res.
|
|
27
|
+
expect(findFile(res, "components/index.ts").contents).toBe(d`
|
|
27
28
|
export * from "./c1.js";
|
|
28
29
|
export * from "./c2.js";
|
|
29
30
|
`);
|
|
30
|
-
expect(res.
|
|
31
|
+
expect(findFile(res, "index.ts").contents).toBe(d`
|
|
31
32
|
export * from "./test1.js";
|
|
32
33
|
export * from "./test2.js";
|
|
33
34
|
export * from "./components/index.js";
|
|
@@ -46,7 +47,7 @@ it("ignores non-TS files", () => {
|
|
|
46
47
|
}), _$createComponent(ts.BarrelFile, {})];
|
|
47
48
|
}
|
|
48
49
|
}));
|
|
49
|
-
expect(res.
|
|
50
|
+
expect(findFile(res, "index.ts").contents).toBe(d`
|
|
50
51
|
export * from "./test1.js";
|
|
51
52
|
export * from "./test2.js";
|
|
52
53
|
`);
|
package/dist/test/class.test.js
CHANGED
|
@@ -4,7 +4,7 @@ import "@alloy-js/core/testing";
|
|
|
4
4
|
import { d } from "@alloy-js/core/testing";
|
|
5
5
|
import { describe, expect, it } from "vitest";
|
|
6
6
|
import * as ts from "../src/components/index.js";
|
|
7
|
-
import { toSourceText } from "./utils.js";
|
|
7
|
+
import { findFile, toSourceText } from "./utils.js";
|
|
8
8
|
it("declares classes", () => {
|
|
9
9
|
const res = toSourceText(_$createComponent(ts.ClassDeclaration, {
|
|
10
10
|
name: "Foo"
|
|
@@ -298,7 +298,7 @@ describe("instance members", () => {
|
|
|
298
298
|
})];
|
|
299
299
|
}
|
|
300
300
|
}));
|
|
301
|
-
expect(tree.
|
|
301
|
+
expect(findFile(tree, "ref.ts").contents).toEqual(d`
|
|
302
302
|
import { one, two } from "./decl.js";
|
|
303
303
|
|
|
304
304
|
class Foo {
|
|
@@ -4,6 +4,7 @@ import { d } from "@alloy-js/core/testing";
|
|
|
4
4
|
import { camelCase } from "change-case";
|
|
5
5
|
import { expect, it } from "vitest";
|
|
6
6
|
import { FunctionDeclaration, SourceFile, TSSymbolFlags } from "../src/index.js";
|
|
7
|
+
import { findFile } from "./utils.js";
|
|
7
8
|
it("handles custom name conflict resolver based on metadata", () => {
|
|
8
9
|
function resolver(name, symbols) {
|
|
9
10
|
const goodNamedSymbols = symbols.filter(s => ~s.tsFlags & TSSymbolFlags.LocalImportSymbol);
|
|
@@ -93,7 +94,7 @@ it("handles custom name conflict resolver based on metadata", () => {
|
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
96
|
}));
|
|
96
|
-
expect(res.
|
|
97
|
+
expect(findFile(res, "test.ts").contents).toBe(d`
|
|
97
98
|
export function conflicty(
|
|
98
99
|
foo,
|
|
99
100
|
foo1,
|
|
@@ -5,6 +5,7 @@ import { d } from "@alloy-js/core/testing";
|
|
|
5
5
|
import { expect, it } from "vitest";
|
|
6
6
|
import * as ts from "../src/components/index.js";
|
|
7
7
|
import { createTSNamePolicy } from "../src/name-policy.js";
|
|
8
|
+
import { findFile } from "./utils.js";
|
|
8
9
|
it("applies to functions and variables", () => {
|
|
9
10
|
const ref1 = refkey({});
|
|
10
11
|
const ref2 = refkey({});
|
|
@@ -35,7 +36,7 @@ it("applies to functions and variables", () => {
|
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
}));
|
|
38
|
-
expect(res.
|
|
39
|
+
expect(findFile(res, "test.ts").contents).toEqual(d`
|
|
39
40
|
function fooBar() {}
|
|
40
41
|
const oneTwo = "hello";
|
|
41
42
|
fooBar;
|
|
@@ -72,7 +73,7 @@ it("keeps _ and $ prefix", () => {
|
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
}));
|
|
75
|
-
expect(res.
|
|
76
|
+
expect(findFile(res, "test.ts").contents).toEqual(d`
|
|
76
77
|
function _fooBar() {}
|
|
77
78
|
const $oneTwo = "hello";
|
|
78
79
|
_fooBar;
|
|
@@ -113,7 +114,7 @@ it("appends _ to reserved words", () => {
|
|
|
113
114
|
});
|
|
114
115
|
}
|
|
115
116
|
}));
|
|
116
|
-
expect(res.
|
|
117
|
+
expect(findFile(res, "test.ts").contents).toEqual(d`
|
|
117
118
|
function default_(await_: any) {}
|
|
118
119
|
const super_ = "hello";
|
|
119
120
|
default_;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
2
|
import { Output, refkey, render, StatementList } from "@alloy-js/core";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
|
-
import {
|
|
4
|
+
import { it } from "vitest";
|
|
5
5
|
import * as ts from "../src/index.js";
|
|
6
|
+
import { assertFileContents } from "./utils.js";
|
|
6
7
|
it("should instantiate classes", () => {
|
|
7
8
|
const varRk = refkey();
|
|
8
9
|
const classRk = refkey();
|
|
@@ -49,14 +50,16 @@ it("should instantiate classes", () => {
|
|
|
49
50
|
})];
|
|
50
51
|
}
|
|
51
52
|
}));
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
assertFileContents(tree, {
|
|
54
|
+
"inst.ts": d`
|
|
55
|
+
import { Foo } from "./decl.js";
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
export const one = new Foo();
|
|
58
|
+
`,
|
|
59
|
+
"decl.ts": d`
|
|
60
|
+
class Foo {
|
|
61
|
+
instanceProp = 42;
|
|
62
|
+
}
|
|
63
|
+
`
|
|
64
|
+
});
|
|
62
65
|
});
|
|
@@ -3,6 +3,7 @@ import { Output, render } from "@alloy-js/core";
|
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { expect, it } from "vitest";
|
|
5
5
|
import { SourceFile } from "../src/components/SourceFile.js";
|
|
6
|
+
import { findFile } from "./utils.js";
|
|
6
7
|
it("Includes header", () => {
|
|
7
8
|
const tree = render(_$createComponent(Output, {
|
|
8
9
|
get children() {
|
|
@@ -13,7 +14,7 @@ it("Includes header", () => {
|
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
16
|
}));
|
|
16
|
-
expect(tree.
|
|
17
|
+
expect(findFile(tree, "hi.ts").contents).toEqual(d`
|
|
17
18
|
// This is a header
|
|
18
19
|
|
|
19
20
|
hello!`);
|
|
@@ -28,7 +29,7 @@ it("Line wraps a header", () => {
|
|
|
28
29
|
});
|
|
29
30
|
}
|
|
30
31
|
}));
|
|
31
|
-
expect(tree.
|
|
32
|
+
expect(findFile(tree, "hi.ts").contents).toEqual(d`
|
|
32
33
|
// This is a very long header that is very long and should be wrapped. Meaning,
|
|
33
34
|
// it should be split into multiple lines.
|
|
34
35
|
|
package/dist/test/utils.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { Children,
|
|
1
|
+
import { Children, ContentOutputFile, OutputDirectory, PrintTreeOptions } from "@alloy-js/core";
|
|
2
|
+
export declare function TestFile(props: {
|
|
3
|
+
children?: Children;
|
|
4
|
+
}): Children;
|
|
2
5
|
export declare function toSourceText(c: Children, options?: PrintTreeOptions): string;
|
|
3
|
-
export declare function findFile(res: OutputDirectory, path: string):
|
|
6
|
+
export declare function findFile(res: OutputDirectory, path: string): ContentOutputFile;
|
|
4
7
|
export declare function assertFileContents(res: OutputDirectory, expectedFiles: Record<string, string>): void;
|
|
5
8
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/test/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../test/utils.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../test/utils.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,iBAAiB,EAEjB,eAAe,EAEf,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AAKxB,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAE,YAMtD;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAS5E;AAED,wBAAgB,QAAQ,CACtB,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,MAAM,GACX,iBAAiB,CA2BnB;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,eAAe,EACpB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAMtC"}
|
package/dist/test/utils.js
CHANGED
|
@@ -3,6 +3,18 @@ import { Output, render } from "@alloy-js/core";
|
|
|
3
3
|
import { dedent } from "@alloy-js/core/testing";
|
|
4
4
|
import { expect } from "vitest";
|
|
5
5
|
import * as ts from "../src/index.js";
|
|
6
|
+
export function TestFile(props) {
|
|
7
|
+
return _$createComponent(Output, {
|
|
8
|
+
get children() {
|
|
9
|
+
return _$createComponent(ts.SourceFile, {
|
|
10
|
+
path: "test.ts",
|
|
11
|
+
get children() {
|
|
12
|
+
return props.children;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
6
18
|
export function toSourceText(c, options) {
|
|
7
19
|
const res = render(_$createComponent(Output, {
|
|
8
20
|
get children() {
|
|
@@ -12,7 +24,7 @@ export function toSourceText(c, options) {
|
|
|
12
24
|
});
|
|
13
25
|
}
|
|
14
26
|
}), options);
|
|
15
|
-
return res.
|
|
27
|
+
return findFile(res, "test.ts").contents;
|
|
16
28
|
}
|
|
17
29
|
export function findFile(res, path) {
|
|
18
30
|
const result = findFileWorker(res, path);
|