@alloy-js/typescript 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/src/components/ArrayExpression.d.ts +1 -1
- package/dist/src/components/ArrayExpression.d.ts.map +1 -1
- package/dist/src/components/ArrayExpression.js +18 -28
- package/dist/src/components/ArrayExpression.js.map +1 -1
- package/dist/src/components/BarrelFile.d.ts.map +1 -1
- package/dist/src/components/BarrelFile.js +11 -9
- package/dist/src/components/BarrelFile.js.map +1 -1
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +8 -9
- package/dist/src/components/ClassDeclaration.js.map +1 -1
- package/dist/src/components/CommaList.d.ts +12 -0
- package/dist/src/components/CommaList.d.ts.map +1 -0
- package/dist/src/components/CommaList.js +19 -0
- package/dist/src/components/CommaList.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +4 -0
- package/dist/src/components/Declaration.d.ts.map +1 -1
- package/dist/src/components/Declaration.js +3 -2
- package/dist/src/components/Declaration.js.map +1 -1
- package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
- package/dist/src/components/EnumDeclaration.js +21 -18
- package/dist/src/components/EnumDeclaration.js.map +1 -1
- package/dist/src/components/EnumMember.d.ts.map +1 -1
- package/dist/src/components/EnumMember.js.map +1 -1
- package/dist/src/components/ExportStatement.d.ts.map +1 -1
- package/dist/src/components/ExportStatement.js +3 -1
- package/dist/src/components/ExportStatement.js.map +1 -1
- package/dist/src/components/FunctionCallExpression.d.ts +2 -2
- package/dist/src/components/FunctionCallExpression.d.ts.map +1 -1
- package/dist/src/components/FunctionCallExpression.js +26 -9
- package/dist/src/components/FunctionCallExpression.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts +10 -2
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js +136 -33
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/ImportStatement.d.ts.map +1 -1
- package/dist/src/components/ImportStatement.js +25 -31
- package/dist/src/components/ImportStatement.js.map +1 -1
- package/dist/src/components/Interface.d.ts +1 -1
- package/dist/src/components/Interface.d.ts.map +1 -1
- package/dist/src/components/Interface.js +5 -5
- package/dist/src/components/Interface.js.map +1 -1
- package/dist/src/components/JSDoc.d.ts +10 -0
- package/dist/src/components/JSDoc.d.ts.map +1 -0
- package/dist/src/components/JSDoc.js +24 -0
- package/dist/src/components/JSDoc.js.map +1 -0
- package/dist/src/components/JSDocComment.d.ts +11 -0
- package/dist/src/components/JSDocComment.d.ts.map +1 -0
- package/dist/src/components/JSDocComment.js +16 -0
- package/dist/src/components/JSDocComment.js.map +1 -0
- package/dist/src/components/JSDocExample.d.ts +12 -0
- package/dist/src/components/JSDocExample.d.ts.map +1 -0
- package/dist/src/components/JSDocExample.js +26 -0
- package/dist/src/components/JSDocExample.js.map +1 -0
- package/dist/src/components/JSDocParagraph.d.ts +10 -0
- package/dist/src/components/JSDocParagraph.d.ts.map +1 -0
- package/dist/src/components/JSDocParagraph.js +23 -0
- package/dist/src/components/JSDocParagraph.js.map +1 -0
- package/dist/src/components/MemberChainExpression.d.ts +11 -0
- package/dist/src/components/MemberChainExpression.d.ts.map +1 -0
- package/dist/src/components/MemberChainExpression.js +100 -0
- package/dist/src/components/MemberChainExpression.js.map +1 -0
- package/dist/src/components/ObjectExpression.d.ts +1 -1
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +45 -42
- package/dist/src/components/ObjectExpression.js.map +1 -1
- package/dist/src/components/PackageDirectory.d.ts +1 -3
- package/dist/src/components/PackageDirectory.d.ts.map +1 -1
- package/dist/src/components/PackageDirectory.js +9 -16
- package/dist/src/components/PackageDirectory.js.map +1 -1
- package/dist/src/components/PackageJson.d.ts +39 -0
- package/dist/src/components/PackageJson.d.ts.map +1 -1
- package/dist/src/components/PackageJson.js +30 -12
- package/dist/src/components/PackageJson.js.map +1 -1
- package/dist/src/components/Reference.js +1 -1
- package/dist/src/components/Reference.js.map +1 -1
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +13 -6
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/TsConfigJson.d.ts.map +1 -1
- package/dist/src/components/TsConfigJson.js.map +1 -1
- package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
- package/dist/src/components/TypeDeclaration.js.map +1 -1
- package/dist/src/components/ValueExpression.d.ts.map +1 -1
- package/dist/src/components/ValueExpression.js.map +1 -1
- package/dist/src/components/VarDeclaration.d.ts.map +1 -1
- package/dist/src/components/VarDeclaration.js +5 -4
- package/dist/src/components/VarDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +2 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +2 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/stc/index.d.ts +21 -21
- package/dist/src/components/stc/index.d.ts.map +1 -1
- package/dist/src/components/stc/index.js +1 -1
- package/dist/src/components/stc/index.js.map +1 -1
- package/dist/src/symbols/reference.d.ts.map +1 -1
- package/dist/src/symbols/reference.js +5 -2
- package/dist/src/symbols/reference.js.map +1 -1
- package/dist/src/symbols/ts-output-symbol.d.ts +2 -1
- package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
- package/dist/src/symbols/ts-output-symbol.js +4 -1
- package/dist/src/symbols/ts-output-symbol.js.map +1 -1
- package/dist/src/symbols/ts-package-scope.d.ts +0 -15
- package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
- package/dist/src/symbols/ts-package-scope.js +0 -8
- package/dist/src/symbols/ts-package-scope.js.map +1 -1
- package/dist/test/imports.test.d.ts.map +1 -1
- package/dist/test/jsdoc.test.d.ts +2 -0
- package/dist/test/jsdoc.test.d.ts.map +1 -0
- package/dist/test/member-chain.test.d.ts +2 -0
- package/dist/test/member-chain.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/values.test.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -5
- package/src/components/ArrayExpression.tsx +22 -32
- package/src/components/BarrelFile.tsx +7 -13
- package/src/components/ClassDeclaration.tsx +33 -28
- package/src/components/CommaList.tsx +23 -0
- package/src/components/Declaration.tsx +14 -5
- package/src/components/EnumDeclaration.tsx +23 -16
- package/src/components/EnumMember.tsx +7 -4
- package/src/components/ExportStatement.tsx +9 -2
- package/src/components/FunctionCallExpression.tsx +18 -9
- package/src/components/FunctionDeclaration.tsx +173 -56
- package/src/components/ImportStatement.tsx +6 -9
- package/src/components/Interface.tsx +20 -13
- package/src/components/JSDoc.tsx +28 -0
- package/src/components/JSDocComment.tsx +23 -0
- package/src/components/JSDocExample.tsx +30 -0
- package/src/components/JSDocParagraph.tsx +35 -0
- package/src/components/MemberChainExpression.tsx +91 -0
- package/src/components/ObjectExpression.tsx +53 -48
- package/src/components/PackageDirectory.tsx +22 -30
- package/src/components/PackageJson.tsx +91 -29
- package/src/components/SourceFile.tsx +15 -8
- package/src/components/TsConfigJson.tsx +5 -3
- package/src/components/TypeDeclaration.tsx +5 -3
- package/src/components/ValueExpression.tsx +3 -1
- package/src/components/VarDeclaration.tsx +13 -7
- package/src/components/index.ts +2 -1
- package/src/components/stc/index.ts +1 -1
- package/src/symbols/reference.ts +7 -4
- package/src/symbols/ts-output-symbol.ts +6 -2
- package/src/symbols/ts-package-scope.ts +0 -28
- package/temp/api.json +802 -395
- package/test/array.test.tsx +40 -7
- package/test/basic.test.tsx +26 -21
- package/test/class.test.tsx +65 -53
- package/test/enum.test.tsx +18 -13
- package/test/externals.test.tsx +6 -7
- package/test/function-call-expression.test.tsx +39 -17
- package/test/function-declaration.test.tsx +96 -78
- package/test/imports.test.tsx +115 -75
- package/test/interface.test.tsx +32 -22
- package/test/jsdoc.test.tsx +154 -0
- package/test/member-chain.test.tsx +124 -0
- package/test/name-policy.test.tsx +33 -26
- package/test/package-external.test.tsx +106 -7
- package/test/package.test.tsx +57 -5
- package/test/reference.test.tsx +2 -6
- package/test/utils.tsx +3 -1
- package/test/value-expression.test.tsx +2 -6
- package/test/values.test.tsx +67 -73
- package/test/var-declaration.test.tsx +11 -5
- package/test/vitest.d.ts +6 -1
- package/tsconfig.json +8 -1
- package/dist/src/components/Block.d.ts +0 -6
- package/dist/src/components/Block.d.ts.map +0 -1
- package/dist/src/components/Block.js +0 -11
- package/dist/src/components/Block.js.map +0 -1
- package/src/components/Block.tsx +0 -12
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AssignmentContext,
|
|
3
|
+
Block,
|
|
3
4
|
Children,
|
|
4
5
|
computed,
|
|
5
6
|
createAssignmentContext,
|
|
7
|
+
For,
|
|
6
8
|
getAssignmentSymbol,
|
|
7
|
-
|
|
9
|
+
Match,
|
|
8
10
|
MemberScope,
|
|
9
|
-
memo,
|
|
10
11
|
OutputSymbolFlags,
|
|
11
12
|
Refkey,
|
|
13
|
+
Switch,
|
|
14
|
+
Wrap,
|
|
12
15
|
} from "@alloy-js/core";
|
|
13
16
|
import { createTSSymbol } from "../symbols/index.js";
|
|
14
17
|
import { ValueExpression } from "./ValueExpression.js";
|
|
@@ -28,7 +31,7 @@ export function ObjectExpression(props: ObjectExpressionProps) {
|
|
|
28
31
|
assignmentSymbol.binder.addStaticMembersToSymbol(assignmentSymbol);
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
const
|
|
34
|
+
const jsValueProperties = computed(() => {
|
|
32
35
|
const jsValue = props.jsValue;
|
|
33
36
|
let properties: [string, unknown][];
|
|
34
37
|
if (Array.isArray(jsValue)) {
|
|
@@ -40,45 +43,45 @@ export function ObjectExpression(props: ObjectExpressionProps) {
|
|
|
40
43
|
} else {
|
|
41
44
|
properties = [];
|
|
42
45
|
}
|
|
43
|
-
|
|
44
|
-
properties,
|
|
45
|
-
([name, value]) => {
|
|
46
|
-
return <ObjectProperty name={name} jsValue={value} />;
|
|
47
|
-
},
|
|
48
|
-
{ joiner: ",\n" },
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
if (props.children) {
|
|
52
|
-
if (elements.length > 0) {
|
|
53
|
-
elements.push(",");
|
|
54
|
-
}
|
|
55
|
-
elements.push(props.children);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return elements;
|
|
46
|
+
return properties;
|
|
59
47
|
});
|
|
60
48
|
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
49
|
+
return (
|
|
50
|
+
<Switch>
|
|
51
|
+
<Match
|
|
52
|
+
when={jsValueProperties.value.length === 0 && !("children" in props)}
|
|
53
|
+
>
|
|
54
|
+
{"{}"}
|
|
55
|
+
</Match>
|
|
56
|
+
<Match else>
|
|
57
|
+
<group>
|
|
58
|
+
<Wrap
|
|
59
|
+
when={!!assignmentSymbol}
|
|
60
|
+
with={MemberScope}
|
|
61
|
+
props={{ owner: assignmentSymbol! }}
|
|
62
|
+
>
|
|
63
|
+
<Block>
|
|
64
|
+
<For each={jsValueProperties} comma softline enderPunctuation>
|
|
65
|
+
{([name, value]) => (
|
|
66
|
+
<ObjectProperty name={name} jsValue={value} />
|
|
67
|
+
)}
|
|
68
|
+
</For>
|
|
69
|
+
{props.children && (
|
|
70
|
+
<>
|
|
71
|
+
{jsValueProperties.value.length > 0 && (
|
|
72
|
+
<>
|
|
73
|
+
,<sbr />
|
|
74
|
+
</>
|
|
75
|
+
)}
|
|
76
|
+
{props.children}
|
|
77
|
+
</>
|
|
78
|
+
)}
|
|
79
|
+
</Block>
|
|
80
|
+
</Wrap>
|
|
81
|
+
</group>
|
|
82
|
+
</Match>
|
|
83
|
+
</Switch>
|
|
84
|
+
);
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
export interface ObjectPropertyProps {
|
|
@@ -119,12 +122,14 @@ export function ObjectProperty(props: ObjectPropertyProps) {
|
|
|
119
122
|
value = props.children;
|
|
120
123
|
}
|
|
121
124
|
|
|
122
|
-
const assignmentContext: AssignmentContext | undefined =
|
|
123
|
-
createAssignmentContext(sym)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
{
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
const assignmentContext: AssignmentContext | undefined =
|
|
126
|
+
sym ? createAssignmentContext(sym) : undefined;
|
|
127
|
+
return (
|
|
128
|
+
<>
|
|
129
|
+
{sym ? sym.name : name}:{" "}
|
|
130
|
+
<AssignmentContext.Provider value={assignmentContext}>
|
|
131
|
+
{value}
|
|
132
|
+
</AssignmentContext.Provider>
|
|
133
|
+
</>
|
|
134
|
+
);
|
|
130
135
|
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
shallowRef,
|
|
8
8
|
SourceDirectory,
|
|
9
9
|
SourceDirectoryContext,
|
|
10
|
+
splitProps,
|
|
10
11
|
useBinder,
|
|
11
12
|
useContext,
|
|
12
13
|
useScope,
|
|
@@ -14,17 +15,10 @@ import {
|
|
|
14
15
|
import { join } from "pathe";
|
|
15
16
|
import { createTSPackageScope, TSPackageScope } from "../symbols/index.js";
|
|
16
17
|
import { modulePath } from "../utils.js";
|
|
17
|
-
import {
|
|
18
|
-
ExportPath,
|
|
19
|
-
PackageExports,
|
|
20
|
-
PackageJsonFile,
|
|
21
|
-
PackageJsonFileProps,
|
|
22
|
-
} from "./PackageJson.js";
|
|
18
|
+
import { PackageJsonFile, PackageJsonFileProps } from "./PackageJson.js";
|
|
23
19
|
import { TSConfigJson } from "./TsConfigJson.js";
|
|
24
20
|
|
|
25
21
|
export interface PackageDirectoryProps extends PackageJsonFileProps {
|
|
26
|
-
dependencies?: Record<string, string>;
|
|
27
|
-
exports?: PackageExports | ExportPath;
|
|
28
22
|
tsConfig?: { outDir?: string };
|
|
29
23
|
children?: Children;
|
|
30
24
|
path?: string;
|
|
@@ -54,31 +48,29 @@ export function PackageDirectory(props: PackageDirectoryProps) {
|
|
|
54
48
|
props.path ?? ".",
|
|
55
49
|
);
|
|
56
50
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} else {
|
|
61
|
-
for (const ex of Object.entries(props.exports)) {
|
|
62
|
-
packageContext.scope.addRawExport(ex[0], ex[1]);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
51
|
+
const devDeps = props.devDependencies ?? {};
|
|
52
|
+
if (!devDeps["typescript"]) {
|
|
53
|
+
devDeps["typescript"] = "^5.5.2";
|
|
65
54
|
}
|
|
66
55
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
56
|
+
const [_, pkgJsonProps] = splitProps(props, [
|
|
57
|
+
"tsConfig",
|
|
58
|
+
"children",
|
|
59
|
+
"path",
|
|
60
|
+
"devDependencies",
|
|
61
|
+
]);
|
|
72
62
|
|
|
73
|
-
return
|
|
74
|
-
<
|
|
75
|
-
<
|
|
76
|
-
<
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
63
|
+
return (
|
|
64
|
+
<SourceDirectory path={props.path ?? "."}>
|
|
65
|
+
<PackageContext.Provider value={packageContext}>
|
|
66
|
+
<Scope value={packageContext.scope}>
|
|
67
|
+
<PackageJsonFile {...pkgJsonProps} devDependencies={devDeps} />
|
|
68
|
+
<TSConfigJson {...props.tsConfig} />
|
|
69
|
+
{props.children}
|
|
70
|
+
</Scope>
|
|
71
|
+
</PackageContext.Provider>
|
|
72
|
+
</SourceDirectory>
|
|
73
|
+
);
|
|
82
74
|
}
|
|
83
75
|
|
|
84
76
|
function createPackageContext(
|
|
@@ -3,10 +3,47 @@ import { modulePath } from "../utils.js";
|
|
|
3
3
|
import { usePackage } from "./PackageDirectory.js";
|
|
4
4
|
|
|
5
5
|
export interface PackageJsonFileProps {
|
|
6
|
+
/** The name of the package */
|
|
6
7
|
name: string;
|
|
8
|
+
|
|
9
|
+
/** The version of the package */
|
|
7
10
|
version: string;
|
|
11
|
+
|
|
12
|
+
/** The description of the package */
|
|
13
|
+
description?: string;
|
|
14
|
+
|
|
15
|
+
/** The license of the package */
|
|
16
|
+
license?: string;
|
|
17
|
+
|
|
18
|
+
/** The author of the package */
|
|
19
|
+
author?: string;
|
|
20
|
+
|
|
21
|
+
/** The homepage of the package */
|
|
22
|
+
homepage?: string;
|
|
23
|
+
|
|
24
|
+
/** The repository of the package */
|
|
25
|
+
repository?: string | { type: string; url: string };
|
|
26
|
+
|
|
27
|
+
/** The keywords of the package */
|
|
28
|
+
keywords?: string[];
|
|
29
|
+
|
|
30
|
+
/** Whether this is a commonjs or module. Defaults to module. */
|
|
8
31
|
type?: "module" | "commonjs";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The hard-coded dependencies of the package. References to external packages
|
|
35
|
+
* will add to the dependency list automatically. Only list dependencies here
|
|
36
|
+
* that are not referenced via refkey.
|
|
37
|
+
*/
|
|
38
|
+
dependencies?: Record<string, string>;
|
|
39
|
+
|
|
40
|
+
/** The hard-coded exports of the package. */
|
|
41
|
+
exports?: PackageExports | ExportPath;
|
|
42
|
+
|
|
43
|
+
/** The dev dependencies of the package. */
|
|
9
44
|
devDependencies?: Record<string, string>;
|
|
45
|
+
|
|
46
|
+
/** The scripts entries of the package. */
|
|
10
47
|
scripts?: Record<string, string>;
|
|
11
48
|
}
|
|
12
49
|
|
|
@@ -20,50 +57,75 @@ export interface PackageExports {
|
|
|
20
57
|
[key: string]: ExportPath;
|
|
21
58
|
}
|
|
22
59
|
|
|
60
|
+
/**
|
|
61
|
+
* A file containing a package.json that defines a package. When placed inside a
|
|
62
|
+
* {@link PackageDirectory}, it will contain dependencies and exports for
|
|
63
|
+
* symbols defined inside the package. Additional dependencies and exports can
|
|
64
|
+
* be provided.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* <PackageJsonFile name="my-package" version="1.0.0" />
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
23
71
|
export function PackageJsonFile(props: PackageJsonFileProps) {
|
|
24
72
|
const pkg = usePackage();
|
|
25
|
-
if (!pkg) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
"Package json component needs to be inside a PackageDirectory",
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
73
|
|
|
31
74
|
const jsonContent = memo(() => {
|
|
32
75
|
const pkgJson = {
|
|
33
76
|
name: props.name,
|
|
34
77
|
version: props.version,
|
|
78
|
+
author: props.author,
|
|
79
|
+
description: props.description,
|
|
80
|
+
license: props.license,
|
|
81
|
+
homepage: props.homepage,
|
|
35
82
|
type: props.type ?? "module",
|
|
36
|
-
dependencies:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
83
|
+
dependencies:
|
|
84
|
+
props.dependencies || (pkg && pkg.scope.dependencies.size > 0) ?
|
|
85
|
+
Object.fromEntries([
|
|
86
|
+
...Object.entries(props.dependencies ?? {}),
|
|
87
|
+
...(pkg ?
|
|
88
|
+
Array.from(pkg.scope.dependencies).map((dependency) => [
|
|
89
|
+
dependency.name,
|
|
90
|
+
dependency.version,
|
|
91
|
+
])
|
|
92
|
+
: []),
|
|
93
|
+
])
|
|
94
|
+
: undefined,
|
|
95
|
+
devDependencies: props.devDependencies,
|
|
47
96
|
scripts: props.scripts,
|
|
48
97
|
exports: undefined as any,
|
|
49
98
|
};
|
|
50
99
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
100
|
+
if (typeof props.exports === "string") {
|
|
101
|
+
pkgJson.exports = props.exports;
|
|
102
|
+
} else {
|
|
103
|
+
const exportsEntries: [string, ExportPath][] = [];
|
|
104
|
+
for (const entry of Object.entries(props.exports ?? {})) {
|
|
105
|
+
exportsEntries.push(entry);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (pkg) {
|
|
109
|
+
for (const [publicPath, module] of pkg.scope.exportedSymbols) {
|
|
110
|
+
exportsEntries.push([
|
|
111
|
+
publicPath,
|
|
112
|
+
modulePath(pkg.outFileMapper.value(module.name)),
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
58
116
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
117
|
+
pkgJson.exports =
|
|
118
|
+
exportsEntries.length === 0 ?
|
|
119
|
+
undefined
|
|
120
|
+
: Object.fromEntries(exportsEntries);
|
|
121
|
+
}
|
|
62
122
|
|
|
63
123
|
return JSON.stringify(pkgJson, null, 2);
|
|
64
124
|
});
|
|
65
125
|
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
126
|
+
return (
|
|
127
|
+
<SourceFile path="package.json" filetype="json">
|
|
128
|
+
{jsonContent}
|
|
129
|
+
</SourceFile>
|
|
130
|
+
);
|
|
69
131
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
SourceFile as CoreSourceFile,
|
|
4
4
|
createNamedContext,
|
|
5
5
|
Scope,
|
|
6
|
+
Show,
|
|
6
7
|
SourceDirectoryContext,
|
|
7
8
|
useBinder,
|
|
8
9
|
useContext,
|
|
@@ -58,14 +59,20 @@ export function SourceFile(props: SourceFileProps) {
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
return (
|
|
63
|
+
<CoreSourceFile
|
|
64
|
+
path={props.path}
|
|
65
|
+
filetype="typescript"
|
|
66
|
+
reference={Reference}
|
|
67
|
+
>
|
|
68
|
+
<Show when={scope.importedModules.size > 0}>
|
|
69
|
+
<ImportStatements records={scope.importedModules} />
|
|
70
|
+
<hbr />
|
|
71
|
+
<hbr />
|
|
72
|
+
</Show>
|
|
73
|
+
<SourceFileContext.Provider value={sfContext}>
|
|
68
74
|
<Scope value={scope}>{props.children}</Scope>
|
|
69
75
|
</SourceFileContext.Provider>
|
|
70
|
-
</CoreSourceFile
|
|
76
|
+
</CoreSourceFile>
|
|
77
|
+
);
|
|
71
78
|
}
|
|
@@ -56,7 +56,9 @@ export function TSConfigJson(props: TSConfigJsonProps) {
|
|
|
56
56
|
return JSON.stringify(jsonContent, null, 2);
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
return (
|
|
60
|
+
<SourceFile path="tsconfig.json" filetype="json">
|
|
61
|
+
{jsonContent}
|
|
62
|
+
</SourceFile>
|
|
63
|
+
);
|
|
62
64
|
}
|
|
@@ -4,7 +4,9 @@ import { BaseDeclarationProps, Declaration } from "./Declaration.js";
|
|
|
4
4
|
export interface TypeDeclarationProps extends BaseDeclarationProps {}
|
|
5
5
|
|
|
6
6
|
export function TypeDeclaration(props: TypeDeclarationProps) {
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
return (
|
|
8
|
+
<Declaration {...props} nameKind="type">
|
|
9
|
+
type <Name /> = {props.children};
|
|
10
|
+
</Declaration>
|
|
11
|
+
);
|
|
10
12
|
}
|
|
@@ -24,7 +24,9 @@ export function ValueExpression(props: ValueExpressionProps): Children {
|
|
|
24
24
|
} else if (Array.isArray(jsValue)) {
|
|
25
25
|
return <ArrayExpression jsValue={jsValue as unknown[]} />;
|
|
26
26
|
} else {
|
|
27
|
-
return
|
|
27
|
+
return (
|
|
28
|
+
<ObjectExpression jsValue={jsValue as Record<string, unknown>} />
|
|
29
|
+
);
|
|
28
30
|
}
|
|
29
31
|
} else if (typeof jsValue === "function") {
|
|
30
32
|
// functions are inserted as-is.
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
Declaration as CoreDeclaration,
|
|
5
5
|
createAssignmentContext,
|
|
6
6
|
Name,
|
|
7
|
-
refkey,
|
|
8
7
|
} from "@alloy-js/core";
|
|
9
8
|
import { useTSNamePolicy } from "../name-policy.js";
|
|
10
9
|
import { createTSSymbol } from "../symbols/index.js";
|
|
@@ -27,16 +26,23 @@ export function VarDeclaration(props: VarDeclarationProps) {
|
|
|
27
26
|
const name = useTSNamePolicy().getName(props.name, "variable");
|
|
28
27
|
const sym = createTSSymbol({
|
|
29
28
|
name: name,
|
|
30
|
-
refkey: props.refkey
|
|
29
|
+
refkey: props.refkey,
|
|
30
|
+
refkeys: props.refkeys,
|
|
31
31
|
default: props.default,
|
|
32
32
|
export: props.export,
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
const assignmentContext = createAssignmentContext(sym);
|
|
36
36
|
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
{props.
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
return (
|
|
38
|
+
<CoreDeclaration symbol={sym}>
|
|
39
|
+
{props.export ? "export " : ""}
|
|
40
|
+
{props.default ? "default " : ""}
|
|
41
|
+
{keyword} <Name />
|
|
42
|
+
{type} ={" "}
|
|
43
|
+
<AssignmentContext.Provider value={assignmentContext}>
|
|
44
|
+
{props.value ?? props.children}
|
|
45
|
+
</AssignmentContext.Provider>
|
|
46
|
+
</CoreDeclaration>
|
|
47
|
+
);
|
|
42
48
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from "./ArrayExpression.js";
|
|
2
2
|
export * from "./BarrelFile.js";
|
|
3
|
-
export * from "./Block.js";
|
|
4
3
|
export * from "./ClassDeclaration.jsx";
|
|
4
|
+
export * from "./CommaList.jsx";
|
|
5
5
|
export * from "./Declaration.js";
|
|
6
6
|
export * from "./EnumDeclaration.js";
|
|
7
7
|
export * from "./EnumMember.js";
|
|
@@ -10,6 +10,7 @@ export * from "./FunctionCallExpression.js";
|
|
|
10
10
|
export * from "./FunctionDeclaration.js";
|
|
11
11
|
export * from "./ImportStatement.js";
|
|
12
12
|
export * from "./Interface.js";
|
|
13
|
+
export * from "./MemberChainExpression.jsx";
|
|
13
14
|
export * from "./ObjectExpression.js";
|
|
14
15
|
export * from "./PackageDirectory.js";
|
|
15
16
|
export * from "./PackageJson.js";
|
|
@@ -3,7 +3,6 @@ import * as base from "../index.js";
|
|
|
3
3
|
|
|
4
4
|
export const ArrayExpression = stc(base.ArrayExpression);
|
|
5
5
|
export const BarrelFile = stc(base.BarrelFile);
|
|
6
|
-
export const Block = stc(base.Block);
|
|
7
6
|
export const ClassDeclaration = stc(base.ClassDeclaration);
|
|
8
7
|
export const ClassField = stc(base.ClassField);
|
|
9
8
|
export const ClassMember = stc(base.ClassMember);
|
|
@@ -19,6 +18,7 @@ export const ImportStatements = stc(base.ImportStatements);
|
|
|
19
18
|
export const InterfaceDeclaration = stc(base.InterfaceDeclaration);
|
|
20
19
|
export const InterfaceExpression = stc(base.InterfaceExpression);
|
|
21
20
|
export const InterfaceMember = stc(base.InterfaceMember);
|
|
21
|
+
export const MemberchainExpression = stc(base.MemberChainExpression);
|
|
22
22
|
export const ObjectExpression = stc(base.ObjectExpression);
|
|
23
23
|
export const ObjectProperty = stc(base.ObjectProperty);
|
|
24
24
|
export const PackageDirectory = stc(base.PackageDirectory);
|
package/src/symbols/reference.ts
CHANGED
|
@@ -53,10 +53,13 @@ export function ref(refkey: Refkey): () => string {
|
|
|
53
53
|
|
|
54
54
|
// find public dependency
|
|
55
55
|
for (const module of sourcePackage.exportedSymbols.values()) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
for (const refkey of importSymbol.refkeys) {
|
|
57
|
+
if (module.exportedSymbols.has(refkey)) {
|
|
58
|
+
localSymbol = untrack(() =>
|
|
59
|
+
sourceFile!.scope.addImport(importSymbol, module),
|
|
60
|
+
);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
65
|
|
|
@@ -26,7 +26,8 @@ export interface TSOutputSymbol extends OutputSymbol {
|
|
|
26
26
|
|
|
27
27
|
export interface createTsSymbolOptions {
|
|
28
28
|
name: string;
|
|
29
|
-
refkey
|
|
29
|
+
refkey?: Refkey;
|
|
30
|
+
refkeys?: Refkey[];
|
|
30
31
|
binder?: Binder;
|
|
31
32
|
scope?: TSOutputScope;
|
|
32
33
|
export?: boolean;
|
|
@@ -49,6 +50,7 @@ export function createTSSymbol(options: createTsSymbolOptions): TSOutputSymbol {
|
|
|
49
50
|
name: options.name,
|
|
50
51
|
scope,
|
|
51
52
|
refkey: options.refkey,
|
|
53
|
+
refkeys: options.refkeys,
|
|
52
54
|
export: !!options.export,
|
|
53
55
|
default: !!options.default,
|
|
54
56
|
flags: options.flags ?? OutputSymbolFlags.None,
|
|
@@ -56,7 +58,9 @@ export function createTSSymbol(options: createTsSymbolOptions): TSOutputSymbol {
|
|
|
56
58
|
});
|
|
57
59
|
|
|
58
60
|
if (options.export && scope.kind === "module") {
|
|
59
|
-
|
|
61
|
+
for (const refkey of sym.refkeys) {
|
|
62
|
+
scope.exportedSymbols.set(refkey, sym);
|
|
63
|
+
}
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
return sym;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { Binder, OutputScope, Refkey } from "@alloy-js/core";
|
|
2
|
-
import {
|
|
3
|
-
ExportConditions,
|
|
4
|
-
PackageExports,
|
|
5
|
-
} from "../components/PackageJson.jsx";
|
|
6
2
|
import { modulePath } from "../utils.js";
|
|
7
3
|
import { TSModuleScope } from "./ts-module-scope.js";
|
|
8
4
|
|
|
@@ -31,20 +27,6 @@ export interface TSPackageScope extends OutputScope {
|
|
|
31
27
|
*/
|
|
32
28
|
dependencies: Set<TSPackageScope>;
|
|
33
29
|
|
|
34
|
-
/**
|
|
35
|
-
* Fixed dependencies of this package. Only use this for packages in which you
|
|
36
|
-
* do not intend to reference via the `Reference` component. Symbols from raw
|
|
37
|
-
* dependencies cannot be auto imported.
|
|
38
|
-
*/
|
|
39
|
-
rawDependencies: Map<string, string>;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Fixed exports of this package. Only use this for exports which you want to
|
|
43
|
-
* add manually to the package. Otherwise use the `export` prop on
|
|
44
|
-
* `SourceFile` to add an export.
|
|
45
|
-
*/
|
|
46
|
-
rawExports: PackageExports;
|
|
47
|
-
|
|
48
30
|
/**
|
|
49
31
|
* All of the modules contained within the package. These modules may or may not
|
|
50
32
|
* be exported.
|
|
@@ -57,9 +39,7 @@ export interface TSPackageScope extends OutputScope {
|
|
|
57
39
|
builtin?: boolean;
|
|
58
40
|
|
|
59
41
|
addExport(publicPath: string, localModule: TSModuleScope): void;
|
|
60
|
-
addRawExport(publicPath: string, exportPath: string | ExportConditions): void;
|
|
61
42
|
addDependency(pkg: TSPackageScope): void;
|
|
62
|
-
addRawDependency(packageName: string, version: string): void;
|
|
63
43
|
addModule(module: TSModuleScope): void;
|
|
64
44
|
findExportedSymbol(refkey: Refkey): [string, TSModuleScope] | null;
|
|
65
45
|
}
|
|
@@ -78,8 +58,6 @@ export function createTSPackageScope(
|
|
|
78
58
|
parent,
|
|
79
59
|
exportedSymbols: new Map(),
|
|
80
60
|
dependencies: new Set(),
|
|
81
|
-
rawDependencies: new Map(),
|
|
82
|
-
rawExports: {},
|
|
83
61
|
modules: new Set(),
|
|
84
62
|
version,
|
|
85
63
|
path: path,
|
|
@@ -90,12 +68,6 @@ export function createTSPackageScope(
|
|
|
90
68
|
addExport(publicPath, module) {
|
|
91
69
|
this.exportedSymbols.set(modulePath(publicPath), module);
|
|
92
70
|
},
|
|
93
|
-
addRawDependency(packageName, version) {
|
|
94
|
-
this.rawDependencies.set(packageName, version);
|
|
95
|
-
},
|
|
96
|
-
addRawExport(localPath, exportPath) {
|
|
97
|
-
this.rawExports[localPath] = exportPath;
|
|
98
|
-
},
|
|
99
71
|
addModule(module) {
|
|
100
72
|
this.modules.add(module);
|
|
101
73
|
},
|