@alloy-js/typescript 0.1.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/LICENSE.txt +7 -0
- package/api-extractor.json +4 -0
- package/babel.config.cjs +4 -0
- package/dist/src/builtins/index.d.ts +2 -0
- package/dist/src/builtins/index.d.ts.map +1 -0
- package/dist/src/builtins/index.js +1 -0
- package/dist/src/builtins/index.js.map +1 -0
- package/dist/src/builtins/node.d.ts +183 -0
- package/dist/src/builtins/node.d.ts.map +1 -0
- package/dist/src/builtins/node.js +39 -0
- package/dist/src/builtins/node.js.map +1 -0
- package/dist/src/components/ArrayExpression.d.ts +7 -0
- package/dist/src/components/ArrayExpression.d.ts.map +1 -0
- package/dist/src/components/ArrayExpression.js +37 -0
- package/dist/src/components/ArrayExpression.js.map +1 -0
- package/dist/src/components/BarrelFile.d.ts +49 -0
- package/dist/src/components/BarrelFile.d.ts.map +1 -0
- package/dist/src/components/BarrelFile.js +73 -0
- package/dist/src/components/BarrelFile.js.map +1 -0
- package/dist/src/components/Block.d.ts +6 -0
- package/dist/src/components/Block.d.ts.map +1 -0
- package/dist/src/components/Block.js +11 -0
- package/dist/src/components/Block.js.map +1 -0
- package/dist/src/components/ClassDeclaration.d.ts +64 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -0
- package/dist/src/components/ClassDeclaration.js +122 -0
- package/dist/src/components/ClassDeclaration.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +53 -0
- package/dist/src/components/Declaration.d.ts.map +1 -0
- package/dist/src/components/Declaration.js +60 -0
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/EnumDeclaration.d.ts +12 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -0
- package/dist/src/components/EnumDeclaration.js +48 -0
- package/dist/src/components/EnumDeclaration.js.map +1 -0
- package/dist/src/components/EnumMember.d.ts +28 -0
- package/dist/src/components/EnumMember.d.ts.map +1 -0
- package/dist/src/components/EnumMember.js +28 -0
- package/dist/src/components/EnumMember.js.map +1 -0
- package/dist/src/components/ExportStatement.d.ts +7 -0
- package/dist/src/components/ExportStatement.d.ts.map +1 -0
- package/dist/src/components/ExportStatement.js +15 -0
- package/dist/src/components/ExportStatement.js.map +1 -0
- package/dist/src/components/FunctionCallExpression.d.ts +7 -0
- package/dist/src/components/FunctionCallExpression.d.ts.map +1 -0
- package/dist/src/components/FunctionCallExpression.js +14 -0
- package/dist/src/components/FunctionCallExpression.js.map +1 -0
- package/dist/src/components/FunctionDeclaration.d.ts +29 -0
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -0
- package/dist/src/components/FunctionDeclaration.js +91 -0
- package/dist/src/components/FunctionDeclaration.js.map +1 -0
- package/dist/src/components/ImportStatement.d.ts +11 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -0
- package/dist/src/components/ImportStatement.js +92 -0
- package/dist/src/components/ImportStatement.js.map +1 -0
- package/dist/src/components/Interface.d.ts +32 -0
- package/dist/src/components/Interface.d.ts.map +1 -0
- package/dist/src/components/Interface.js +50 -0
- package/dist/src/components/Interface.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts +16 -0
- package/dist/src/components/ObjectExpression.d.ts.map +1 -0
- package/dist/src/components/ObjectExpression.js +101 -0
- package/dist/src/components/ObjectExpression.js.map +1 -0
- package/dist/src/components/PackageDirectory.d.ts +23 -0
- package/dist/src/components/PackageDirectory.d.ts.map +1 -0
- package/dist/src/components/PackageDirectory.js +62 -0
- package/dist/src/components/PackageDirectory.js.map +1 -0
- package/dist/src/components/PackageJson.d.ts +16 -0
- package/dist/src/components/PackageJson.d.ts.map +1 -0
- package/dist/src/components/PackageJson.js +36 -0
- package/dist/src/components/PackageJson.js.map +1 -0
- package/dist/src/components/Reference.d.ts +6 -0
- package/dist/src/components/Reference.d.ts.map +1 -0
- package/dist/src/components/Reference.js +8 -0
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +15 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -0
- package/dist/src/components/SourceFile.js +62 -0
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/TsConfigJson.d.ts +5 -0
- package/dist/src/components/TsConfigJson.d.ts.map +1 -0
- package/dist/src/components/TsConfigJson.js +53 -0
- package/dist/src/components/TsConfigJson.js.map +1 -0
- package/dist/src/components/TypeDeclaration.d.ts +5 -0
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -0
- package/dist/src/components/TypeDeclaration.js +14 -0
- package/dist/src/components/TypeDeclaration.js.map +1 -0
- package/dist/src/components/ValueExpression.d.ts +5 -0
- package/dist/src/components/ValueExpression.d.ts.map +1 -0
- package/dist/src/components/ValueExpression.js +32 -0
- package/dist/src/components/ValueExpression.js.map +1 -0
- package/dist/src/components/VarDeclaration.d.ts +11 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -0
- package/dist/src/components/VarDeclaration.js +29 -0
- package/dist/src/components/VarDeclaration.js.map +1 -0
- package/dist/src/components/index.d.ts +22 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +22 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/stc/index.d.ts +102 -0
- package/dist/src/components/stc/index.d.ts.map +1 -0
- package/dist/src/components/stc/index.js +28 -0
- package/dist/src/components/stc/index.js.map +1 -0
- package/dist/src/create-package.d.ts +33 -0
- package/dist/src/create-package.d.ts.map +1 -0
- package/dist/src/create-package.js +50 -0
- package/dist/src/create-package.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/name-conflict-resolver.d.ts +3 -0
- package/dist/src/name-conflict-resolver.d.ts.map +1 -0
- package/dist/src/name-conflict-resolver.js +15 -0
- package/dist/src/name-conflict-resolver.js.map +1 -0
- package/dist/src/name-policy.d.ts +5 -0
- package/dist/src/name-policy.d.ts.map +1 -0
- package/dist/src/name-policy.js +23 -0
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/source-directory-data.d.ts +7 -0
- package/dist/src/source-directory-data.d.ts.map +1 -0
- package/dist/src/source-directory-data.js +13 -0
- package/dist/src/source-directory-data.js.map +1 -0
- package/dist/src/symbols/index.d.ts +7 -0
- package/dist/src/symbols/index.d.ts.map +1 -0
- package/dist/src/symbols/index.js +7 -0
- package/dist/src/symbols/index.js.map +1 -0
- package/dist/src/symbols/reference.d.ts +3 -0
- package/dist/src/symbols/reference.d.ts.map +1 -0
- package/dist/src/symbols/reference.js +75 -0
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/src/symbols/scopes.d.ts +16 -0
- package/dist/src/symbols/scopes.d.ts.map +1 -0
- package/dist/src/symbols/scopes.js +5 -0
- package/dist/src/symbols/scopes.js.map +1 -0
- package/dist/src/symbols/ts-member-scope.d.ts +9 -0
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-member-scope.js +10 -0
- package/dist/src/symbols/ts-member-scope.js.map +1 -0
- package/dist/src/symbols/ts-module-scope.d.ts +19 -0
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-module-scope.js +36 -0
- package/dist/src/symbols/ts-module-scope.js.map +1 -0
- package/dist/src/symbols/ts-output-symbol.d.ts +28 -0
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -0
- package/dist/src/symbols/ts-output-symbol.js +30 -0
- package/dist/src/symbols/ts-output-symbol.js.map +1 -0
- package/dist/src/symbols/ts-package-scope.d.ts +54 -0
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-package-scope.js +40 -0
- package/dist/src/symbols/ts-package-scope.js.map +1 -0
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +7 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/test/array.test.d.ts +2 -0
- package/dist/test/array.test.d.ts.map +1 -0
- package/dist/test/barrel.test.d.ts +2 -0
- package/dist/test/barrel.test.d.ts.map +1 -0
- package/dist/test/basic.test.d.ts +2 -0
- package/dist/test/basic.test.d.ts.map +1 -0
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/enum.test.d.ts +2 -0
- package/dist/test/enum.test.d.ts.map +1 -0
- package/dist/test/externals.test.d.ts +2 -0
- package/dist/test/externals.test.d.ts.map +1 -0
- package/dist/test/function-call-expression.test.d.ts +2 -0
- package/dist/test/function-call-expression.test.d.ts.map +1 -0
- package/dist/test/function-declaration.test.d.ts +2 -0
- package/dist/test/function-declaration.test.d.ts.map +1 -0
- package/dist/test/imports.test.d.ts +2 -0
- package/dist/test/imports.test.d.ts.map +1 -0
- package/dist/test/interface.test.d.ts +2 -0
- package/dist/test/interface.test.d.ts.map +1 -0
- package/dist/test/name-policy.test.d.ts +2 -0
- package/dist/test/name-policy.test.d.ts.map +1 -0
- package/dist/test/package-external.test.d.ts +2 -0
- package/dist/test/package-external.test.d.ts.map +1 -0
- package/dist/test/package.test.d.ts +2 -0
- package/dist/test/package.test.d.ts.map +1 -0
- package/dist/test/reference.test.d.ts +2 -0
- package/dist/test/reference.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +5 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/values.test.d.ts +2 -0
- package/dist/test/values.test.d.ts.map +1 -0
- package/dist/test/var-declaration.test.d.ts +2 -0
- package/dist/test/var-declaration.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +49 -0
- package/src/builtins/index.ts +1 -0
- package/src/builtins/node.ts +219 -0
- package/src/components/ArrayExpression.tsx +41 -0
- package/src/components/BarrelFile.tsx +96 -0
- package/src/components/Block.tsx +12 -0
- package/src/components/ClassDeclaration.tsx +145 -0
- package/src/components/Declaration.tsx +105 -0
- package/src/components/EnumDeclaration.tsx +53 -0
- package/src/components/EnumMember.tsx +52 -0
- package/src/components/ExportStatement.tsx +21 -0
- package/src/components/FunctionCallExpression.tsx +15 -0
- package/src/components/FunctionDeclaration.tsx +132 -0
- package/src/components/ImportStatement.tsx +131 -0
- package/src/components/Interface.tsx +62 -0
- package/src/components/ObjectExpression.tsx +130 -0
- package/src/components/PackageDirectory.tsx +104 -0
- package/src/components/PackageJson.tsx +69 -0
- package/src/components/Reference.tsx +12 -0
- package/src/components/SourceFile.tsx +71 -0
- package/src/components/TsConfigJson.tsx +62 -0
- package/src/components/TypeDeclaration.tsx +10 -0
- package/src/components/ValueExpression.tsx +32 -0
- package/src/components/VarDeclaration.tsx +42 -0
- package/src/components/index.ts +21 -0
- package/src/components/stc/index.ts +28 -0
- package/src/create-package.ts +108 -0
- package/src/index.ts +6 -0
- package/src/name-conflict-resolver.ts +22 -0
- package/src/name-policy.ts +39 -0
- package/src/source-directory-data.ts +25 -0
- package/src/symbols/index.ts +6 -0
- package/src/symbols/reference.ts +120 -0
- package/src/symbols/scopes.ts +28 -0
- package/src/symbols/ts-member-scope.ts +23 -0
- package/src/symbols/ts-module-scope.ts +66 -0
- package/src/symbols/ts-output-symbol.ts +63 -0
- package/src/symbols/ts-package-scope.ts +112 -0
- package/src/utils.ts +7 -0
- package/temp/api.json +9866 -0
- package/test/array.test.tsx +14 -0
- package/test/barrel.test.tsx +46 -0
- package/test/basic.test.tsx +78 -0
- package/test/class.test.tsx +181 -0
- package/test/enum.test.tsx +132 -0
- package/test/externals.test.tsx +139 -0
- package/test/function-call-expression.test.tsx +49 -0
- package/test/function-declaration.test.tsx +201 -0
- package/test/imports.test.tsx +213 -0
- package/test/interface.test.tsx +124 -0
- package/test/name-policy.test.tsx +62 -0
- package/test/package-external.test.tsx +75 -0
- package/test/package.test.tsx +68 -0
- package/test/reference.test.tsx +59 -0
- package/test/utils.tsx +59 -0
- package/test/values.test.tsx +292 -0
- package/test/var-declaration.test.tsx +45 -0
- package/test/vitest.d.ts +10 -0
- package/tsconfig.json +11 -0
- package/tsdoc-metadata.json +11 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { d } from "@alloy-js/core/testing";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import { ArrayExpression } from "../src/index.js";
|
|
4
|
+
import { toSourceText } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
it("works", () => {
|
|
7
|
+
expect(toSourceText(<ArrayExpression jsValue={[1,2,3]} />)).toBe(d`
|
|
8
|
+
[
|
|
9
|
+
1,
|
|
10
|
+
2,
|
|
11
|
+
3
|
|
12
|
+
]
|
|
13
|
+
`);
|
|
14
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Output, render, SourceDirectory, SourceFile } from "@alloy-js/core";
|
|
2
|
+
import "@alloy-js/core/testing";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as ts from "../src/components/index.js";
|
|
6
|
+
|
|
7
|
+
it("exports everything from source files within it", () => {
|
|
8
|
+
const res = render(
|
|
9
|
+
<Output>
|
|
10
|
+
<ts.SourceFile path="test1.ts" />
|
|
11
|
+
<ts.SourceFile path="test2.ts" />
|
|
12
|
+
<SourceDirectory path="components">
|
|
13
|
+
<ts.SourceFile path="c1.ts" />
|
|
14
|
+
<ts.SourceFile path="c2.ts" />
|
|
15
|
+
<ts.BarrelFile />
|
|
16
|
+
</SourceDirectory>
|
|
17
|
+
<ts.BarrelFile />
|
|
18
|
+
</Output>,
|
|
19
|
+
);
|
|
20
|
+
expect((res.contents[2].contents[2] as any).contents).toBe(d`
|
|
21
|
+
export * from "./c1.js";
|
|
22
|
+
export * from "./c2.js";
|
|
23
|
+
`);
|
|
24
|
+
|
|
25
|
+
expect(res.contents[3].contents).toBe(d`
|
|
26
|
+
export * from "./test1.js";
|
|
27
|
+
export * from "./test2.js";
|
|
28
|
+
export * from "./components/index.js";
|
|
29
|
+
`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("ignores non-TS files", () => {
|
|
33
|
+
const res = render(
|
|
34
|
+
<Output>
|
|
35
|
+
<SourceFile path="test.txt" filetype="text" />
|
|
36
|
+
<ts.SourceFile path="test1.ts" />
|
|
37
|
+
<ts.SourceFile path="test2.ts" />
|
|
38
|
+
<ts.BarrelFile />
|
|
39
|
+
</Output>,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(res.contents[3].contents).toBe(d`
|
|
43
|
+
export * from "./test1.js";
|
|
44
|
+
export * from "./test2.js";
|
|
45
|
+
`);
|
|
46
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Output, refkey, render, SourceFile } from "@alloy-js/core";
|
|
2
|
+
import "@alloy-js/core/testing";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as ts from "../src/components/index.js";
|
|
6
|
+
import { Reference } from "../src/components/Reference.js";
|
|
7
|
+
import { findFile } from "./utils.js";
|
|
8
|
+
|
|
9
|
+
it("works", () => {
|
|
10
|
+
const fnSpec = {
|
|
11
|
+
greeting: "Hello",
|
|
12
|
+
farewell: "Goodbye",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const greetKey = refkey(fnSpec, "greet");
|
|
16
|
+
const farewellKey = refkey(fnSpec, "farewell");
|
|
17
|
+
|
|
18
|
+
const res = render(
|
|
19
|
+
<Output>
|
|
20
|
+
<SourceFile path="readme.md" filetype="markdown">
|
|
21
|
+
This is a sample output project.
|
|
22
|
+
</SourceFile>
|
|
23
|
+
|
|
24
|
+
<ts.SourceFile path="index.ts">
|
|
25
|
+
console.log("Hello world!");
|
|
26
|
+
</ts.SourceFile>
|
|
27
|
+
|
|
28
|
+
<ts.SourceFile path="test2.ts">
|
|
29
|
+
console.log(<Reference refkey={greetKey} />("world"));
|
|
30
|
+
console.log(<Reference refkey={farewellKey} />("world"));
|
|
31
|
+
</ts.SourceFile>
|
|
32
|
+
|
|
33
|
+
<ts.SourceFile path="test1.ts">
|
|
34
|
+
<ts.FunctionDeclaration
|
|
35
|
+
name={"say" + fnSpec.greeting}
|
|
36
|
+
refkey={greetKey}
|
|
37
|
+
parameters={{str: "string"}}
|
|
38
|
+
>
|
|
39
|
+
return "{fnSpec.greeting} " + str;
|
|
40
|
+
</ts.FunctionDeclaration>
|
|
41
|
+
|
|
42
|
+
<ts.FunctionDeclaration
|
|
43
|
+
name={"say" + fnSpec.farewell}
|
|
44
|
+
refkey={farewellKey}
|
|
45
|
+
parameters={{str: "string"}}
|
|
46
|
+
>
|
|
47
|
+
return "{fnSpec.farewell} " + str;
|
|
48
|
+
</ts.FunctionDeclaration>
|
|
49
|
+
</ts.SourceFile>
|
|
50
|
+
|
|
51
|
+
</Output>,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
expect(findFile(res, "readme.md").contents).toEqual(d`
|
|
55
|
+
This is a sample output project.
|
|
56
|
+
`);
|
|
57
|
+
|
|
58
|
+
expect(findFile(res, "index.ts").contents).toEqual(d`
|
|
59
|
+
console.log("Hello world!");
|
|
60
|
+
`);
|
|
61
|
+
|
|
62
|
+
expect(findFile(res, "test1.ts").contents).toEqual(d`
|
|
63
|
+
function sayHello(str: string) {
|
|
64
|
+
return "Hello " + str;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function sayGoodbye(str: string) {
|
|
68
|
+
return "Goodbye " + str;
|
|
69
|
+
}
|
|
70
|
+
`);
|
|
71
|
+
|
|
72
|
+
expect(findFile(res, "test2.ts").contents).toEqual(d`
|
|
73
|
+
import { sayHello, sayGoodbye } from "./test1.js";
|
|
74
|
+
|
|
75
|
+
console.log(sayHello("world"));
|
|
76
|
+
console.log(sayGoodbye("world"));
|
|
77
|
+
`);
|
|
78
|
+
});
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { refkey } from "@alloy-js/core";
|
|
2
|
+
import "@alloy-js/core/testing";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import * as ts from "../src/components/index.js";
|
|
6
|
+
import { toSourceText } from "./utils.js";
|
|
7
|
+
|
|
8
|
+
it("declares classes", () => {
|
|
9
|
+
const res = toSourceText(<ts.ClassDeclaration name="Foo" />);
|
|
10
|
+
expect(res).toEqual(d`
|
|
11
|
+
class Foo {
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("accepts export and default", () => {
|
|
18
|
+
const res = toSourceText(<ts.ClassDeclaration name="Foo" export default />);
|
|
19
|
+
expect(res).toEqual(d`
|
|
20
|
+
export default class Foo {
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
`);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("creates extends", () => {
|
|
27
|
+
const res = toSourceText(<ts.ClassDeclaration name="Foo" extends="string" />);
|
|
28
|
+
|
|
29
|
+
expect(res).toEqual(d`
|
|
30
|
+
class Foo extends string {
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("instance members", () => {
|
|
37
|
+
it("can be created", () => {
|
|
38
|
+
const res = toSourceText(
|
|
39
|
+
<ts.ClassDeclaration name="Foo">
|
|
40
|
+
<ts.ClassField name="one" />
|
|
41
|
+
<ts.ClassField name="two" public />
|
|
42
|
+
<ts.ClassField name="three" private />
|
|
43
|
+
<ts.ClassField name="four" protected />
|
|
44
|
+
<ts.ClassField name="five" type="number" />
|
|
45
|
+
<ts.ClassField name="six" type="number">12</ts.ClassField>
|
|
46
|
+
<ts.ClassField name="seven" jsPrivate />
|
|
47
|
+
</ts.ClassDeclaration>,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(res).toEqual(d`
|
|
51
|
+
class Foo {
|
|
52
|
+
one;
|
|
53
|
+
public two;
|
|
54
|
+
private three;
|
|
55
|
+
protected four;
|
|
56
|
+
five: number;
|
|
57
|
+
six: number = 12;
|
|
58
|
+
#seven;
|
|
59
|
+
}
|
|
60
|
+
`);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("can be referenced", () => {
|
|
64
|
+
const one = refkey();
|
|
65
|
+
const res = toSourceText(
|
|
66
|
+
<ts.ClassDeclaration name="Foo">
|
|
67
|
+
<ts.ClassField name="one" refkey={one}>1</ts.ClassField>
|
|
68
|
+
<ts.ClassField name="two">{one} + 1</ts.ClassField>
|
|
69
|
+
</ts.ClassDeclaration>,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect(res).toEqual(d`
|
|
73
|
+
class Foo {
|
|
74
|
+
one = 1;
|
|
75
|
+
two = this.one + 1;
|
|
76
|
+
}
|
|
77
|
+
`);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("cannot be referenced outside the class", () => {
|
|
81
|
+
const one = refkey();
|
|
82
|
+
expect(() => {
|
|
83
|
+
toSourceText(
|
|
84
|
+
<>
|
|
85
|
+
<ts.ClassDeclaration name="Foo">
|
|
86
|
+
<ts.ClassField name="one" refkey={one}>1</ts.ClassField>
|
|
87
|
+
</ts.ClassDeclaration>
|
|
88
|
+
{one}
|
|
89
|
+
</>,
|
|
90
|
+
);
|
|
91
|
+
}).toThrow(/Cannot resolve member symbols/);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("static members", () => {
|
|
96
|
+
it("renders", () => {
|
|
97
|
+
const one = refkey();
|
|
98
|
+
const res = toSourceText(
|
|
99
|
+
<ts.ClassDeclaration name="Foo">
|
|
100
|
+
<ts.ClassField static name="one" refkey={one}>1</ts.ClassField>
|
|
101
|
+
</ts.ClassDeclaration>,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
expect(res).toBe(d`
|
|
105
|
+
class Foo {
|
|
106
|
+
static one = 1;
|
|
107
|
+
}
|
|
108
|
+
`);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("can be referenced", () => {
|
|
112
|
+
const one = refkey();
|
|
113
|
+
const res = toSourceText(
|
|
114
|
+
<>
|
|
115
|
+
<ts.ClassDeclaration name="Foo">
|
|
116
|
+
<ts.ClassField static name="one" refkey={one}>1</ts.ClassField>
|
|
117
|
+
</ts.ClassDeclaration>
|
|
118
|
+
{one};
|
|
119
|
+
</>,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
expect(res).toBe(d`
|
|
123
|
+
class Foo {
|
|
124
|
+
static one = 1;
|
|
125
|
+
}
|
|
126
|
+
Foo.one;
|
|
127
|
+
`);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("instance methods", () => {
|
|
132
|
+
it("renders", () => {
|
|
133
|
+
const one = refkey();
|
|
134
|
+
const a = refkey();
|
|
135
|
+
const b = refkey();
|
|
136
|
+
|
|
137
|
+
const res = toSourceText(
|
|
138
|
+
<ts.ClassDeclaration name="Foo">
|
|
139
|
+
<ts.ClassMethod name="one" refkey={one} />
|
|
140
|
+
<ts.ClassMethod name="two" public />
|
|
141
|
+
<ts.ClassMethod name="three" private />
|
|
142
|
+
<ts.ClassMethod name="four" protected />
|
|
143
|
+
<ts.ClassMethod name="five" parameters={{a: "string", b: "string"}} />
|
|
144
|
+
<ts.ClassMethod
|
|
145
|
+
name="six"
|
|
146
|
+
parameters={{a: {type: "number", refkey: a }, b: {type: "number", refkey: b }}}
|
|
147
|
+
returnType="number"
|
|
148
|
+
>
|
|
149
|
+
{one} = {a} + {b};
|
|
150
|
+
</ts.ClassMethod>
|
|
151
|
+
<ts.ClassMethod name="seven" jsPrivate />
|
|
152
|
+
</ts.ClassDeclaration>,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
expect(res).toEqual(d`
|
|
156
|
+
class Foo {
|
|
157
|
+
one() {
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
public two() {
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
private three() {
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
protected four() {
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
five(a: string, b: string) {
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
six(a: number, b: number): number {
|
|
173
|
+
this.one = a + b;
|
|
174
|
+
}
|
|
175
|
+
#seven() {
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
`);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Output, refkey } from "@alloy-js/core";
|
|
2
|
+
import "@alloy-js/core/testing";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import * as ts from "../src/index.js";
|
|
6
|
+
|
|
7
|
+
it("renders an enum with enum children", () => {
|
|
8
|
+
expect(
|
|
9
|
+
<Output>
|
|
10
|
+
<ts.SourceFile path="foo.ts">
|
|
11
|
+
<ts.EnumDeclaration name="MyEnum">
|
|
12
|
+
<ts.EnumMember name="foo" value="1" />,
|
|
13
|
+
<ts.EnumMember name="bar" value="2" />
|
|
14
|
+
</ts.EnumDeclaration>
|
|
15
|
+
</ts.SourceFile>
|
|
16
|
+
</Output>,
|
|
17
|
+
).toRenderTo(`
|
|
18
|
+
enum MyEnum {
|
|
19
|
+
foo = 1,
|
|
20
|
+
bar = 2
|
|
21
|
+
}
|
|
22
|
+
`);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("renders an enum with enum children specifying JS Value", () => {
|
|
26
|
+
expect(
|
|
27
|
+
<Output>
|
|
28
|
+
<ts.SourceFile path="foo.ts">
|
|
29
|
+
<ts.EnumDeclaration name="MyEnum">
|
|
30
|
+
<ts.EnumMember name="foo" jsValue="1" />,
|
|
31
|
+
<ts.EnumMember name="bar" jsValue={2} />
|
|
32
|
+
</ts.EnumDeclaration>
|
|
33
|
+
</ts.SourceFile>
|
|
34
|
+
</Output>,
|
|
35
|
+
).toRenderTo(`
|
|
36
|
+
enum MyEnum {
|
|
37
|
+
foo = "1",
|
|
38
|
+
bar = 2
|
|
39
|
+
}
|
|
40
|
+
`);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("renders an enum given a JS value", () => {
|
|
44
|
+
const members = {
|
|
45
|
+
foo: 1,
|
|
46
|
+
bar: 2,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
expect(
|
|
50
|
+
<Output>
|
|
51
|
+
<ts.SourceFile path="foo.ts">
|
|
52
|
+
<ts.EnumDeclaration name="MyEnum" jsValue={members} />
|
|
53
|
+
</ts.SourceFile>
|
|
54
|
+
</Output>,
|
|
55
|
+
).toRenderTo(`
|
|
56
|
+
enum MyEnum {
|
|
57
|
+
foo = 1,
|
|
58
|
+
bar = 2
|
|
59
|
+
}
|
|
60
|
+
`);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("renders an enum given a JS value and children", () => {
|
|
64
|
+
const members = {
|
|
65
|
+
foo: 1,
|
|
66
|
+
bar: 2,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
expect(
|
|
70
|
+
<Output>
|
|
71
|
+
<ts.SourceFile path="foo.ts">
|
|
72
|
+
<ts.EnumDeclaration name="MyEnum" jsValue={members}>
|
|
73
|
+
custom = "hello"
|
|
74
|
+
</ts.EnumDeclaration>
|
|
75
|
+
</ts.SourceFile>
|
|
76
|
+
</Output>,
|
|
77
|
+
).toRenderTo(`
|
|
78
|
+
enum MyEnum {
|
|
79
|
+
foo = 1,
|
|
80
|
+
bar = 2,
|
|
81
|
+
custom = "hello"
|
|
82
|
+
}
|
|
83
|
+
`);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("uses the naming policy", () => {
|
|
87
|
+
const members = {
|
|
88
|
+
"foo-prop": 1,
|
|
89
|
+
"bar-prop": 2,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const policy = ts.createTSNamePolicy();
|
|
93
|
+
|
|
94
|
+
expect(
|
|
95
|
+
<Output namePolicy={policy}>
|
|
96
|
+
<ts.SourceFile path="foo.ts">
|
|
97
|
+
<ts.EnumDeclaration name="my-enum" jsValue={members} />
|
|
98
|
+
</ts.SourceFile>
|
|
99
|
+
</Output>,
|
|
100
|
+
).toRenderTo(`
|
|
101
|
+
enum MyEnum {
|
|
102
|
+
fooProp = 1,
|
|
103
|
+
barProp = 2
|
|
104
|
+
}
|
|
105
|
+
`);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("symbols", () => {
|
|
109
|
+
it("can reference enum members by refkey", () => {
|
|
110
|
+
const memberOne = refkey();
|
|
111
|
+
|
|
112
|
+
expect(
|
|
113
|
+
<Output>
|
|
114
|
+
<ts.SourceFile path="foo.ts">
|
|
115
|
+
<ts.EnumDeclaration name="MyEnum">
|
|
116
|
+
<ts.EnumMember name="foo" jsValue="1" refkey={memberOne} />,
|
|
117
|
+
<ts.EnumMember name="bar" jsValue={2} />
|
|
118
|
+
</ts.EnumDeclaration>
|
|
119
|
+
|
|
120
|
+
{memberOne};
|
|
121
|
+
</ts.SourceFile>
|
|
122
|
+
</Output>,
|
|
123
|
+
).toRenderTo(`
|
|
124
|
+
enum MyEnum {
|
|
125
|
+
foo = "1",
|
|
126
|
+
bar = 2
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
MyEnum.foo;
|
|
130
|
+
`);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Output, render } from "@alloy-js/core";
|
|
2
|
+
import { it } from "vitest";
|
|
3
|
+
import { fs } from "../src/builtins/node.js";
|
|
4
|
+
import {
|
|
5
|
+
createPackage,
|
|
6
|
+
FunctionDeclaration,
|
|
7
|
+
PackageDirectory,
|
|
8
|
+
Reference,
|
|
9
|
+
SourceFile,
|
|
10
|
+
} from "../src/index.js";
|
|
11
|
+
import { assertFileContents } from "./utils.js";
|
|
12
|
+
|
|
13
|
+
it("can import builtins", () => {
|
|
14
|
+
const testLib = createPackage({
|
|
15
|
+
name: "testLib",
|
|
16
|
+
version: "1.0.0",
|
|
17
|
+
descriptor: {
|
|
18
|
+
".": {
|
|
19
|
+
default: "defaultExport",
|
|
20
|
+
named: ["foo", "bar"],
|
|
21
|
+
},
|
|
22
|
+
"./subpath": {
|
|
23
|
+
named: ["nice", "cool"],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const res = render(
|
|
29
|
+
<Output externals={[testLib, fs]}>
|
|
30
|
+
<PackageDirectory path="." name="test" version="1.0.0">
|
|
31
|
+
<SourceFile path="index.ts">
|
|
32
|
+
<Reference refkey={testLib["./subpath"].nice} />;
|
|
33
|
+
await <Reference refkey={fs["./promises"].readFile} />();
|
|
34
|
+
</SourceFile>
|
|
35
|
+
</PackageDirectory>
|
|
36
|
+
</Output>,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
assertFileContents(res, {
|
|
40
|
+
"package.json": `
|
|
41
|
+
{
|
|
42
|
+
"name": "test",
|
|
43
|
+
"version": "1.0.0",
|
|
44
|
+
"type": "module",
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"testLib": "1.0.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"typescript": "^5.5.2"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`,
|
|
53
|
+
"index.ts": `
|
|
54
|
+
import { nice } from "testLib/subpath";
|
|
55
|
+
import { readFile } from "node:fs/promises";
|
|
56
|
+
|
|
57
|
+
nice;
|
|
58
|
+
await readFile();
|
|
59
|
+
`,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("can import builtins without a package", () => {
|
|
64
|
+
const testLib = createPackage({
|
|
65
|
+
name: "testLib",
|
|
66
|
+
version: "1.0.0",
|
|
67
|
+
descriptor: {
|
|
68
|
+
".": {
|
|
69
|
+
default: "defaultExport",
|
|
70
|
+
named: ["foo", "bar"],
|
|
71
|
+
},
|
|
72
|
+
"./subpath": {
|
|
73
|
+
named: ["nice", "cool"],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const res = render(
|
|
79
|
+
<Output externals={[testLib, fs]}>
|
|
80
|
+
<SourceFile path="index.ts">
|
|
81
|
+
<Reference refkey={testLib["./subpath"].nice} />;
|
|
82
|
+
await <Reference refkey={fs["./promises"].readFile} />();
|
|
83
|
+
</SourceFile>
|
|
84
|
+
</Output>,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
assertFileContents(res, {
|
|
88
|
+
"index.ts": `
|
|
89
|
+
import { nice } from "testLib/subpath";
|
|
90
|
+
import { readFile } from "node:fs/promises";
|
|
91
|
+
|
|
92
|
+
nice;
|
|
93
|
+
await readFile();
|
|
94
|
+
`,
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("can import builtins without a package", () => {
|
|
99
|
+
const testLib = createPackage({
|
|
100
|
+
name: "testLib",
|
|
101
|
+
version: "1.0.0",
|
|
102
|
+
descriptor: {
|
|
103
|
+
".": {
|
|
104
|
+
default: "defaultExport",
|
|
105
|
+
named: ["foo", "bar"],
|
|
106
|
+
},
|
|
107
|
+
"./subpath": {
|
|
108
|
+
named: ["nice", "cool"],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const res = render(
|
|
114
|
+
<Output externals={[testLib, fs]}>
|
|
115
|
+
<SourceFile path="index.ts">
|
|
116
|
+
<FunctionDeclaration name="foo">
|
|
117
|
+
<FunctionDeclaration name="bar">
|
|
118
|
+
<Reference refkey={testLib["./subpath"].nice} />;
|
|
119
|
+
await <Reference refkey={fs["./promises"].readFile} />();
|
|
120
|
+
</FunctionDeclaration>
|
|
121
|
+
</FunctionDeclaration>
|
|
122
|
+
</SourceFile>
|
|
123
|
+
</Output>,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
assertFileContents(res, {
|
|
127
|
+
"index.ts": `
|
|
128
|
+
import { nice } from "testLib/subpath";
|
|
129
|
+
import { readFile } from "node:fs/promises";
|
|
130
|
+
|
|
131
|
+
function foo() {
|
|
132
|
+
function bar() {
|
|
133
|
+
nice;
|
|
134
|
+
await readFile();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
`,
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Output, refkey, render } from "@alloy-js/core";
|
|
2
|
+
import { it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
FunctionCallExpression,
|
|
5
|
+
FunctionDeclaration,
|
|
6
|
+
PackageDirectory,
|
|
7
|
+
SourceFile,
|
|
8
|
+
VarDeclaration,
|
|
9
|
+
} from "../../typescript/src/index.js";
|
|
10
|
+
import { assertFileContents } from "./utils.js";
|
|
11
|
+
|
|
12
|
+
it("can declare and call a function with parameters", () => {
|
|
13
|
+
const functionRefkey = refkey();
|
|
14
|
+
const res = render(
|
|
15
|
+
<Output>
|
|
16
|
+
<PackageDirectory path="." name="test" version="1.0.0">
|
|
17
|
+
<SourceFile path="index.ts">
|
|
18
|
+
<VarDeclaration name="foo" value={`"Foo"`} const />
|
|
19
|
+
<FunctionDeclaration refkey={functionRefkey} name="bar" parameters={{"foo?": "string", "baz?": "number"}} >
|
|
20
|
+
const message = foo ? foo : "Hello, World!";
|
|
21
|
+
console.log(message);
|
|
22
|
+
if(baz) console.log(baz)
|
|
23
|
+
</FunctionDeclaration>
|
|
24
|
+
<FunctionCallExpression refkey={functionRefkey} args={[`"Hello!"`]} />;
|
|
25
|
+
<FunctionCallExpression refkey={functionRefkey} />;
|
|
26
|
+
<FunctionCallExpression refkey={functionRefkey} args={[<>"Hello {<>World</>}!"</>]} />;
|
|
27
|
+
<FunctionCallExpression refkey={functionRefkey} args={[<>"Hey there!"</>]} />;
|
|
28
|
+
<FunctionCallExpression refkey={functionRefkey} args={[<>"Hello World"</>, <>12345</>]} />;
|
|
29
|
+
</SourceFile>
|
|
30
|
+
</PackageDirectory>
|
|
31
|
+
</Output>,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
assertFileContents(res, {
|
|
35
|
+
"index.ts": `
|
|
36
|
+
const foo = "Foo";
|
|
37
|
+
function bar(foo?: string, baz?: number) {
|
|
38
|
+
const message = foo ? foo : "Hello, World!";
|
|
39
|
+
console.log(message);
|
|
40
|
+
if(baz) console.log(baz)
|
|
41
|
+
}
|
|
42
|
+
bar("Hello!");
|
|
43
|
+
bar();
|
|
44
|
+
bar("Hello World!");
|
|
45
|
+
bar("Hey there!");
|
|
46
|
+
bar("Hello World", 12345);
|
|
47
|
+
`,
|
|
48
|
+
});
|
|
49
|
+
});
|