@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.
Files changed (174) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/src/components/ArrayExpression.d.ts +1 -1
  3. package/dist/src/components/ArrayExpression.d.ts.map +1 -1
  4. package/dist/src/components/ArrayExpression.js +18 -28
  5. package/dist/src/components/ArrayExpression.js.map +1 -1
  6. package/dist/src/components/BarrelFile.d.ts.map +1 -1
  7. package/dist/src/components/BarrelFile.js +11 -9
  8. package/dist/src/components/BarrelFile.js.map +1 -1
  9. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  10. package/dist/src/components/ClassDeclaration.js +8 -9
  11. package/dist/src/components/ClassDeclaration.js.map +1 -1
  12. package/dist/src/components/CommaList.d.ts +12 -0
  13. package/dist/src/components/CommaList.d.ts.map +1 -0
  14. package/dist/src/components/CommaList.js +19 -0
  15. package/dist/src/components/CommaList.js.map +1 -0
  16. package/dist/src/components/Declaration.d.ts +4 -0
  17. package/dist/src/components/Declaration.d.ts.map +1 -1
  18. package/dist/src/components/Declaration.js +3 -2
  19. package/dist/src/components/Declaration.js.map +1 -1
  20. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  21. package/dist/src/components/EnumDeclaration.js +21 -18
  22. package/dist/src/components/EnumDeclaration.js.map +1 -1
  23. package/dist/src/components/EnumMember.d.ts.map +1 -1
  24. package/dist/src/components/EnumMember.js.map +1 -1
  25. package/dist/src/components/ExportStatement.d.ts.map +1 -1
  26. package/dist/src/components/ExportStatement.js +3 -1
  27. package/dist/src/components/ExportStatement.js.map +1 -1
  28. package/dist/src/components/FunctionCallExpression.d.ts +2 -2
  29. package/dist/src/components/FunctionCallExpression.d.ts.map +1 -1
  30. package/dist/src/components/FunctionCallExpression.js +26 -9
  31. package/dist/src/components/FunctionCallExpression.js.map +1 -1
  32. package/dist/src/components/FunctionDeclaration.d.ts +10 -2
  33. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  34. package/dist/src/components/FunctionDeclaration.js +136 -33
  35. package/dist/src/components/FunctionDeclaration.js.map +1 -1
  36. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  37. package/dist/src/components/ImportStatement.js +25 -31
  38. package/dist/src/components/ImportStatement.js.map +1 -1
  39. package/dist/src/components/Interface.d.ts +1 -1
  40. package/dist/src/components/Interface.d.ts.map +1 -1
  41. package/dist/src/components/Interface.js +5 -5
  42. package/dist/src/components/Interface.js.map +1 -1
  43. package/dist/src/components/JSDoc.d.ts +10 -0
  44. package/dist/src/components/JSDoc.d.ts.map +1 -0
  45. package/dist/src/components/JSDoc.js +24 -0
  46. package/dist/src/components/JSDoc.js.map +1 -0
  47. package/dist/src/components/JSDocComment.d.ts +11 -0
  48. package/dist/src/components/JSDocComment.d.ts.map +1 -0
  49. package/dist/src/components/JSDocComment.js +16 -0
  50. package/dist/src/components/JSDocComment.js.map +1 -0
  51. package/dist/src/components/JSDocExample.d.ts +12 -0
  52. package/dist/src/components/JSDocExample.d.ts.map +1 -0
  53. package/dist/src/components/JSDocExample.js +26 -0
  54. package/dist/src/components/JSDocExample.js.map +1 -0
  55. package/dist/src/components/JSDocParagraph.d.ts +10 -0
  56. package/dist/src/components/JSDocParagraph.d.ts.map +1 -0
  57. package/dist/src/components/JSDocParagraph.js +23 -0
  58. package/dist/src/components/JSDocParagraph.js.map +1 -0
  59. package/dist/src/components/MemberChainExpression.d.ts +11 -0
  60. package/dist/src/components/MemberChainExpression.d.ts.map +1 -0
  61. package/dist/src/components/MemberChainExpression.js +100 -0
  62. package/dist/src/components/MemberChainExpression.js.map +1 -0
  63. package/dist/src/components/ObjectExpression.d.ts +1 -1
  64. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  65. package/dist/src/components/ObjectExpression.js +45 -42
  66. package/dist/src/components/ObjectExpression.js.map +1 -1
  67. package/dist/src/components/PackageDirectory.d.ts +1 -3
  68. package/dist/src/components/PackageDirectory.d.ts.map +1 -1
  69. package/dist/src/components/PackageDirectory.js +9 -16
  70. package/dist/src/components/PackageDirectory.js.map +1 -1
  71. package/dist/src/components/PackageJson.d.ts +39 -0
  72. package/dist/src/components/PackageJson.d.ts.map +1 -1
  73. package/dist/src/components/PackageJson.js +30 -12
  74. package/dist/src/components/PackageJson.js.map +1 -1
  75. package/dist/src/components/Reference.js +1 -1
  76. package/dist/src/components/Reference.js.map +1 -1
  77. package/dist/src/components/SourceFile.d.ts.map +1 -1
  78. package/dist/src/components/SourceFile.js +13 -6
  79. package/dist/src/components/SourceFile.js.map +1 -1
  80. package/dist/src/components/TsConfigJson.d.ts.map +1 -1
  81. package/dist/src/components/TsConfigJson.js.map +1 -1
  82. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  83. package/dist/src/components/TypeDeclaration.js.map +1 -1
  84. package/dist/src/components/ValueExpression.d.ts.map +1 -1
  85. package/dist/src/components/ValueExpression.js.map +1 -1
  86. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  87. package/dist/src/components/VarDeclaration.js +5 -4
  88. package/dist/src/components/VarDeclaration.js.map +1 -1
  89. package/dist/src/components/index.d.ts +2 -1
  90. package/dist/src/components/index.d.ts.map +1 -1
  91. package/dist/src/components/index.js +2 -1
  92. package/dist/src/components/index.js.map +1 -1
  93. package/dist/src/components/stc/index.d.ts +21 -21
  94. package/dist/src/components/stc/index.d.ts.map +1 -1
  95. package/dist/src/components/stc/index.js +1 -1
  96. package/dist/src/components/stc/index.js.map +1 -1
  97. package/dist/src/symbols/reference.d.ts.map +1 -1
  98. package/dist/src/symbols/reference.js +5 -2
  99. package/dist/src/symbols/reference.js.map +1 -1
  100. package/dist/src/symbols/ts-output-symbol.d.ts +2 -1
  101. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  102. package/dist/src/symbols/ts-output-symbol.js +4 -1
  103. package/dist/src/symbols/ts-output-symbol.js.map +1 -1
  104. package/dist/src/symbols/ts-package-scope.d.ts +0 -15
  105. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
  106. package/dist/src/symbols/ts-package-scope.js +0 -8
  107. package/dist/src/symbols/ts-package-scope.js.map +1 -1
  108. package/dist/test/imports.test.d.ts.map +1 -1
  109. package/dist/test/jsdoc.test.d.ts +2 -0
  110. package/dist/test/jsdoc.test.d.ts.map +1 -0
  111. package/dist/test/member-chain.test.d.ts +2 -0
  112. package/dist/test/member-chain.test.d.ts.map +1 -0
  113. package/dist/test/utils.d.ts +2 -2
  114. package/dist/test/utils.d.ts.map +1 -1
  115. package/dist/test/values.test.d.ts.map +1 -1
  116. package/dist/tsconfig.tsbuildinfo +1 -1
  117. package/package.json +3 -5
  118. package/src/components/ArrayExpression.tsx +22 -32
  119. package/src/components/BarrelFile.tsx +7 -13
  120. package/src/components/ClassDeclaration.tsx +33 -28
  121. package/src/components/CommaList.tsx +23 -0
  122. package/src/components/Declaration.tsx +14 -5
  123. package/src/components/EnumDeclaration.tsx +23 -16
  124. package/src/components/EnumMember.tsx +7 -4
  125. package/src/components/ExportStatement.tsx +9 -2
  126. package/src/components/FunctionCallExpression.tsx +18 -9
  127. package/src/components/FunctionDeclaration.tsx +173 -56
  128. package/src/components/ImportStatement.tsx +6 -9
  129. package/src/components/Interface.tsx +20 -13
  130. package/src/components/JSDoc.tsx +28 -0
  131. package/src/components/JSDocComment.tsx +23 -0
  132. package/src/components/JSDocExample.tsx +30 -0
  133. package/src/components/JSDocParagraph.tsx +35 -0
  134. package/src/components/MemberChainExpression.tsx +91 -0
  135. package/src/components/ObjectExpression.tsx +53 -48
  136. package/src/components/PackageDirectory.tsx +22 -30
  137. package/src/components/PackageJson.tsx +91 -29
  138. package/src/components/SourceFile.tsx +15 -8
  139. package/src/components/TsConfigJson.tsx +5 -3
  140. package/src/components/TypeDeclaration.tsx +5 -3
  141. package/src/components/ValueExpression.tsx +3 -1
  142. package/src/components/VarDeclaration.tsx +13 -7
  143. package/src/components/index.ts +2 -1
  144. package/src/components/stc/index.ts +1 -1
  145. package/src/symbols/reference.ts +7 -4
  146. package/src/symbols/ts-output-symbol.ts +6 -2
  147. package/src/symbols/ts-package-scope.ts +0 -28
  148. package/temp/api.json +802 -395
  149. package/test/array.test.tsx +40 -7
  150. package/test/basic.test.tsx +26 -21
  151. package/test/class.test.tsx +65 -53
  152. package/test/enum.test.tsx +18 -13
  153. package/test/externals.test.tsx +6 -7
  154. package/test/function-call-expression.test.tsx +39 -17
  155. package/test/function-declaration.test.tsx +96 -78
  156. package/test/imports.test.tsx +115 -75
  157. package/test/interface.test.tsx +32 -22
  158. package/test/jsdoc.test.tsx +154 -0
  159. package/test/member-chain.test.tsx +124 -0
  160. package/test/name-policy.test.tsx +33 -26
  161. package/test/package-external.test.tsx +106 -7
  162. package/test/package.test.tsx +57 -5
  163. package/test/reference.test.tsx +2 -6
  164. package/test/utils.tsx +3 -1
  165. package/test/value-expression.test.tsx +2 -6
  166. package/test/values.test.tsx +67 -73
  167. package/test/var-declaration.test.tsx +11 -5
  168. package/test/vitest.d.ts +6 -1
  169. package/tsconfig.json +8 -1
  170. package/dist/src/components/Block.d.ts +0 -6
  171. package/dist/src/components/Block.d.ts.map +0 -1
  172. package/dist/src/components/Block.js +0 -11
  173. package/dist/src/components/Block.js.map +0 -1
  174. 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
- mapJoin,
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 elements = computed(() => {
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
- const elements = mapJoin(
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 memo(() => {
62
- if (elements.value.length === 0) {
63
- return "{}";
64
- } else {
65
- if (assignmentSymbol) {
66
- return <>
67
- {"{"}
68
- <MemberScope owner={assignmentSymbol}>
69
- {elements.value}
70
- </MemberScope>
71
- {"}"}
72
- </>;
73
- } else {
74
- return <>
75
- {"{"}
76
- {elements.value}
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 = sym ?
123
- createAssignmentContext(sym)
124
- : undefined;
125
- return <>
126
- {sym ? sym.name : name}: <AssignmentContext.Provider value={assignmentContext}>
127
- {value}
128
- </AssignmentContext.Provider>
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
- if (props.exports) {
58
- if (typeof props.exports === "string") {
59
- packageContext.scope.addRawExport(".", props.exports);
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
- if (props.dependencies) {
68
- for (const dep of Object.entries(props.dependencies)) {
69
- packageContext.scope.addRawDependency(dep[0], dep[1]);
70
- }
71
- }
56
+ const [_, pkgJsonProps] = splitProps(props, [
57
+ "tsConfig",
58
+ "children",
59
+ "path",
60
+ "devDependencies",
61
+ ]);
72
62
 
73
- return <SourceDirectory path={props.path ?? "."}>
74
- <PackageContext.Provider value={packageContext}>
75
- <Scope value={packageContext.scope}>
76
- <PackageJsonFile {...props} />
77
- <TSConfigJson {... props.tsConfig} />
78
- {props.children}
79
- </Scope>
80
- </PackageContext.Provider>
81
- </SourceDirectory>;
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: Object.fromEntries([
37
- ...pkg.scope.rawDependencies.entries(),
38
- ...Array.from(pkg.scope.dependencies).map((dependency) => [
39
- dependency.name,
40
- dependency.version,
41
- ]),
42
- ]),
43
- devDependencies: {
44
- ...props.devDependencies,
45
- typescript: "^5.5.2",
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
- const exportsEntries: [string, ExportPath][] = [];
52
- for (const [publicPath, module] of pkg.scope.exportedSymbols) {
53
- exportsEntries.push([
54
- publicPath,
55
- modulePath(pkg.outFileMapper.value(module.name)),
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
- pkgJson.exports = exportsEntries.length === 0 ?
60
- undefined
61
- : Object.fromEntries(exportsEntries);
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 <SourceFile path="package.json" filetype="json">
67
- {jsonContent}
68
- </SourceFile>;
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 <CoreSourceFile path={props.path} filetype="typescript" reference={Reference}>
62
- {scope.importedModules.size > 0 ? (
63
- <>
64
- <ImportStatements records={scope.importedModules} />
65
- {"\n"}
66
- </>
67
- ) : undefined}<SourceFileContext.Provider value={sfContext}>
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 <SourceFile path="tsconfig.json" filetype="json">
60
- {jsonContent}
61
- </SourceFile>;
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 <Declaration {...props} nameKind="type">
8
- type <Name /> = {props.children};
9
- </Declaration>;
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 <ObjectExpression jsValue={jsValue as Record<string, unknown>} />;
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 ?? refkey(name),
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 <CoreDeclaration symbol={sym}>
38
- {props.export ? "export " : ""}{props.default ? "default " : ""}{keyword} <Name />{type} = <AssignmentContext.Provider value={assignmentContext}>
39
- {props.value ?? props.children};
40
- </AssignmentContext.Provider>
41
- </CoreDeclaration>;
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
  }
@@ -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);
@@ -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
- if (module.exportedSymbols.has(importSymbol.refkey)) {
57
- localSymbol = untrack(() =>
58
- sourceFile!.scope.addImport(importSymbol, module),
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: 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
- scope.exportedSymbols.set(sym.refkey, sym);
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
  },