@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,122 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Output, refkey, render, StatementList } from "@alloy-js/core";
|
|
3
|
+
import "@alloy-js/core/testing";
|
|
4
|
+
import { d } from "@alloy-js/core/testing";
|
|
5
|
+
import { expect, it } from "vitest";
|
|
6
|
+
import * as ts from "../src/components/index.js";
|
|
7
|
+
import { createTSNamePolicy } from "../src/name-policy.js";
|
|
8
|
+
it("applies to functions and variables", () => {
|
|
9
|
+
const ref1 = refkey({});
|
|
10
|
+
const ref2 = refkey({});
|
|
11
|
+
const namePolicy = createTSNamePolicy();
|
|
12
|
+
const res = render(_$createComponent(Output, {
|
|
13
|
+
namePolicy: namePolicy,
|
|
14
|
+
get children() {
|
|
15
|
+
return _$createComponent(ts.SourceFile, {
|
|
16
|
+
path: "test.ts",
|
|
17
|
+
get children() {
|
|
18
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
19
|
+
name: "foo-bar",
|
|
20
|
+
refkey: ref1
|
|
21
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(StatementList, {
|
|
22
|
+
get children() {
|
|
23
|
+
return [_$createComponent(ts.VarDeclaration, {
|
|
24
|
+
name: "one-two",
|
|
25
|
+
refkey: ref2,
|
|
26
|
+
children: "\"hello\""
|
|
27
|
+
}), _$createComponent(ts.Reference, {
|
|
28
|
+
refkey: ref1
|
|
29
|
+
}), _$createComponent(ts.Reference, {
|
|
30
|
+
refkey: ref2
|
|
31
|
+
})];
|
|
32
|
+
}
|
|
33
|
+
})];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
expect(res.contents[0].contents).toEqual(d`
|
|
39
|
+
function fooBar() {}
|
|
40
|
+
const oneTwo = "hello";
|
|
41
|
+
fooBar;
|
|
42
|
+
oneTwo;
|
|
43
|
+
`);
|
|
44
|
+
});
|
|
45
|
+
it("keeps _ and $ prefix", () => {
|
|
46
|
+
const ref1 = refkey({});
|
|
47
|
+
const ref2 = refkey({});
|
|
48
|
+
const namePolicy = createTSNamePolicy();
|
|
49
|
+
const res = render(_$createComponent(Output, {
|
|
50
|
+
namePolicy: namePolicy,
|
|
51
|
+
get children() {
|
|
52
|
+
return _$createComponent(ts.SourceFile, {
|
|
53
|
+
path: "test.ts",
|
|
54
|
+
get children() {
|
|
55
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
56
|
+
name: "_foo-bar",
|
|
57
|
+
refkey: ref1
|
|
58
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(StatementList, {
|
|
59
|
+
get children() {
|
|
60
|
+
return [_$createComponent(ts.VarDeclaration, {
|
|
61
|
+
name: "$one-two",
|
|
62
|
+
refkey: ref2,
|
|
63
|
+
children: "\"hello\""
|
|
64
|
+
}), _$createComponent(ts.Reference, {
|
|
65
|
+
refkey: ref1
|
|
66
|
+
}), _$createComponent(ts.Reference, {
|
|
67
|
+
refkey: ref2
|
|
68
|
+
})];
|
|
69
|
+
}
|
|
70
|
+
})];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
expect(res.contents[0].contents).toEqual(d`
|
|
76
|
+
function _fooBar() {}
|
|
77
|
+
const $oneTwo = "hello";
|
|
78
|
+
_fooBar;
|
|
79
|
+
$oneTwo;
|
|
80
|
+
`);
|
|
81
|
+
});
|
|
82
|
+
it("appends _ to reserved words", () => {
|
|
83
|
+
const ref1 = refkey({});
|
|
84
|
+
const ref2 = refkey({});
|
|
85
|
+
const namePolicy = createTSNamePolicy();
|
|
86
|
+
const res = render(_$createComponent(Output, {
|
|
87
|
+
namePolicy: namePolicy,
|
|
88
|
+
get children() {
|
|
89
|
+
return _$createComponent(ts.SourceFile, {
|
|
90
|
+
path: "test.ts",
|
|
91
|
+
get children() {
|
|
92
|
+
return [_$createComponent(ts.FunctionDeclaration, {
|
|
93
|
+
name: "default",
|
|
94
|
+
refkey: ref1,
|
|
95
|
+
parameters: [{
|
|
96
|
+
name: "await",
|
|
97
|
+
type: "any"
|
|
98
|
+
}]
|
|
99
|
+
}), _$createIntrinsic("hbr", {}), _$createComponent(StatementList, {
|
|
100
|
+
get children() {
|
|
101
|
+
return [_$createComponent(ts.VarDeclaration, {
|
|
102
|
+
name: "super",
|
|
103
|
+
refkey: ref2,
|
|
104
|
+
children: "\"hello\""
|
|
105
|
+
}), _$createComponent(ts.Reference, {
|
|
106
|
+
refkey: ref1
|
|
107
|
+
}), _$createComponent(ts.Reference, {
|
|
108
|
+
refkey: ref2
|
|
109
|
+
})];
|
|
110
|
+
}
|
|
111
|
+
})];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}));
|
|
116
|
+
expect(res.contents[0].contents).toEqual(d`
|
|
117
|
+
function default_(await_: any) {}
|
|
118
|
+
const super_ = "hello";
|
|
119
|
+
default_;
|
|
120
|
+
super_;
|
|
121
|
+
`);
|
|
122
|
+
});
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Output, refkey, render } 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 { findFile } from "./utils.js";
|
|
7
|
+
it("imports external packages", () => {
|
|
8
|
+
const res = render(_$createComponent(Output, {
|
|
9
|
+
get children() {
|
|
10
|
+
return [_$createComponent(ts.PackageDirectory, {
|
|
11
|
+
name: "greeting-lib",
|
|
12
|
+
path: "greeting-lib",
|
|
13
|
+
version: "1.0.0",
|
|
14
|
+
get children() {
|
|
15
|
+
return [_$createComponent(ts.SourceFile, {
|
|
16
|
+
path: "greetings.ts",
|
|
17
|
+
get children() {
|
|
18
|
+
return _$createComponent(ts.FunctionDeclaration, {
|
|
19
|
+
name: "getGreeting",
|
|
20
|
+
get refkey() {
|
|
21
|
+
return refkey("getGreeting");
|
|
22
|
+
},
|
|
23
|
+
children: "return \"Hello world!\";"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}), _$createComponent(ts.SourceFile, {
|
|
27
|
+
path: "logGreetings.ts",
|
|
28
|
+
get children() {
|
|
29
|
+
return _$createComponent(ts.FunctionDeclaration, {
|
|
30
|
+
"export": true,
|
|
31
|
+
name: "printGreeting",
|
|
32
|
+
get refkey() {
|
|
33
|
+
return refkey("printGreeting");
|
|
34
|
+
},
|
|
35
|
+
children: "console.log(\"Hello world!\");"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}), _$createComponent(ts.BarrelFile, {
|
|
39
|
+
"export": "."
|
|
40
|
+
})];
|
|
41
|
+
}
|
|
42
|
+
}), _$createComponent(ts.PackageDirectory, {
|
|
43
|
+
name: "consumer",
|
|
44
|
+
path: "consumer",
|
|
45
|
+
version: "1.0.0",
|
|
46
|
+
get children() {
|
|
47
|
+
return _$createComponent(ts.SourceFile, {
|
|
48
|
+
"export": ".",
|
|
49
|
+
path: "ref.ts",
|
|
50
|
+
get children() {
|
|
51
|
+
return [_$createComponent(ts.Reference, {
|
|
52
|
+
get refkey() {
|
|
53
|
+
return refkey("getGreeting");
|
|
54
|
+
}
|
|
55
|
+
}), "();"];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
})];
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
const consumerPkgJson = findFile(res, "consumer/package.json");
|
|
63
|
+
const greetingPkgJson = findFile(res, "greeting-lib/package.json");
|
|
64
|
+
const refFile = findFile(res, "consumer/ref.ts");
|
|
65
|
+
expect(consumerPkgJson.contents).toEqual(d`
|
|
66
|
+
{
|
|
67
|
+
"name": "consumer",
|
|
68
|
+
"version": "1.0.0",
|
|
69
|
+
"type": "module",
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"greeting-lib": "1.0.0"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"typescript": "^5.5.2"
|
|
75
|
+
},
|
|
76
|
+
"exports": {
|
|
77
|
+
".": "./dist/ref.js"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
`);
|
|
81
|
+
expect(greetingPkgJson.contents).toEqual(d`
|
|
82
|
+
{
|
|
83
|
+
"name": "greeting-lib",
|
|
84
|
+
"version": "1.0.0",
|
|
85
|
+
"type": "module",
|
|
86
|
+
"devDependencies": {
|
|
87
|
+
"typescript": "^5.5.2"
|
|
88
|
+
},
|
|
89
|
+
"exports": {
|
|
90
|
+
".": "./dist/index.js"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
`);
|
|
94
|
+
expect(refFile.contents).toEqual(d`
|
|
95
|
+
import { getGreeting } from "greeting-lib";
|
|
96
|
+
|
|
97
|
+
getGreeting();
|
|
98
|
+
`);
|
|
99
|
+
});
|
|
100
|
+
it("combines explicit dependencies with referenced dependencies", () => {
|
|
101
|
+
const res = render(_$createComponent(Output, {
|
|
102
|
+
get children() {
|
|
103
|
+
return [_$createComponent(ts.PackageDirectory, {
|
|
104
|
+
name: "greeting-lib",
|
|
105
|
+
path: "greeting-lib",
|
|
106
|
+
version: "1.0.0",
|
|
107
|
+
get children() {
|
|
108
|
+
return [_$createComponent(ts.SourceFile, {
|
|
109
|
+
path: "greetings.ts",
|
|
110
|
+
get children() {
|
|
111
|
+
return _$createComponent(ts.FunctionDeclaration, {
|
|
112
|
+
name: "getGreeting",
|
|
113
|
+
get refkey() {
|
|
114
|
+
return refkey("getGreeting");
|
|
115
|
+
},
|
|
116
|
+
children: "return \"Hello world!\";"
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}), _$createComponent(ts.SourceFile, {
|
|
120
|
+
path: "logGreetings.ts",
|
|
121
|
+
get children() {
|
|
122
|
+
return _$createComponent(ts.FunctionDeclaration, {
|
|
123
|
+
"export": true,
|
|
124
|
+
name: "printGreeting",
|
|
125
|
+
get refkey() {
|
|
126
|
+
return refkey("printGreeting");
|
|
127
|
+
},
|
|
128
|
+
children: "console.log(\"Hello world!\");"
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}), _$createComponent(ts.BarrelFile, {
|
|
132
|
+
"export": "."
|
|
133
|
+
})];
|
|
134
|
+
}
|
|
135
|
+
}), _$createComponent(ts.PackageDirectory, {
|
|
136
|
+
name: "consumer",
|
|
137
|
+
path: "consumer",
|
|
138
|
+
version: "1.0.0",
|
|
139
|
+
dependencies: {
|
|
140
|
+
foo: "bar"
|
|
141
|
+
},
|
|
142
|
+
get children() {
|
|
143
|
+
return _$createComponent(ts.SourceFile, {
|
|
144
|
+
"export": ".",
|
|
145
|
+
path: "ref.ts",
|
|
146
|
+
get children() {
|
|
147
|
+
return [_$createComponent(ts.Reference, {
|
|
148
|
+
get refkey() {
|
|
149
|
+
return refkey("getGreeting");
|
|
150
|
+
}
|
|
151
|
+
}), "();"];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
})];
|
|
156
|
+
}
|
|
157
|
+
}));
|
|
158
|
+
const consumerPkgJson = findFile(res, "consumer/package.json");
|
|
159
|
+
const greetingPkgJson = findFile(res, "greeting-lib/package.json");
|
|
160
|
+
const refFile = findFile(res, "consumer/ref.ts");
|
|
161
|
+
expect(consumerPkgJson.contents).toEqual(d`
|
|
162
|
+
{
|
|
163
|
+
"name": "consumer",
|
|
164
|
+
"version": "1.0.0",
|
|
165
|
+
"type": "module",
|
|
166
|
+
"dependencies": {
|
|
167
|
+
"foo": "bar",
|
|
168
|
+
"greeting-lib": "1.0.0"
|
|
169
|
+
},
|
|
170
|
+
"devDependencies": {
|
|
171
|
+
"typescript": "^5.5.2"
|
|
172
|
+
},
|
|
173
|
+
"exports": {
|
|
174
|
+
".": "./dist/ref.js"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
`);
|
|
178
|
+
expect(greetingPkgJson.contents).toEqual(d`
|
|
179
|
+
{
|
|
180
|
+
"name": "greeting-lib",
|
|
181
|
+
"version": "1.0.0",
|
|
182
|
+
"type": "module",
|
|
183
|
+
"devDependencies": {
|
|
184
|
+
"typescript": "^5.5.2"
|
|
185
|
+
},
|
|
186
|
+
"exports": {
|
|
187
|
+
".": "./dist/index.js"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
`);
|
|
191
|
+
expect(refFile.contents).toEqual(d`
|
|
192
|
+
import { getGreeting } from "greeting-lib";
|
|
193
|
+
|
|
194
|
+
getGreeting();
|
|
195
|
+
`);
|
|
196
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Output, render } from "@alloy-js/core";
|
|
3
|
+
import "@alloy-js/core/testing";
|
|
4
|
+
import { it } from "vitest";
|
|
5
|
+
import { PackageJsonFile } from "../src/components/PackageJson.js";
|
|
6
|
+
import { assertFileContents } from "./utils.js";
|
|
7
|
+
it("creates a simple package.json", () => {
|
|
8
|
+
const res = render(_$createComponent(Output, {
|
|
9
|
+
get children() {
|
|
10
|
+
return _$createComponent(PackageJsonFile, {
|
|
11
|
+
name: "test",
|
|
12
|
+
version: "1.0.0"
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
assertFileContents(res, {
|
|
17
|
+
"package.json": `
|
|
18
|
+
{
|
|
19
|
+
"name": "test",
|
|
20
|
+
"version": "1.0.0",
|
|
21
|
+
"type": "module"
|
|
22
|
+
}
|
|
23
|
+
`
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
it("makes a complex package.json", () => {
|
|
27
|
+
const res = render(_$createComponent(Output, {
|
|
28
|
+
get children() {
|
|
29
|
+
return _$createComponent(PackageJsonFile, {
|
|
30
|
+
name: "test",
|
|
31
|
+
version: "1.0.0",
|
|
32
|
+
author: "Brian Terlson",
|
|
33
|
+
license: "MIT",
|
|
34
|
+
description: "A test package!",
|
|
35
|
+
homepage: "https://example.com",
|
|
36
|
+
repository: "https://github.com/alloy-project/alloy",
|
|
37
|
+
keywords: ["test", "package"],
|
|
38
|
+
type: "commonjs",
|
|
39
|
+
scripts: {
|
|
40
|
+
build: "tsc -p .",
|
|
41
|
+
test: "vitest run",
|
|
42
|
+
"test:watch": "vitest -w"
|
|
43
|
+
},
|
|
44
|
+
dependencies: {
|
|
45
|
+
"@alloy-js/core": "^0.1.0",
|
|
46
|
+
"@alloy-js/typescript": "^0.1.0"
|
|
47
|
+
},
|
|
48
|
+
devDependencies: {
|
|
49
|
+
typescript: "^5.5.2"
|
|
50
|
+
},
|
|
51
|
+
exports: {
|
|
52
|
+
".": "./lib/index.js",
|
|
53
|
+
"./complex": {
|
|
54
|
+
main: "./lib/index.js",
|
|
55
|
+
export: "./lib/index.mjs"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
assertFileContents(res, {
|
|
62
|
+
"package.json": `
|
|
63
|
+
{
|
|
64
|
+
"name": "test",
|
|
65
|
+
"version": "1.0.0",
|
|
66
|
+
"author": "Brian Terlson",
|
|
67
|
+
"description": "A test package!",
|
|
68
|
+
"license": "MIT",
|
|
69
|
+
"homepage": "https://example.com",
|
|
70
|
+
"type": "commonjs",
|
|
71
|
+
"dependencies": {
|
|
72
|
+
"@alloy-js/core": "^0.1.0",
|
|
73
|
+
"@alloy-js/typescript": "^0.1.0"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"typescript": "^5.5.2"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "tsc -p .",
|
|
80
|
+
"test": "vitest run",
|
|
81
|
+
"test:watch": "vitest -w"
|
|
82
|
+
},
|
|
83
|
+
"exports": {
|
|
84
|
+
".": "./lib/index.js",
|
|
85
|
+
"./complex": {
|
|
86
|
+
"main": "./lib/index.js",
|
|
87
|
+
"export": "./lib/index.mjs"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
`
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Output, refkey, render } from "@alloy-js/core";
|
|
3
|
+
import "@alloy-js/core/testing";
|
|
4
|
+
import { it } from "vitest";
|
|
5
|
+
import * as ts from "../src/components/index.js";
|
|
6
|
+
import { PackageDirectory } from "../src/components/PackageDirectory.js";
|
|
7
|
+
import { assertFileContents } from "./utils.js";
|
|
8
|
+
it("exports source files", () => {
|
|
9
|
+
const res = render(_$createComponent(Output, {
|
|
10
|
+
get children() {
|
|
11
|
+
return _$createComponent(PackageDirectory, {
|
|
12
|
+
name: "greeting-js",
|
|
13
|
+
path: ".",
|
|
14
|
+
version: "1.0.0",
|
|
15
|
+
get children() {
|
|
16
|
+
return [_$createComponent(ts.SourceFile, {
|
|
17
|
+
path: "greeting.ts",
|
|
18
|
+
get children() {
|
|
19
|
+
return _$createComponent(ts.FunctionDeclaration, {
|
|
20
|
+
name: "getGreeting",
|
|
21
|
+
get refkey() {
|
|
22
|
+
return refkey("getGreeting");
|
|
23
|
+
},
|
|
24
|
+
children: "return \"Hello world!\";"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}), _$createComponent(ts.SourceFile, {
|
|
28
|
+
"export": true,
|
|
29
|
+
path: "printing.ts",
|
|
30
|
+
get children() {
|
|
31
|
+
return [_$createComponent(ts.VarDeclaration, {
|
|
32
|
+
name: "greeting",
|
|
33
|
+
get children() {
|
|
34
|
+
return [_$memo(() => refkey("getGreeting")), "()"];
|
|
35
|
+
}
|
|
36
|
+
}), ";", _$createIntrinsic("hbr", {}), _$createComponent(ts.FunctionDeclaration, {
|
|
37
|
+
"export": true,
|
|
38
|
+
name: "printGreeting",
|
|
39
|
+
get refkey() {
|
|
40
|
+
return refkey("printGreeting");
|
|
41
|
+
},
|
|
42
|
+
children: "console.log(greeting);"
|
|
43
|
+
})];
|
|
44
|
+
}
|
|
45
|
+
}), _$createComponent(ts.BarrelFile, {
|
|
46
|
+
"export": "."
|
|
47
|
+
})];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
assertFileContents(res, {
|
|
53
|
+
"greeting.ts": `
|
|
54
|
+
function getGreeting() {
|
|
55
|
+
return "Hello world!";
|
|
56
|
+
}
|
|
57
|
+
`,
|
|
58
|
+
"printing.ts": `
|
|
59
|
+
import { getGreeting } from "./greeting.js";
|
|
60
|
+
|
|
61
|
+
const greeting = getGreeting();
|
|
62
|
+
export function printGreeting() {
|
|
63
|
+
console.log(greeting);
|
|
64
|
+
}
|
|
65
|
+
`,
|
|
66
|
+
"index.ts": `
|
|
67
|
+
export * from "./greeting.js";
|
|
68
|
+
export * from "./printing.js";
|
|
69
|
+
`,
|
|
70
|
+
"package.json": `
|
|
71
|
+
{
|
|
72
|
+
"name": "greeting-js",
|
|
73
|
+
"version": "1.0.0",
|
|
74
|
+
"type": "module",
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"typescript": "^5.5.2"
|
|
77
|
+
},
|
|
78
|
+
"exports": {
|
|
79
|
+
"./printing.js": "./dist/printing.js",
|
|
80
|
+
".": "./dist/index.js"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
`
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
it("combines ref'd exports with explicit exports", () => {
|
|
87
|
+
const res = render(_$createComponent(Output, {
|
|
88
|
+
get children() {
|
|
89
|
+
return _$createComponent(PackageDirectory, {
|
|
90
|
+
name: "greeting-js",
|
|
91
|
+
path: ".",
|
|
92
|
+
version: "1.0.0",
|
|
93
|
+
exports: {
|
|
94
|
+
"./foo": "./foo/test.js"
|
|
95
|
+
},
|
|
96
|
+
get children() {
|
|
97
|
+
return _$createComponent(ts.SourceFile, {
|
|
98
|
+
"export": ".",
|
|
99
|
+
path: "index.ts",
|
|
100
|
+
get children() {
|
|
101
|
+
return _$createComponent(ts.FunctionDeclaration, {
|
|
102
|
+
"export": true,
|
|
103
|
+
name: "printGreeting",
|
|
104
|
+
get refkey() {
|
|
105
|
+
return refkey("printGreeting");
|
|
106
|
+
},
|
|
107
|
+
children: "console.log(greeting);"
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}));
|
|
115
|
+
assertFileContents(res, {
|
|
116
|
+
"index.ts": `
|
|
117
|
+
export function printGreeting() {
|
|
118
|
+
console.log(greeting);
|
|
119
|
+
}
|
|
120
|
+
`,
|
|
121
|
+
"package.json": `
|
|
122
|
+
{
|
|
123
|
+
"name": "greeting-js",
|
|
124
|
+
"version": "1.0.0",
|
|
125
|
+
"type": "module",
|
|
126
|
+
"devDependencies": {
|
|
127
|
+
"typescript": "^5.5.2"
|
|
128
|
+
},
|
|
129
|
+
"exports": {
|
|
130
|
+
"./foo": "./foo/test.js",
|
|
131
|
+
".": "./dist/index.js"
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
`
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Declaration, Output, refkey, render } from "@alloy-js/core";
|
|
3
|
+
import "@alloy-js/core/testing";
|
|
4
|
+
import { it } from "vitest";
|
|
5
|
+
import * as ts from "../src/components/index.js";
|
|
6
|
+
import { Reference } from "../src/components/Reference.js";
|
|
7
|
+
import { assertFileContents } from "./utils.js";
|
|
8
|
+
it("works with back references", () => {
|
|
9
|
+
const res = render(_$createComponent(Output, {
|
|
10
|
+
get children() {
|
|
11
|
+
return [_$createComponent(ts.SourceFile, {
|
|
12
|
+
path: "test1.ts",
|
|
13
|
+
get children() {
|
|
14
|
+
return _$createComponent(Declaration, {
|
|
15
|
+
name: "foo",
|
|
16
|
+
get refkey() {
|
|
17
|
+
return refkey("foo");
|
|
18
|
+
},
|
|
19
|
+
children: "const foo = 1;"
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}), _$createComponent(ts.SourceFile, {
|
|
23
|
+
path: "test2.ts",
|
|
24
|
+
get children() {
|
|
25
|
+
return ["const v = ", _$createComponent(Reference, {
|
|
26
|
+
get refkey() {
|
|
27
|
+
return refkey("foo");
|
|
28
|
+
}
|
|
29
|
+
}), ";"];
|
|
30
|
+
}
|
|
31
|
+
})];
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
assertFileContents(res, {
|
|
35
|
+
"test1.ts": `
|
|
36
|
+
const foo = 1;
|
|
37
|
+
`,
|
|
38
|
+
"test2.ts": `
|
|
39
|
+
import { foo } from "./test1.js";
|
|
40
|
+
|
|
41
|
+
const v = foo;
|
|
42
|
+
`
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it("works with forward references", () => {
|
|
46
|
+
const res = render(_$createComponent(Output, {
|
|
47
|
+
get children() {
|
|
48
|
+
return [_$createComponent(ts.SourceFile, {
|
|
49
|
+
path: "test2.ts",
|
|
50
|
+
get children() {
|
|
51
|
+
return ["const v = ", _$createComponent(Reference, {
|
|
52
|
+
get refkey() {
|
|
53
|
+
return refkey("foo");
|
|
54
|
+
}
|
|
55
|
+
}), ";"];
|
|
56
|
+
}
|
|
57
|
+
}), _$createComponent(ts.SourceFile, {
|
|
58
|
+
path: "test1.ts",
|
|
59
|
+
get children() {
|
|
60
|
+
return _$createComponent(Declaration, {
|
|
61
|
+
name: "foo",
|
|
62
|
+
get refkey() {
|
|
63
|
+
return refkey("foo");
|
|
64
|
+
},
|
|
65
|
+
children: "const foo = 1;"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
})];
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
assertFileContents(res, {
|
|
72
|
+
"test1.ts": `
|
|
73
|
+
const foo = 1;
|
|
74
|
+
`,
|
|
75
|
+
"test2.ts": `
|
|
76
|
+
import { foo } from "./test1.js";
|
|
77
|
+
|
|
78
|
+
const v = foo;
|
|
79
|
+
`
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Output, render } from "@alloy-js/core";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import { SourceFile } from "../src/components/SourceFile.js";
|
|
6
|
+
it("Includes header", () => {
|
|
7
|
+
const tree = render(_$createComponent(Output, {
|
|
8
|
+
get children() {
|
|
9
|
+
return _$createComponent(SourceFile, {
|
|
10
|
+
path: "hi.ts",
|
|
11
|
+
headerComment: "This is a header",
|
|
12
|
+
children: "hello!"
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
expect(tree.contents[0].contents).toEqual(d`
|
|
17
|
+
// This is a header
|
|
18
|
+
|
|
19
|
+
hello!`);
|
|
20
|
+
});
|
|
21
|
+
it("Line wraps a header", () => {
|
|
22
|
+
const tree = render(_$createComponent(Output, {
|
|
23
|
+
get children() {
|
|
24
|
+
return _$createComponent(SourceFile, {
|
|
25
|
+
path: "hi.ts",
|
|
26
|
+
headerComment: "This is a very long header that is very long and should be wrapped. Meaning, it should be split into multiple lines.",
|
|
27
|
+
children: "hello!"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
expect(tree.contents[0].contents).toEqual(d`
|
|
32
|
+
// This is a very long header that is very long and should be wrapped. Meaning,
|
|
33
|
+
// it should be split into multiple lines.
|
|
34
|
+
|
|
35
|
+
hello!`);
|
|
36
|
+
});
|