@alloy-js/typescript 0.20.0-dev.0 → 0.20.0-dev.2
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/builtins/index.js +2 -1
- package/dist/src/builtins/index.js.map +1 -0
- package/dist/src/builtins/node.d.ts +1 -1
- package/dist/src/builtins/node.js +2 -1
- package/dist/src/builtins/node.js.map +1 -0
- package/dist/src/components/ArrayExpression.js +2 -1
- package/dist/src/components/ArrayExpression.js.map +1 -0
- package/dist/src/components/ArrowFunction.d.ts.map +1 -1
- package/dist/src/components/ArrowFunction.js +9 -14
- package/dist/src/components/ArrowFunction.js.map +1 -0
- package/dist/src/components/BarrelFile.js +2 -1
- package/dist/src/components/BarrelFile.js.map +1 -0
- package/dist/src/components/BlockScope.d.ts.map +1 -1
- package/dist/src/components/BlockScope.js +5 -3
- package/dist/src/components/BlockScope.js.map +1 -0
- package/dist/src/components/CallSignature.js +2 -1
- package/dist/src/components/CallSignature.js.map +1 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +22 -31
- package/dist/src/components/ClassDeclaration.js.map +1 -0
- package/dist/src/components/CommaList.js +2 -1
- package/dist/src/components/CommaList.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +2 -9
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +22 -44
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +7 -10
- package/dist/src/components/EnumDeclaration.js.map +1 -0
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js +5 -5
- package/dist/src/components/EnumMember.js.map +1 -0
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/ExportStatement.js +4 -2
- package/dist/src/components/ExportStatement.js.map +1 -0
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js +17 -13
- package/dist/src/components/FunctionBase.js.map +1 -0
- package/dist/src/components/FunctionCallExpression.js +2 -1
- package/dist/src/components/FunctionCallExpression.js.map +1 -0
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +5 -4
- package/dist/src/components/FunctionDeclaration.js.map +1 -0
- package/dist/src/components/FunctionExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionExpression.js +9 -14
- package/dist/src/components/FunctionExpression.js.map +1 -0
- package/dist/src/components/FunctionType.d.ts.map +1 -1
- package/dist/src/components/FunctionType.js +5 -4
- package/dist/src/components/FunctionType.js.map +1 -0
- package/dist/src/components/IfStatement.d.ts.map +1 -1
- package/dist/src/components/IfStatement.js +4 -2
- package/dist/src/components/IfStatement.js.map +1 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +5 -5
- package/dist/src/components/ImportStatement.js.map +1 -0
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +16 -14
- package/dist/src/components/Interface.js.map +1 -0
- package/dist/src/components/InterfaceMethod.d.ts.map +1 -1
- package/dist/src/components/InterfaceMethod.js +6 -4
- package/dist/src/components/InterfaceMethod.js.map +1 -0
- package/dist/src/components/JSDoc.js +2 -1
- package/dist/src/components/JSDoc.js.map +1 -0
- package/dist/src/components/JSDocComment.js +2 -1
- package/dist/src/components/JSDocComment.js.map +1 -0
- package/dist/src/components/JSDocExample.js +2 -1
- package/dist/src/components/JSDocExample.js.map +1 -0
- package/dist/src/components/JSDocParam.js +2 -1
- package/dist/src/components/JSDocParam.js.map +1 -0
- package/dist/src/components/LexicalScope.d.ts +12 -0
- package/dist/src/components/LexicalScope.d.ts.map +1 -0
- package/dist/src/components/LexicalScope.js +25 -0
- package/dist/src/components/LexicalScope.js.map +1 -0
- package/dist/src/components/MemberDeclaration.d.ts +1 -10
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js +5 -8
- package/dist/src/components/MemberDeclaration.js.map +1 -0
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +15 -6
- package/dist/src/components/MemberExpression.js.map +1 -0
- package/dist/src/components/MemberScope.d.ts +15 -0
- package/dist/src/components/MemberScope.d.ts.map +1 -0
- package/dist/src/components/MemberScope.js +18 -0
- package/dist/src/components/MemberScope.js.map +1 -0
- package/dist/src/components/NewExpression.d.ts.map +1 -1
- package/dist/src/components/NewExpression.js +7 -6
- package/dist/src/components/NewExpression.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +12 -15
- package/dist/src/components/ObjectExpression.js.map +1 -0
- package/dist/src/components/PackageDirectory.js +2 -1
- package/dist/src/components/PackageDirectory.js.map +1 -0
- package/dist/src/components/PackageJson.js +2 -1
- package/dist/src/components/PackageJson.js.map +1 -0
- package/dist/src/components/PropertyName.js +3 -3
- package/dist/src/components/PropertyName.js.map +1 -0
- package/dist/src/components/Reference.js +2 -1
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SingleLineCommentBlock.js +2 -1
- package/dist/src/components/SingleLineCommentBlock.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +5 -3
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/SwitchStatement.js +2 -1
- package/dist/src/components/SwitchStatement.js.map +1 -0
- package/dist/src/components/TsConfigJson.js +2 -1
- package/dist/src/components/TsConfigJson.js.map +1 -0
- package/dist/src/components/TypeDeclaration.js +2 -1
- package/dist/src/components/TypeDeclaration.js.map +1 -0
- package/dist/src/components/TypeRefContext.js +2 -1
- package/dist/src/components/TypeRefContext.js.map +1 -0
- package/dist/src/components/ValueExpression.js +2 -1
- package/dist/src/components/ValueExpression.js.map +1 -0
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +16 -27
- package/dist/src/components/VarDeclaration.js.map +1 -0
- package/dist/src/components/index.js +2 -1
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/interface/expression.test.js +2 -1
- package/dist/src/components/interface/expression.test.js.map +1 -0
- package/dist/src/components/stc/index.js +2 -1
- package/dist/src/components/stc/index.js.map +1 -0
- package/dist/src/context/index.d.ts +1 -1
- package/dist/src/context/index.d.ts.map +1 -1
- package/dist/src/context/index.js +2 -1
- package/dist/src/context/index.js.map +1 -0
- package/dist/src/context/type-ref-context.js +2 -1
- package/dist/src/context/type-ref-context.js.map +1 -0
- package/dist/src/create-package.d.ts.map +1 -1
- package/dist/src/create-package.js +13 -34
- package/dist/src/create-package.js.map +1 -0
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -0
- package/dist/src/name-conflict-resolver.js +2 -1
- package/dist/src/name-conflict-resolver.js.map +1 -0
- package/dist/src/name-policy.js +2 -1
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/parameter-descriptor.js +2 -1
- package/dist/src/parameter-descriptor.js.map +1 -0
- package/dist/src/source-directory-data.js +2 -1
- package/dist/src/source-directory-data.js.map +1 -0
- package/dist/src/symbols/index.d.ts +19 -0
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +73 -1
- package/dist/src/symbols/index.js.map +1 -0
- package/dist/src/symbols/reference.d.ts +2 -2
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +69 -70
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/src/symbols/scopes.d.ts +5 -8
- package/dist/src/symbols/scopes.d.ts.map +1 -1
- package/dist/src/symbols/scopes.js +28 -1
- package/dist/src/symbols/scopes.js.map +1 -0
- package/dist/src/symbols/ts-lexical-scope.d.ts +12 -0
- package/dist/src/symbols/ts-lexical-scope.d.ts.map +1 -0
- package/dist/src/symbols/ts-lexical-scope.js +17 -0
- package/dist/src/symbols/ts-lexical-scope.js.map +1 -0
- package/dist/src/symbols/ts-member-scope.d.ts +12 -4
- package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-member-scope.js +17 -7
- package/dist/src/symbols/ts-member-scope.js.map +1 -0
- package/dist/src/symbols/ts-module-scope.d.ts +8 -3
- package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-module-scope.js +31 -19
- package/dist/src/symbols/ts-module-scope.js.map +1 -0
- package/dist/src/symbols/ts-output-symbol.d.ts +19 -18
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +62 -38
- package/dist/src/symbols/ts-output-symbol.js.map +1 -0
- package/dist/src/symbols/ts-package-scope.d.ts +1 -1
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +6 -6
- package/dist/src/symbols/ts-package-scope.js.map +1 -0
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +25 -2
- package/dist/src/utils.js.map +1 -0
- package/dist/test/array.test.js +2 -1
- package/dist/test/array.test.js.map +1 -0
- package/dist/test/arrow-function.test.js +2 -1
- package/dist/test/arrow-function.test.js.map +1 -0
- package/dist/test/barrel.test.js +26 -17
- package/dist/test/barrel.test.js.map +1 -0
- package/dist/test/basic.test.js +22 -26
- package/dist/test/basic.test.js.map +1 -0
- package/dist/test/block-scope.test.js +2 -1
- package/dist/test/block-scope.test.js.map +1 -0
- package/dist/test/class.test.js +24 -18
- package/dist/test/class.test.js.map +1 -0
- package/dist/test/enum-jsdoc.test.js +2 -1
- package/dist/test/enum-jsdoc.test.js.map +1 -0
- package/dist/test/enum.test.js +2 -1
- package/dist/test/enum.test.js.map +1 -0
- package/dist/test/externals.test.js +12 -51
- package/dist/test/externals.test.js.map +1 -0
- package/dist/test/function-call-expression.test.js +9 -8
- package/dist/test/function-call-expression.test.js.map +1 -0
- package/dist/test/function-declaration-jsdoc.test.js +2 -1
- package/dist/test/function-declaration-jsdoc.test.js.map +1 -0
- package/dist/test/function-declaration.test.js +2 -1
- package/dist/test/function-declaration.test.js.map +1 -0
- package/dist/test/function-expression.test.js +2 -1
- package/dist/test/function-expression.test.js.map +1 -0
- package/dist/test/function-type.test.js +2 -1
- package/dist/test/function-type.test.js.map +1 -0
- package/dist/test/if-statement.test.js +2 -1
- package/dist/test/if-statement.test.js.map +1 -0
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/imports.test.js +62 -60
- package/dist/test/imports.test.js.map +1 -0
- package/dist/test/interface-jsdoc.test.js +2 -1
- package/dist/test/interface-jsdoc.test.js.map +1 -0
- package/dist/test/interface.test.js +2 -1
- package/dist/test/interface.test.js.map +1 -0
- package/dist/test/jscomment.test.js +2 -1
- package/dist/test/jscomment.test.js.map +1 -0
- package/dist/test/jsdoc.test.js +2 -1
- package/dist/test/jsdoc.test.js.map +1 -0
- package/dist/test/jsdocparam.test.js +2 -1
- package/dist/test/jsdocparam.test.js.map +1 -0
- package/dist/test/member-expression.test.js +8 -7
- package/dist/test/member-expression.test.js.map +1 -0
- package/dist/test/name-conflict.test.js +5 -7
- package/dist/test/name-conflict.test.js.map +1 -0
- package/dist/test/name-policy.test.js +9 -13
- package/dist/test/name-policy.test.js.map +1 -0
- package/dist/test/new-expression.test.js +6 -7
- package/dist/test/new-expression.test.js.map +1 -0
- package/dist/test/object.test.js +2 -1
- package/dist/test/object.test.js.map +1 -0
- package/dist/test/package-external.test.js +71 -66
- package/dist/test/package-external.test.js.map +1 -0
- package/dist/test/package-json.test.js +8 -10
- package/dist/test/package-json.test.js.map +1 -0
- package/dist/test/package.test.js +12 -12
- package/dist/test/package.test.js.map +1 -0
- package/dist/test/reference.test.js +10 -12
- package/dist/test/reference.test.js.map +1 -0
- package/dist/test/source-file.test.js +7 -10
- package/dist/test/source-file.test.js.map +1 -0
- package/dist/test/switch-statement.test.js +2 -1
- package/dist/test/switch-statement.test.js.map +1 -0
- package/dist/test/utils.js +6 -2
- package/dist/test/utils.js.map +1 -0
- package/dist/test/value-expression.test.js +2 -1
- package/dist/test/value-expression.test.js.map +1 -0
- package/dist/test/values.test.d.ts.map +1 -1
- package/dist/test/values.test.js +11 -8
- package/dist/test/values.test.js.map +1 -0
- package/dist/test/var-declaration-jsdoc.test.js +2 -1
- package/dist/test/var-declaration-jsdoc.test.js.map +1 -0
- package/dist/test/var-declaration.test.d.ts.map +1 -1
- package/dist/test/var-declaration.test.js +21 -12
- package/dist/test/var-declaration.test.js.map +1 -0
- package/dist/test/vitest.setup.js +2 -1
- package/dist/test/vitest.setup.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/ArrowFunction.tsx +7 -10
- package/src/components/BlockScope.tsx +3 -3
- package/src/components/ClassDeclaration.tsx +19 -44
- package/src/components/Declaration.tsx +22 -53
- package/src/components/EnumDeclaration.tsx +4 -11
- package/src/components/EnumMember.tsx +3 -3
- package/src/components/ExportStatement.tsx +2 -1
- package/src/components/FunctionBase.tsx +33 -28
- package/src/components/FunctionDeclaration.tsx +3 -3
- package/src/components/FunctionExpression.tsx +7 -10
- package/src/components/FunctionType.tsx +3 -3
- package/src/components/IfStatement.tsx +2 -1
- package/src/components/ImportStatement.tsx +4 -8
- package/src/components/Interface.tsx +15 -22
- package/src/components/InterfaceMethod.tsx +4 -4
- package/src/components/LexicalScope.tsx +27 -0
- package/src/components/MemberDeclaration.tsx +8 -20
- package/src/components/MemberExpression.tsx +25 -5
- package/src/components/MemberScope.tsx +29 -0
- package/src/components/NewExpression.tsx +4 -5
- package/src/components/ObjectExpression.tsx +11 -18
- package/src/components/PropertyName.tsx +2 -2
- package/src/components/SourceFile.tsx +3 -1
- package/src/components/VarDeclaration.tsx +14 -28
- package/src/context/index.ts +1 -1
- package/src/create-package.ts +10 -39
- package/src/symbols/index.ts +118 -0
- package/src/symbols/reference.tsx +163 -0
- package/src/symbols/scopes.ts +38 -13
- package/src/symbols/ts-lexical-scope.ts +18 -0
- package/src/symbols/ts-member-scope.ts +23 -6
- package/src/symbols/ts-module-scope.ts +31 -21
- package/src/symbols/ts-output-symbol.ts +111 -49
- package/src/symbols/ts-package-scope.ts +5 -5
- package/src/utils.ts +38 -1
- package/temp/api.json +1641 -713
- package/test/barrel.test.tsx +24 -18
- package/test/basic.test.tsx +20 -29
- package/test/class.test.tsx +28 -18
- package/test/externals.test.tsx +10 -57
- package/test/function-call-expression.test.tsx +6 -7
- package/test/imports.test.tsx +57 -74
- package/test/member-expression.test.tsx +5 -13
- package/test/name-conflict.test.tsx +4 -7
- package/test/name-policy.test.tsx +7 -15
- package/test/new-expression.test.tsx +4 -7
- package/test/package-external.test.tsx +69 -73
- package/test/package-json.test.tsx +6 -11
- package/test/package.test.tsx +8 -11
- package/test/reference.test.tsx +10 -15
- package/test/source-file.test.tsx +5 -11
- package/test/utils.tsx +1 -1
- package/test/values.test.tsx +8 -8
- package/test/var-declaration.test.tsx +19 -20
- package/tsdoc-metadata.json +1 -1
- package/dist/src/context/private-scope.d.ts +0 -18
- package/dist/src/context/private-scope.d.ts.map +0 -1
- package/dist/src/context/private-scope.js +0 -8
- package/src/context/private-scope.ts +0 -23
- package/src/symbols/reference.ts +0 -197
package/test/barrel.test.tsx
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Output,
|
|
1
|
+
import { Output, SourceDirectory, SourceFile } from "@alloy-js/core";
|
|
2
2
|
import "@alloy-js/core/testing";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { expect, it } from "vitest";
|
|
5
5
|
import * as ts from "../src/components/index.js";
|
|
6
|
-
import { findFile } from "./utils.jsx";
|
|
7
6
|
|
|
8
7
|
it("exports everything from source files within it", () => {
|
|
9
|
-
|
|
8
|
+
expect(
|
|
10
9
|
<Output>
|
|
11
10
|
<ts.SourceFile path="test1.ts" />
|
|
12
11
|
<ts.SourceFile path="test2.ts" />
|
|
@@ -17,31 +16,38 @@ it("exports everything from source files within it", () => {
|
|
|
17
16
|
</SourceDirectory>
|
|
18
17
|
<ts.BarrelFile />
|
|
19
18
|
</Output>,
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
expect(findFile(res, "index.ts").contents).toBe(d`
|
|
19
|
+
).toRenderTo({
|
|
20
|
+
"components/index.ts": d`
|
|
21
|
+
export * from "./c1.js";
|
|
22
|
+
export * from "./c2.js";
|
|
23
|
+
`,
|
|
24
|
+
"index.ts": d`
|
|
27
25
|
export * from "./test1.js";
|
|
28
26
|
export * from "./test2.js";
|
|
29
27
|
export * from "./components/index.js";
|
|
30
|
-
|
|
28
|
+
`,
|
|
29
|
+
"components/c2.ts": "",
|
|
30
|
+
"components/c1.ts": "",
|
|
31
|
+
"test1.ts": "",
|
|
32
|
+
"test2.ts": "",
|
|
33
|
+
});
|
|
31
34
|
});
|
|
32
35
|
|
|
33
36
|
it("ignores non-TS files", () => {
|
|
34
|
-
|
|
37
|
+
expect(
|
|
35
38
|
<Output>
|
|
36
39
|
<SourceFile path="test.txt" filetype="text" />
|
|
37
40
|
<ts.SourceFile path="test1.ts" />
|
|
38
41
|
<ts.SourceFile path="test2.ts" />
|
|
39
42
|
<ts.BarrelFile />
|
|
40
43
|
</Output>,
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
).toRenderTo({
|
|
45
|
+
"index.ts": d`
|
|
46
|
+
export * from "./test1.js";
|
|
47
|
+
export * from "./test2.js";
|
|
48
|
+
`,
|
|
49
|
+
"test.txt": "",
|
|
50
|
+
"test1.ts": "",
|
|
51
|
+
"test2.ts": "",
|
|
52
|
+
});
|
|
47
53
|
});
|
package/test/basic.test.tsx
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { List, Output, refkey,
|
|
1
|
+
import { List, Output, refkey, SourceFile } from "@alloy-js/core";
|
|
2
2
|
import "@alloy-js/core/testing";
|
|
3
|
-
import { d } from "@alloy-js/core/testing";
|
|
4
3
|
import { expect, it } from "vitest";
|
|
5
4
|
import * as ts from "../src/components/index.js";
|
|
6
5
|
import { Reference } from "../src/components/Reference.js";
|
|
7
|
-
import { findFile } from "./utils.js";
|
|
8
6
|
|
|
9
7
|
it("works", () => {
|
|
10
8
|
const fnSpec = {
|
|
@@ -15,7 +13,7 @@ it("works", () => {
|
|
|
15
13
|
const greetKey = refkey(fnSpec, "greet");
|
|
16
14
|
const farewellKey = refkey(fnSpec, "farewell");
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
expect(
|
|
19
17
|
<Output>
|
|
20
18
|
<SourceFile path="readme.md" filetype="markdown">
|
|
21
19
|
This is a sample output project.
|
|
@@ -55,29 +53,22 @@ it("works", () => {
|
|
|
55
53
|
</List>
|
|
56
54
|
</ts.SourceFile>
|
|
57
55
|
</Output>,
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
expect(findFile(res, "test2.ts").contents).toEqual(d`
|
|
78
|
-
import { sayGoodbye, sayHello } from "./test1.js";
|
|
79
|
-
|
|
80
|
-
console.log(sayHello("world"));
|
|
81
|
-
console.log(sayGoodbye("world"));
|
|
82
|
-
`);
|
|
56
|
+
).toRenderTo({
|
|
57
|
+
"readme.md": `This is a sample output project.`,
|
|
58
|
+
"index.ts": `console.log("Hello world!");`,
|
|
59
|
+
"test1.ts": `
|
|
60
|
+
function sayHello(str: string) {
|
|
61
|
+
return "Hello " + str;
|
|
62
|
+
}
|
|
63
|
+
function sayGoodbye(str: string) {
|
|
64
|
+
return "Goodbye " + str;
|
|
65
|
+
}
|
|
66
|
+
`,
|
|
67
|
+
"test2.ts": `
|
|
68
|
+
import { sayGoodbye, sayHello } from "./test1.js";
|
|
69
|
+
|
|
70
|
+
console.log(sayHello("world"));
|
|
71
|
+
console.log(sayGoodbye("world"));
|
|
72
|
+
`,
|
|
73
|
+
});
|
|
83
74
|
});
|
package/test/class.test.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { List, Output, refkey,
|
|
1
|
+
import { List, Output, refkey, StatementList } from "@alloy-js/core";
|
|
2
2
|
import "@alloy-js/core/testing";
|
|
3
3
|
import { d } from "@alloy-js/core/testing";
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
5
|
import * as ts from "../src/components/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { toSourceText } from "./utils.js";
|
|
7
7
|
|
|
8
8
|
it("declares classes", () => {
|
|
9
9
|
const res = toSourceText(<ts.ClassDeclaration name="Foo" />);
|
|
@@ -102,7 +102,9 @@ describe("instance members", () => {
|
|
|
102
102
|
{one}
|
|
103
103
|
</>,
|
|
104
104
|
);
|
|
105
|
-
}).toThrow(
|
|
105
|
+
}).toThrow(
|
|
106
|
+
/Cannot reference instance member 'one' without an instance of 'Foo'/,
|
|
107
|
+
);
|
|
106
108
|
});
|
|
107
109
|
|
|
108
110
|
it("cannot be referenced outside the class when protected", () => {
|
|
@@ -120,7 +122,9 @@ describe("instance members", () => {
|
|
|
120
122
|
{one}
|
|
121
123
|
</>,
|
|
122
124
|
);
|
|
123
|
-
}).toThrow(
|
|
125
|
+
}).toThrow(
|
|
126
|
+
/Cannot reference instance member 'one' without an instance of 'Foo'/,
|
|
127
|
+
);
|
|
124
128
|
});
|
|
125
129
|
|
|
126
130
|
it("cannot be referenced outside the class when private", () => {
|
|
@@ -138,7 +142,9 @@ describe("instance members", () => {
|
|
|
138
142
|
{one}
|
|
139
143
|
</>,
|
|
140
144
|
);
|
|
141
|
-
}).toThrow(
|
|
145
|
+
}).toThrow(
|
|
146
|
+
/Cannot reference instance member 'one' without an instance of 'Foo'/,
|
|
147
|
+
);
|
|
142
148
|
});
|
|
143
149
|
|
|
144
150
|
it("works with invalid identifier names", () => {
|
|
@@ -194,7 +200,7 @@ describe("instance members", () => {
|
|
|
194
200
|
it("doesn't conflict with imports from other files", () => {
|
|
195
201
|
const rk1 = refkey();
|
|
196
202
|
const rk2 = refkey();
|
|
197
|
-
|
|
203
|
+
expect(
|
|
198
204
|
<Output
|
|
199
205
|
nameConflictResolver={() => {
|
|
200
206
|
// do nothing
|
|
@@ -220,18 +226,22 @@ describe("instance members", () => {
|
|
|
220
226
|
</ts.ClassDeclaration>
|
|
221
227
|
</ts.SourceFile>
|
|
222
228
|
</Output>,
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
229
|
+
).toRenderTo({
|
|
230
|
+
"decl.ts": `
|
|
231
|
+
export const one = 1;
|
|
232
|
+
export const two = 2;
|
|
233
|
+
`,
|
|
234
|
+
"ref.ts": `
|
|
235
|
+
import { one, two } from "./decl.js";
|
|
227
236
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
237
|
+
class Foo {
|
|
238
|
+
one = one;
|
|
239
|
+
two() {
|
|
240
|
+
two
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
`,
|
|
244
|
+
});
|
|
235
245
|
});
|
|
236
246
|
});
|
|
237
247
|
|
|
@@ -310,7 +320,7 @@ describe("static members", () => {
|
|
|
310
320
|
{two};
|
|
311
321
|
</>,
|
|
312
322
|
),
|
|
313
|
-
).toThrow(/Cannot
|
|
323
|
+
).toThrow(/Cannot reference/);
|
|
314
324
|
});
|
|
315
325
|
});
|
|
316
326
|
|
package/test/externals.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Output
|
|
1
|
+
import { Output } from "@alloy-js/core";
|
|
2
2
|
import { expect, it } from "vitest";
|
|
3
3
|
import { fs } from "../src/builtins/node.js";
|
|
4
4
|
import {
|
|
@@ -6,9 +6,7 @@ import {
|
|
|
6
6
|
FunctionDeclaration,
|
|
7
7
|
PackageDirectory,
|
|
8
8
|
SourceFile,
|
|
9
|
-
TSOutputSymbol,
|
|
10
9
|
} from "../src/index.js";
|
|
11
|
-
import { assertFileContents } from "./utils.js";
|
|
12
10
|
|
|
13
11
|
it("can import builtins", () => {
|
|
14
12
|
const testLib = createPackage({
|
|
@@ -25,7 +23,7 @@ it("can import builtins", () => {
|
|
|
25
23
|
},
|
|
26
24
|
});
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
expect(
|
|
29
27
|
<Output externals={[testLib, fs]}>
|
|
30
28
|
<PackageDirectory path="." name="test" version="1.0.0">
|
|
31
29
|
<SourceFile path="index.ts">
|
|
@@ -34,9 +32,7 @@ it("can import builtins", () => {
|
|
|
34
32
|
</SourceFile>
|
|
35
33
|
</PackageDirectory>
|
|
36
34
|
</Output>,
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
assertFileContents(res, {
|
|
35
|
+
).toRenderTo({
|
|
40
36
|
"package.json": `
|
|
41
37
|
{
|
|
42
38
|
"name": "test",
|
|
@@ -50,6 +46,7 @@ it("can import builtins", () => {
|
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
48
|
`,
|
|
49
|
+
"tsconfig.json": expect.anything(),
|
|
53
50
|
"index.ts": `
|
|
54
51
|
import { readFile } from "node:fs/promises";
|
|
55
52
|
import { nice } from "testLib/subpath";
|
|
@@ -75,16 +72,14 @@ it("can import builtins without a package", () => {
|
|
|
75
72
|
},
|
|
76
73
|
});
|
|
77
74
|
|
|
78
|
-
|
|
75
|
+
expect(
|
|
79
76
|
<Output externals={[testLib, fs]}>
|
|
80
77
|
<SourceFile path="index.ts">
|
|
81
78
|
{testLib["./subpath"].nice};<hbr />
|
|
82
79
|
await {fs["./promises"].readFile}();
|
|
83
80
|
</SourceFile>
|
|
84
81
|
</Output>,
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
assertFileContents(res, {
|
|
82
|
+
).toRenderTo({
|
|
88
83
|
"index.ts": `
|
|
89
84
|
import { readFile } from "node:fs/promises";
|
|
90
85
|
import { nice } from "testLib/subpath";
|
|
@@ -110,7 +105,7 @@ it("can import builtins without a package", () => {
|
|
|
110
105
|
},
|
|
111
106
|
});
|
|
112
107
|
|
|
113
|
-
|
|
108
|
+
expect(
|
|
114
109
|
<Output externals={[testLib, fs]}>
|
|
115
110
|
<SourceFile path="index.ts">
|
|
116
111
|
<FunctionDeclaration name="foo">
|
|
@@ -121,9 +116,7 @@ it("can import builtins without a package", () => {
|
|
|
121
116
|
</FunctionDeclaration>
|
|
122
117
|
</SourceFile>
|
|
123
118
|
</Output>,
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
assertFileContents(res, {
|
|
119
|
+
).toRenderTo({
|
|
127
120
|
"index.ts": `
|
|
128
121
|
import { readFile } from "node:fs/promises";
|
|
129
122
|
import { nice } from "testLib/subpath";
|
|
@@ -160,7 +153,7 @@ it("can import static members", () => {
|
|
|
160
153
|
},
|
|
161
154
|
});
|
|
162
155
|
|
|
163
|
-
|
|
156
|
+
expect(
|
|
164
157
|
<Output externals={[mcpSdk]}>
|
|
165
158
|
<SourceFile path="index.ts">
|
|
166
159
|
<FunctionDeclaration name="foo">
|
|
@@ -180,9 +173,7 @@ it("can import static members", () => {
|
|
|
180
173
|
</FunctionDeclaration>
|
|
181
174
|
</SourceFile>
|
|
182
175
|
</Output>,
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
assertFileContents(res, {
|
|
176
|
+
).toRenderTo({
|
|
186
177
|
"index.ts": `
|
|
187
178
|
import { noMembers, server, simpleName } from "@modelcontextprotocol/sdk/server/index.js";
|
|
188
179
|
|
|
@@ -196,41 +187,3 @@ it("can import static members", () => {
|
|
|
196
187
|
`,
|
|
197
188
|
});
|
|
198
189
|
});
|
|
199
|
-
|
|
200
|
-
it("can import instance members", () => {
|
|
201
|
-
const mcpSdk = createPackage({
|
|
202
|
-
name: "@modelcontextprotocol/sdk",
|
|
203
|
-
version: "^3.23.0",
|
|
204
|
-
descriptor: {
|
|
205
|
-
"./server/index.js": {
|
|
206
|
-
named: [{ name: "Server", instanceMembers: ["instanceHandler"] }],
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
function RunTest() {
|
|
212
|
-
const sym = new TSOutputSymbol("foo");
|
|
213
|
-
const binder = sym.binder!;
|
|
214
|
-
|
|
215
|
-
expect(binder).toBeDefined();
|
|
216
|
-
|
|
217
|
-
const source = binder.getSymbolForRefkey(
|
|
218
|
-
mcpSdk["./server/index.js"].Server,
|
|
219
|
-
).value!;
|
|
220
|
-
expect(source).toBeDefined();
|
|
221
|
-
expect(source.instanceMemberScope?.symbols.size).toBe(1);
|
|
222
|
-
|
|
223
|
-
source.instantiateTo(sym);
|
|
224
|
-
|
|
225
|
-
expect(sym.staticMemberScope?.symbols.size).toBe(1);
|
|
226
|
-
expect([...sym.staticMemberScope!.symbols][0].name).toBe("instanceHandler");
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
render(
|
|
230
|
-
<Output externals={[mcpSdk]}>
|
|
231
|
-
<SourceFile path="index.ts">
|
|
232
|
-
<RunTest />
|
|
233
|
-
</SourceFile>
|
|
234
|
-
</Output>,
|
|
235
|
-
);
|
|
236
|
-
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Output, refkey,
|
|
2
|
-
import { it } from "vitest";
|
|
1
|
+
import { Output, refkey, StatementList } from "@alloy-js/core";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
3
|
import {
|
|
4
4
|
FunctionCallExpression,
|
|
5
5
|
FunctionDeclaration,
|
|
@@ -7,11 +7,10 @@ import {
|
|
|
7
7
|
SourceFile,
|
|
8
8
|
VarDeclaration,
|
|
9
9
|
} from "../../typescript/src/index.js";
|
|
10
|
-
import { assertFileContents } from "./utils.js";
|
|
11
10
|
|
|
12
11
|
it("can declare and call a function with parameters", () => {
|
|
13
12
|
const functionRefkey = refkey();
|
|
14
|
-
|
|
13
|
+
expect(
|
|
15
14
|
<Output>
|
|
16
15
|
<PackageDirectory path="." name="test" version="1.0.0">
|
|
17
16
|
<SourceFile path="index.ts">
|
|
@@ -53,9 +52,7 @@ it("can declare and call a function with parameters", () => {
|
|
|
53
52
|
</SourceFile>
|
|
54
53
|
</PackageDirectory>
|
|
55
54
|
</Output>,
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
assertFileContents(res, {
|
|
55
|
+
).toRenderTo({
|
|
59
56
|
"index.ts": `
|
|
60
57
|
const foo = "Foo";
|
|
61
58
|
function bar(foo?: string, baz?: number) {
|
|
@@ -69,5 +66,7 @@ it("can declare and call a function with parameters", () => {
|
|
|
69
66
|
bar("Hey there!");
|
|
70
67
|
bar("Hello World", 12345);
|
|
71
68
|
`,
|
|
69
|
+
"package.json": expect.anything(),
|
|
70
|
+
"tsconfig.json": expect.anything(),
|
|
72
71
|
});
|
|
73
72
|
});
|