@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/imports.test.tsx
CHANGED
|
@@ -4,19 +4,17 @@ import {
|
|
|
4
4
|
SourceDirectory,
|
|
5
5
|
StatementList,
|
|
6
6
|
refkey,
|
|
7
|
-
render,
|
|
8
7
|
} from "@alloy-js/core";
|
|
9
8
|
import "@alloy-js/core/testing";
|
|
10
|
-
import { describe, it } from "vitest";
|
|
9
|
+
import { describe, expect, it } from "vitest";
|
|
11
10
|
import * as ts from "../src/components/index.js";
|
|
12
11
|
import { Reference } from "../src/components/Reference.js";
|
|
13
12
|
import { TypeRefContext } from "../src/context/type-ref-context.js";
|
|
14
13
|
import { createPackage } from "../src/create-package.js";
|
|
15
14
|
import { tsNameConflictResolver } from "../src/name-conflict-resolver.js";
|
|
16
|
-
import { assertFileContents } from "./utils.js";
|
|
17
15
|
|
|
18
16
|
it("works with default imports", () => {
|
|
19
|
-
|
|
17
|
+
expect(
|
|
20
18
|
<Output>
|
|
21
19
|
<ts.SourceFile path="test1.ts">
|
|
22
20
|
<ts.FunctionDeclaration
|
|
@@ -31,9 +29,7 @@ it("works with default imports", () => {
|
|
|
31
29
|
const v = <Reference refkey={refkey("test")} />;
|
|
32
30
|
</ts.SourceFile>
|
|
33
31
|
</Output>,
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
assertFileContents(res, {
|
|
32
|
+
).toRenderTo({
|
|
37
33
|
"test1.ts": `
|
|
38
34
|
export default function asdf() {}
|
|
39
35
|
`,
|
|
@@ -46,7 +42,7 @@ it("works with default imports", () => {
|
|
|
46
42
|
});
|
|
47
43
|
|
|
48
44
|
it("works with named imports", () => {
|
|
49
|
-
|
|
45
|
+
expect(
|
|
50
46
|
<Output>
|
|
51
47
|
<ts.SourceFile path="test1.ts">
|
|
52
48
|
<ts.FunctionDeclaration export name="test" refkey={refkey("test")} />
|
|
@@ -56,9 +52,7 @@ it("works with named imports", () => {
|
|
|
56
52
|
const v = <Reference refkey={refkey("test")} />;
|
|
57
53
|
</ts.SourceFile>
|
|
58
54
|
</Output>,
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
assertFileContents(res, {
|
|
55
|
+
).toRenderTo({
|
|
62
56
|
"test1.ts": `
|
|
63
57
|
export function test() {}
|
|
64
58
|
`,
|
|
@@ -71,7 +65,7 @@ it("works with named imports", () => {
|
|
|
71
65
|
});
|
|
72
66
|
|
|
73
67
|
it("sort named imports", () => {
|
|
74
|
-
|
|
68
|
+
expect(
|
|
75
69
|
<Output>
|
|
76
70
|
<ts.SourceFile path="test1.ts">
|
|
77
71
|
<List>
|
|
@@ -95,20 +89,22 @@ it("sort named imports", () => {
|
|
|
95
89
|
</List>
|
|
96
90
|
</ts.SourceFile>
|
|
97
91
|
</Output>,
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
assertFileContents(res, {
|
|
92
|
+
).toRenderTo({
|
|
101
93
|
"test2.ts": `
|
|
102
94
|
import { a, B } from "./test1.js";
|
|
103
95
|
|
|
104
96
|
const b = B;
|
|
105
97
|
const a = a;
|
|
106
98
|
`,
|
|
99
|
+
"test1.ts": `
|
|
100
|
+
export class B {}
|
|
101
|
+
export function a() {}
|
|
102
|
+
`,
|
|
107
103
|
});
|
|
108
104
|
});
|
|
109
105
|
|
|
110
106
|
it("sort statements by import paths", () => {
|
|
111
|
-
|
|
107
|
+
expect(
|
|
112
108
|
<Output>
|
|
113
109
|
<ts.SourceFile path="a.ts">
|
|
114
110
|
<ts.ClassDeclaration export default name="A" refkey={refkey("A")} />
|
|
@@ -128,9 +124,7 @@ it("sort statements by import paths", () => {
|
|
|
128
124
|
</List>
|
|
129
125
|
</ts.SourceFile>
|
|
130
126
|
</Output>,
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
assertFileContents(res, {
|
|
127
|
+
).toRenderTo({
|
|
134
128
|
"test2.ts": `
|
|
135
129
|
import A from "./a.js";
|
|
136
130
|
import B from "./b.js";
|
|
@@ -138,11 +132,13 @@ it("sort statements by import paths", () => {
|
|
|
138
132
|
const b = B;
|
|
139
133
|
const a = A;
|
|
140
134
|
`,
|
|
135
|
+
"a.ts": "export default class A {}",
|
|
136
|
+
"b.ts": "export default class B {}",
|
|
141
137
|
});
|
|
142
138
|
});
|
|
143
139
|
|
|
144
140
|
it("works with default and named imports", () => {
|
|
145
|
-
|
|
141
|
+
expect(
|
|
146
142
|
<Output>
|
|
147
143
|
<ts.SourceFile path="test1.ts">
|
|
148
144
|
<ts.FunctionDeclaration
|
|
@@ -160,9 +156,7 @@ it("works with default and named imports", () => {
|
|
|
160
156
|
const v2 = <Reference refkey={refkey("test2")} />;
|
|
161
157
|
</ts.SourceFile>
|
|
162
158
|
</Output>,
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
assertFileContents(res, {
|
|
159
|
+
).toRenderTo({
|
|
166
160
|
"test1.ts": `
|
|
167
161
|
export default function test1() {}
|
|
168
162
|
export function test2() {}
|
|
@@ -177,7 +171,7 @@ it("works with default and named imports", () => {
|
|
|
177
171
|
});
|
|
178
172
|
|
|
179
173
|
it("works with default and named imports and name conflicts", () => {
|
|
180
|
-
|
|
174
|
+
expect(
|
|
181
175
|
<Output nameConflictResolver={tsNameConflictResolver}>
|
|
182
176
|
<ts.SourceFile path="test1.ts">
|
|
183
177
|
<ts.FunctionDeclaration
|
|
@@ -221,9 +215,7 @@ it("works with default and named imports and name conflicts", () => {
|
|
|
221
215
|
</StatementList>
|
|
222
216
|
</ts.SourceFile>
|
|
223
217
|
</Output>,
|
|
224
|
-
)
|
|
225
|
-
|
|
226
|
-
assertFileContents(res, {
|
|
218
|
+
).toRenderTo({
|
|
227
219
|
"test1.ts": `
|
|
228
220
|
export default function test1() {}
|
|
229
221
|
export function test2() {}
|
|
@@ -253,7 +245,7 @@ it("works with importing the same name many times from different files with the
|
|
|
253
245
|
const rk3 = refkey();
|
|
254
246
|
const rk3i = refkey();
|
|
255
247
|
|
|
256
|
-
|
|
248
|
+
expect(
|
|
257
249
|
<Output>
|
|
258
250
|
<ts.SourceFile path="test1.ts">
|
|
259
251
|
<ts.VarDeclaration export name="conflict" refkey={rk1}>
|
|
@@ -281,9 +273,7 @@ it("works with importing the same name many times from different files with the
|
|
|
281
273
|
</StatementList>
|
|
282
274
|
</ts.SourceFile>
|
|
283
275
|
</Output>,
|
|
284
|
-
)
|
|
285
|
-
|
|
286
|
-
assertFileContents(res, {
|
|
276
|
+
).toRenderTo({
|
|
287
277
|
"test-import.ts": `
|
|
288
278
|
import { conflict, type MyInterface } from "./test1.js";
|
|
289
279
|
import { conflict as conflict_2, type MyInterface as MyInterface_2 } from "./test2.js";
|
|
@@ -293,10 +283,13 @@ it("works with importing the same name many times from different files with the
|
|
|
293
283
|
const two: MyInterface_2 = conflict_2;
|
|
294
284
|
const three: MyInterface_3 = conflict_3;
|
|
295
285
|
`,
|
|
286
|
+
"test1.ts": `export const conflict = "hi"export interface MyInterface {}`,
|
|
287
|
+
"test2.ts": `const conflict = "hi"export interface MyInterface {}`,
|
|
288
|
+
"test3.ts": `const conflict = "hi"export interface MyInterface {}`,
|
|
296
289
|
});
|
|
297
290
|
});
|
|
298
291
|
it("works with default and named imports and name conflicts and references in nested scopes", () => {
|
|
299
|
-
|
|
292
|
+
expect(
|
|
300
293
|
<Output nameConflictResolver={tsNameConflictResolver}>
|
|
301
294
|
<ts.SourceFile path="test1.ts">
|
|
302
295
|
<ts.FunctionDeclaration
|
|
@@ -345,9 +338,7 @@ it("works with default and named imports and name conflicts and references in ne
|
|
|
345
338
|
</ts.FunctionDeclaration>
|
|
346
339
|
</ts.SourceFile>
|
|
347
340
|
</Output>,
|
|
348
|
-
)
|
|
349
|
-
|
|
350
|
-
assertFileContents(res, {
|
|
341
|
+
).toRenderTo({
|
|
351
342
|
"test1.ts": `
|
|
352
343
|
export default function test1() {}
|
|
353
344
|
export function test2() {}
|
|
@@ -372,7 +363,7 @@ it("works with default and named imports and name conflicts and references in ne
|
|
|
372
363
|
});
|
|
373
364
|
|
|
374
365
|
it("works with imports from different directories", () => {
|
|
375
|
-
|
|
366
|
+
expect(
|
|
376
367
|
<Output>
|
|
377
368
|
<SourceDirectory path="src">
|
|
378
369
|
<ts.SourceFile path="test1.ts">
|
|
@@ -387,9 +378,7 @@ it("works with imports from different directories", () => {
|
|
|
387
378
|
<ts.FunctionDeclaration export name="test2" refkey={refkey("test2")} />
|
|
388
379
|
</ts.SourceFile>
|
|
389
380
|
</Output>,
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
assertFileContents(res, {
|
|
381
|
+
).toRenderTo({
|
|
393
382
|
"src/test1.ts": `
|
|
394
383
|
import { test2 } from "../test2.js";
|
|
395
384
|
|
|
@@ -406,7 +395,7 @@ it("works with imports from different directories", () => {
|
|
|
406
395
|
});
|
|
407
396
|
|
|
408
397
|
it("handles conflicts with local declarations", () => {
|
|
409
|
-
|
|
398
|
+
expect(
|
|
410
399
|
<Output nameConflictResolver={tsNameConflictResolver}>
|
|
411
400
|
<SourceDirectory path="src">
|
|
412
401
|
<ts.SourceFile path="test1.ts">
|
|
@@ -421,9 +410,11 @@ it("handles conflicts with local declarations", () => {
|
|
|
421
410
|
<ts.FunctionDeclaration export name="test" />
|
|
422
411
|
</ts.SourceFile>
|
|
423
412
|
</Output>,
|
|
424
|
-
)
|
|
425
|
-
|
|
426
|
-
|
|
413
|
+
).toRenderTo({
|
|
414
|
+
"src/test1.ts": `
|
|
415
|
+
export function test() {}
|
|
416
|
+
const v = <Unresolved Symbol>;
|
|
417
|
+
`,
|
|
427
418
|
"test2.ts": `
|
|
428
419
|
import { test as test_1 } from "./src/test1.js";
|
|
429
420
|
|
|
@@ -455,7 +446,7 @@ describe("type imports", () => {
|
|
|
455
446
|
|
|
456
447
|
it("adds type keyword only to type imports", () => {
|
|
457
448
|
const { component, TypeA, ClassA } = mkTestFile("test1.ts");
|
|
458
|
-
|
|
449
|
+
expect(
|
|
459
450
|
<Output>
|
|
460
451
|
{component}
|
|
461
452
|
<ts.SourceFile path="test2.ts">
|
|
@@ -469,21 +460,20 @@ describe("type imports", () => {
|
|
|
469
460
|
</List>
|
|
470
461
|
</ts.SourceFile>
|
|
471
462
|
</Output>,
|
|
472
|
-
)
|
|
473
|
-
|
|
474
|
-
assertFileContents(res, {
|
|
463
|
+
).toRenderTo({
|
|
464
|
+
"test1.ts": expect.anything(),
|
|
475
465
|
"test2.ts": `
|
|
476
|
-
|
|
466
|
+
import { ClassA, type TypeA } from "./test1.js";
|
|
477
467
|
|
|
478
|
-
|
|
479
|
-
|
|
468
|
+
type A = TypeA
|
|
469
|
+
class B extends ClassA {}
|
|
480
470
|
`,
|
|
481
471
|
});
|
|
482
472
|
});
|
|
483
473
|
|
|
484
474
|
it("add type keyword for whole import if all are types", () => {
|
|
485
475
|
const { component, TypeA, TypeB } = mkTestFile("test1.ts");
|
|
486
|
-
|
|
476
|
+
expect(
|
|
487
477
|
<Output>
|
|
488
478
|
{component}
|
|
489
479
|
<ts.SourceFile path="test2.ts">
|
|
@@ -497,9 +487,8 @@ describe("type imports", () => {
|
|
|
497
487
|
</List>
|
|
498
488
|
</ts.SourceFile>
|
|
499
489
|
</Output>,
|
|
500
|
-
)
|
|
501
|
-
|
|
502
|
-
assertFileContents(res, {
|
|
490
|
+
).toRenderTo({
|
|
491
|
+
"test1.ts": expect.anything(),
|
|
503
492
|
"test2.ts": `
|
|
504
493
|
import type { TypeA, TypeB } from "./test1.js";
|
|
505
494
|
|
|
@@ -510,7 +499,7 @@ describe("type imports", () => {
|
|
|
510
499
|
});
|
|
511
500
|
it("reference same type multiple times", () => {
|
|
512
501
|
const { component, TypeA } = mkTestFile("test1.ts");
|
|
513
|
-
|
|
502
|
+
expect(
|
|
514
503
|
<Output>
|
|
515
504
|
{component}
|
|
516
505
|
<ts.SourceFile path="test2.ts">
|
|
@@ -524,9 +513,8 @@ describe("type imports", () => {
|
|
|
524
513
|
</List>
|
|
525
514
|
</ts.SourceFile>
|
|
526
515
|
</Output>,
|
|
527
|
-
)
|
|
528
|
-
|
|
529
|
-
assertFileContents(res, {
|
|
516
|
+
).toRenderTo({
|
|
517
|
+
"test1.ts": expect.anything(),
|
|
530
518
|
"test2.ts": `
|
|
531
519
|
import type { TypeA } from "./test1.js";
|
|
532
520
|
|
|
@@ -538,7 +526,7 @@ describe("type imports", () => {
|
|
|
538
526
|
|
|
539
527
|
it("same reference used as both type and non type doesn't include type", () => {
|
|
540
528
|
const { component, ClassA } = mkTestFile("test1.ts");
|
|
541
|
-
|
|
529
|
+
expect(
|
|
542
530
|
<Output>
|
|
543
531
|
{component}
|
|
544
532
|
<ts.SourceFile path="test2.ts">
|
|
@@ -552,9 +540,8 @@ describe("type imports", () => {
|
|
|
552
540
|
</List>
|
|
553
541
|
</ts.SourceFile>
|
|
554
542
|
</Output>,
|
|
555
|
-
)
|
|
556
|
-
|
|
557
|
-
assertFileContents(res, {
|
|
543
|
+
).toRenderTo({
|
|
544
|
+
"test1.ts": expect.anything(),
|
|
558
545
|
"test2.ts": `
|
|
559
546
|
import { ClassA } from "./test1.js";
|
|
560
547
|
|
|
@@ -566,7 +553,7 @@ describe("type imports", () => {
|
|
|
566
553
|
|
|
567
554
|
it("value reference from another file doesn't affect a type only reference", () => {
|
|
568
555
|
const { component, ClassA } = mkTestFile("test1.ts");
|
|
569
|
-
|
|
556
|
+
expect(
|
|
570
557
|
<Output>
|
|
571
558
|
{component}
|
|
572
559
|
<ts.SourceFile path="test2.ts">
|
|
@@ -576,9 +563,8 @@ describe("type imports", () => {
|
|
|
576
563
|
class B extends <Reference refkey={ClassA} /> {"{}"}
|
|
577
564
|
</ts.SourceFile>
|
|
578
565
|
</Output>,
|
|
579
|
-
)
|
|
580
|
-
|
|
581
|
-
assertFileContents(res, {
|
|
566
|
+
).toRenderTo({
|
|
567
|
+
"test1.ts": expect.anything(),
|
|
582
568
|
"test2.ts": `
|
|
583
569
|
import type { ClassA } from "./test1.js";
|
|
584
570
|
|
|
@@ -594,7 +580,7 @@ describe("type imports", () => {
|
|
|
594
580
|
|
|
595
581
|
it("infer if a type reference from the typescript context", () => {
|
|
596
582
|
const { component, TypeA } = mkTestFile("test1.ts");
|
|
597
|
-
|
|
583
|
+
expect(
|
|
598
584
|
<Output>
|
|
599
585
|
{component}
|
|
600
586
|
<ts.SourceFile path="test2.ts">
|
|
@@ -610,9 +596,8 @@ describe("type imports", () => {
|
|
|
610
596
|
</TypeRefContext.Provider>
|
|
611
597
|
</ts.SourceFile>
|
|
612
598
|
</Output>,
|
|
613
|
-
)
|
|
614
|
-
|
|
615
|
-
assertFileContents(res, {
|
|
599
|
+
).toRenderTo({
|
|
600
|
+
"test1.ts": expect.anything(),
|
|
616
601
|
"test2.ts": `
|
|
617
602
|
import type { TypeA } from "./test1.js";
|
|
618
603
|
|
|
@@ -633,15 +618,13 @@ describe("type imports", () => {
|
|
|
633
618
|
},
|
|
634
619
|
});
|
|
635
620
|
|
|
636
|
-
|
|
621
|
+
expect(
|
|
637
622
|
<Output externals={[pkg1]}>
|
|
638
623
|
<ts.SourceFile path="test2.ts">
|
|
639
624
|
type A = <Reference refkey={pkg1.Foo} type />
|
|
640
625
|
</ts.SourceFile>
|
|
641
626
|
</Output>,
|
|
642
|
-
)
|
|
643
|
-
|
|
644
|
-
assertFileContents(res, {
|
|
627
|
+
).toRenderTo({
|
|
645
628
|
"test2.ts": `
|
|
646
629
|
import type { Foo } from "test";
|
|
647
630
|
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
code,
|
|
3
|
-
List,
|
|
4
|
-
Output,
|
|
5
|
-
refkey,
|
|
6
|
-
render,
|
|
7
|
-
StatementList,
|
|
8
|
-
} from "@alloy-js/core";
|
|
1
|
+
import { code, List, Output, refkey, StatementList } from "@alloy-js/core";
|
|
9
2
|
import { d } from "@alloy-js/core/testing";
|
|
10
3
|
import { describe, expect, it } from "vitest";
|
|
11
4
|
import { InterfaceMember, ObjectExpression } from "../src/components/index.js";
|
|
@@ -20,7 +13,7 @@ import {
|
|
|
20
13
|
ParameterDescriptor,
|
|
21
14
|
SourceFile,
|
|
22
15
|
} from "../src/index.js";
|
|
23
|
-
import {
|
|
16
|
+
import { toSourceText } from "./utils.js";
|
|
24
17
|
|
|
25
18
|
it("renders basic member expression with dot notation", () => {
|
|
26
19
|
expect(
|
|
@@ -498,7 +491,7 @@ describe("with refkeys", () => {
|
|
|
498
491
|
|
|
499
492
|
it("creates a full reference to the first refkey", () => {
|
|
500
493
|
const rk1 = refkey();
|
|
501
|
-
|
|
494
|
+
expect(
|
|
502
495
|
<Output>
|
|
503
496
|
<SourceFile path="source.ts">
|
|
504
497
|
<VarDeclaration name="importMe">
|
|
@@ -520,15 +513,14 @@ describe("with refkeys", () => {
|
|
|
520
513
|
</StatementList>
|
|
521
514
|
</SourceFile>
|
|
522
515
|
</Output>,
|
|
523
|
-
)
|
|
524
|
-
|
|
525
|
-
assertFileContents(res, {
|
|
516
|
+
).toRenderTo({
|
|
526
517
|
"index.ts": d`
|
|
527
518
|
import { importMe } from "./source.js";
|
|
528
519
|
|
|
529
520
|
importMe.prop.foo;
|
|
530
521
|
importMe.prop.foo;
|
|
531
522
|
`,
|
|
523
|
+
"source.ts": expect.anything(),
|
|
532
524
|
});
|
|
533
525
|
});
|
|
534
526
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Output
|
|
2
|
-
import { d } from "@alloy-js/core/testing";
|
|
1
|
+
import { Output } from "@alloy-js/core";
|
|
3
2
|
import { camelCase } from "change-case";
|
|
4
3
|
import { expect, it } from "vitest";
|
|
5
4
|
import {
|
|
@@ -9,7 +8,7 @@ import {
|
|
|
9
8
|
TSSymbolFlags,
|
|
10
9
|
} from "../src/index.js";
|
|
11
10
|
import { ParameterDescriptor } from "../src/parameter-descriptor.js";
|
|
12
|
-
|
|
11
|
+
|
|
13
12
|
it("handles custom name conflict resolver based on metadata", () => {
|
|
14
13
|
function resolver(name: string, symbols: TSOutputSymbol[]) {
|
|
15
14
|
const goodNamedSymbols = symbols.filter(
|
|
@@ -79,7 +78,7 @@ it("handles custom name conflict resolver based on metadata", () => {
|
|
|
79
78
|
{ name: "foo", metadata: { sourceLocation: "header" } },
|
|
80
79
|
];
|
|
81
80
|
|
|
82
|
-
|
|
81
|
+
expect(
|
|
83
82
|
<Output nameConflictResolver={resolver}>
|
|
84
83
|
<SourceFile path="test.ts">
|
|
85
84
|
<FunctionDeclaration
|
|
@@ -89,9 +88,7 @@ it("handles custom name conflict resolver based on metadata", () => {
|
|
|
89
88
|
/>
|
|
90
89
|
</SourceFile>
|
|
91
90
|
</Output>,
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
expect(findFile(res, "test.ts").contents).toBe(d`
|
|
91
|
+
).toRenderTo(`
|
|
95
92
|
export function conflicty(
|
|
96
93
|
foo,
|
|
97
94
|
foo1,
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { Output, refkey,
|
|
1
|
+
import { Output, refkey, StatementList } 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 { createTSNamePolicy } from "../src/name-policy.js";
|
|
7
|
-
import { findFile } from "./utils.jsx";
|
|
8
6
|
|
|
9
7
|
it("applies to functions and variables", () => {
|
|
10
8
|
const ref1 = refkey({});
|
|
11
9
|
const ref2 = refkey({});
|
|
12
10
|
|
|
13
11
|
const namePolicy = createTSNamePolicy();
|
|
14
|
-
|
|
12
|
+
expect(
|
|
15
13
|
<Output namePolicy={namePolicy}>
|
|
16
14
|
<ts.SourceFile path="test.ts">
|
|
17
15
|
<ts.FunctionDeclaration name="foo-bar" refkey={ref1} />
|
|
@@ -25,9 +23,7 @@ it("applies to functions and variables", () => {
|
|
|
25
23
|
</StatementList>
|
|
26
24
|
</ts.SourceFile>
|
|
27
25
|
</Output>,
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
expect(findFile(res, "test.ts").contents).toEqual(d`
|
|
26
|
+
).toRenderTo(`
|
|
31
27
|
function fooBar() {}
|
|
32
28
|
const oneTwo = "hello";
|
|
33
29
|
fooBar;
|
|
@@ -40,7 +36,7 @@ it("keeps _ and $ prefix", () => {
|
|
|
40
36
|
const ref2 = refkey({});
|
|
41
37
|
|
|
42
38
|
const namePolicy = createTSNamePolicy();
|
|
43
|
-
|
|
39
|
+
expect(
|
|
44
40
|
<Output namePolicy={namePolicy}>
|
|
45
41
|
<ts.SourceFile path="test.ts">
|
|
46
42
|
<ts.FunctionDeclaration name="_foo-bar" refkey={ref1} />
|
|
@@ -54,9 +50,7 @@ it("keeps _ and $ prefix", () => {
|
|
|
54
50
|
</StatementList>
|
|
55
51
|
</ts.SourceFile>
|
|
56
52
|
</Output>,
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
expect(findFile(res, "test.ts").contents).toEqual(d`
|
|
53
|
+
).toRenderTo(`
|
|
60
54
|
function _fooBar() {}
|
|
61
55
|
const $oneTwo = "hello";
|
|
62
56
|
_fooBar;
|
|
@@ -69,7 +63,7 @@ it("appends _ to reserved words", () => {
|
|
|
69
63
|
const ref2 = refkey({});
|
|
70
64
|
|
|
71
65
|
const namePolicy = createTSNamePolicy();
|
|
72
|
-
|
|
66
|
+
expect(
|
|
73
67
|
<Output namePolicy={namePolicy}>
|
|
74
68
|
<ts.SourceFile path="test.ts">
|
|
75
69
|
<ts.FunctionDeclaration
|
|
@@ -87,9 +81,7 @@ it("appends _ to reserved words", () => {
|
|
|
87
81
|
</StatementList>
|
|
88
82
|
</ts.SourceFile>
|
|
89
83
|
</Output>,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
expect(findFile(res, "test.ts").contents).toEqual(d`
|
|
84
|
+
).toRenderTo(`
|
|
93
85
|
function default_(await_: any) {}
|
|
94
86
|
const super_ = "hello";
|
|
95
87
|
default_;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { Output, refkey,
|
|
1
|
+
import { Output, refkey, StatementList } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
|
-
import { it } from "vitest";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
4
|
import * as ts from "../src/index.js";
|
|
5
|
-
import { assertFileContents } from "./utils.jsx";
|
|
6
5
|
|
|
7
6
|
it("should instantiate classes", () => {
|
|
8
7
|
const varRk = refkey();
|
|
9
8
|
const classRk = refkey();
|
|
10
9
|
const memberRk = refkey();
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
expect(
|
|
13
12
|
<Output>
|
|
14
13
|
<ts.SourceFile path="inst.ts">
|
|
15
14
|
<StatementList>
|
|
@@ -28,9 +27,7 @@ it("should instantiate classes", () => {
|
|
|
28
27
|
</ts.ClassDeclaration>
|
|
29
28
|
</ts.SourceFile>
|
|
30
29
|
</Output>,
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
assertFileContents(tree, {
|
|
30
|
+
).toRenderTo({
|
|
34
31
|
"inst.ts": d`
|
|
35
32
|
import { Foo } from "./decl.js";
|
|
36
33
|
|