@alloy-js/typescript 0.15.0 → 0.17.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 (136) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/src/builtins/node.d.ts +9 -41
  3. package/dist/src/builtins/node.d.ts.map +1 -1
  4. package/dist/src/components/ArrowFunction.d.ts +3 -3
  5. package/dist/src/components/BarrelFile.d.ts +1 -1
  6. package/dist/src/components/BarrelFile.d.ts.map +1 -1
  7. package/dist/src/components/BlockScope.d.ts +1 -1
  8. package/dist/src/components/BlockScope.d.ts.map +1 -1
  9. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  10. package/dist/src/components/ClassDeclaration.js +5 -7
  11. package/dist/src/components/Declaration.d.ts.map +1 -1
  12. package/dist/src/components/Declaration.js +3 -4
  13. package/dist/src/components/EnumDeclaration.d.ts +1 -1
  14. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  15. package/dist/src/components/EnumDeclaration.js +3 -4
  16. package/dist/src/components/EnumMember.d.ts.map +1 -1
  17. package/dist/src/components/EnumMember.js +3 -4
  18. package/dist/src/components/FunctionBase.d.ts +4 -4
  19. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  20. package/dist/src/components/FunctionBase.js +15 -10
  21. package/dist/src/components/FunctionDeclaration.d.ts +3 -3
  22. package/dist/src/components/FunctionExpression.d.ts +3 -3
  23. package/dist/src/components/FunctionType.d.ts +2 -2
  24. package/dist/src/components/ImportStatement.d.ts +1 -1
  25. package/dist/src/components/ImportStatement.d.ts.map +1 -1
  26. package/dist/src/components/Interface.js +1 -1
  27. package/dist/src/components/InterfaceMethod.d.ts +2 -2
  28. package/dist/src/components/MemberDeclaration.d.ts +1 -1
  29. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  30. package/dist/src/components/MemberDeclaration.js +4 -4
  31. package/dist/src/components/MemberExpression.d.ts +27 -5
  32. package/dist/src/components/MemberExpression.d.ts.map +1 -1
  33. package/dist/src/components/MemberExpression.js +327 -89
  34. package/dist/src/components/NewExpression.d.ts +5 -0
  35. package/dist/src/components/NewExpression.d.ts.map +1 -0
  36. package/dist/src/components/NewExpression.js +12 -0
  37. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  38. package/dist/src/components/ObjectExpression.js +14 -15
  39. package/dist/src/components/PackageDirectory.d.ts.map +1 -1
  40. package/dist/src/components/PackageDirectory.js +3 -3
  41. package/dist/src/components/PackageJson.d.ts +1 -1
  42. package/dist/src/components/PackageJson.d.ts.map +1 -1
  43. package/dist/src/components/PropertyName.d.ts +1 -1
  44. package/dist/src/components/PropertyName.d.ts.map +1 -1
  45. package/dist/src/components/Reference.d.ts +1 -1
  46. package/dist/src/components/Reference.d.ts.map +1 -1
  47. package/dist/src/components/Reference.js +5 -1
  48. package/dist/src/components/SourceFile.d.ts.map +1 -1
  49. package/dist/src/components/SourceFile.js +3 -3
  50. package/dist/src/components/TsConfigJson.d.ts +1 -1
  51. package/dist/src/components/TsConfigJson.d.ts.map +1 -1
  52. package/dist/src/components/TypeDeclaration.d.ts +1 -1
  53. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  54. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  55. package/dist/src/components/VarDeclaration.js +30 -10
  56. package/dist/src/components/index.d.ts +1 -1
  57. package/dist/src/components/index.d.ts.map +1 -1
  58. package/dist/src/components/index.js +1 -1
  59. package/dist/src/components/stc/index.d.ts +45 -44
  60. package/dist/src/components/stc/index.d.ts.map +1 -1
  61. package/dist/src/components/stc/index.js +46 -45
  62. package/dist/src/create-package.d.ts +62 -18
  63. package/dist/src/create-package.d.ts.map +1 -1
  64. package/dist/src/create-package.js +153 -15
  65. package/dist/src/source-directory-data.d.ts.map +1 -1
  66. package/dist/src/source-directory-data.js +2 -2
  67. package/dist/src/symbols/reference.d.ts +2 -1
  68. package/dist/src/symbols/reference.d.ts.map +1 -1
  69. package/dist/src/symbols/reference.js +3 -4
  70. package/dist/src/symbols/scopes.d.ts +1 -4
  71. package/dist/src/symbols/scopes.d.ts.map +1 -1
  72. package/dist/src/symbols/ts-member-scope.d.ts +4 -6
  73. package/dist/src/symbols/ts-member-scope.d.ts.map +1 -1
  74. package/dist/src/symbols/ts-member-scope.js +8 -10
  75. package/dist/src/symbols/ts-module-scope.d.ts +8 -11
  76. package/dist/src/symbols/ts-module-scope.d.ts.map +1 -1
  77. package/dist/src/symbols/ts-module-scope.js +47 -40
  78. package/dist/src/symbols/ts-output-symbol.d.ts +23 -16
  79. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  80. package/dist/src/symbols/ts-output-symbol.js +88 -27
  81. package/dist/src/symbols/ts-package-scope.d.ts +18 -14
  82. package/dist/src/symbols/ts-package-scope.d.ts.map +1 -1
  83. package/dist/src/symbols/ts-package-scope.js +78 -27
  84. package/dist/test/class.test.js +2 -1
  85. package/dist/test/externals.test.js +87 -2
  86. package/dist/test/function-declaration.test.js +74 -3
  87. package/dist/test/member-expression.test.js +391 -5
  88. package/dist/test/new-expression.test.d.ts +2 -0
  89. package/dist/test/new-expression.test.d.ts.map +1 -0
  90. package/dist/test/new-expression.test.js +62 -0
  91. package/dist/test/var-declaration.test.d.ts.map +1 -1
  92. package/dist/test/var-declaration.test.js +145 -2
  93. package/dist/tsconfig.tsbuildinfo +1 -1
  94. package/package.json +4 -4
  95. package/src/components/ClassDeclaration.tsx +5 -7
  96. package/src/components/Declaration.tsx +3 -8
  97. package/src/components/EnumDeclaration.tsx +3 -4
  98. package/src/components/EnumMember.tsx +3 -4
  99. package/src/components/FunctionBase.tsx +25 -18
  100. package/src/components/ImportStatement.tsx +0 -1
  101. package/src/components/Interface.tsx +1 -1
  102. package/src/components/MemberDeclaration.tsx +5 -8
  103. package/src/components/MemberExpression.tsx +416 -103
  104. package/src/components/NewExpression.tsx +25 -0
  105. package/src/components/ObjectExpression.tsx +18 -16
  106. package/src/components/PackageDirectory.tsx +2 -10
  107. package/src/components/Reference.tsx +4 -2
  108. package/src/components/SourceFile.tsx +2 -5
  109. package/src/components/VarDeclaration.tsx +34 -11
  110. package/src/components/index.ts +1 -1
  111. package/src/components/stc/index.ts +46 -45
  112. package/src/create-package.ts +274 -35
  113. package/src/source-directory-data.ts +2 -2
  114. package/src/symbols/reference.ts +10 -5
  115. package/src/symbols/scopes.ts +1 -6
  116. package/src/symbols/ts-member-scope.ts +8 -23
  117. package/src/symbols/ts-module-scope.ts +58 -62
  118. package/src/symbols/ts-output-symbol.ts +108 -50
  119. package/src/symbols/ts-package-scope.ts +71 -53
  120. package/temp/api.json +1665 -1733
  121. package/test/class.test.tsx +2 -1
  122. package/test/externals.test.tsx +99 -1
  123. package/test/function-declaration.test.tsx +75 -2
  124. package/test/member-expression.test.tsx +312 -8
  125. package/test/new-expression.test.tsx +42 -0
  126. package/test/values.test.tsx +1 -0
  127. package/test/var-declaration.test.tsx +101 -1
  128. package/tsdoc-metadata.json +1 -1
  129. package/dist/src/components/MemberChainExpression.d.ts +0 -11
  130. package/dist/src/components/MemberChainExpression.d.ts.map +0 -1
  131. package/dist/src/components/MemberChainExpression.js +0 -98
  132. package/dist/test/member-chain.test.d.ts +0 -2
  133. package/dist/test/member-chain.test.d.ts.map +0 -1
  134. package/dist/test/member-chain.test.js +0 -141
  135. package/src/components/MemberChainExpression.tsx +0 -91
  136. package/test/member-chain.test.tsx +0 -124
@@ -15,7 +15,7 @@ import {
15
15
  import { usePrivateScope } from "../context/private-scope.js";
16
16
  import { useTSNamePolicy } from "../name-policy.js";
17
17
  import { TSOutputScope } from "../symbols/scopes.js";
18
- import { createTSSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
18
+ import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
19
19
  import { getCallSignatureProps } from "../utils.js";
20
20
  import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
21
21
  import { BaseDeclarationProps, Declaration } from "./Declaration.jsx";
@@ -65,9 +65,8 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
65
65
  const namePolicy = useTSNamePolicy();
66
66
  const extendsPart = props.extends && <> extends {props.extends}</>;
67
67
 
68
- const sym = createTSSymbol({
69
- name: namePolicy.getName(props.name!, "class"),
70
- refkey: props.refkey,
68
+ const sym = new TSOutputSymbol(namePolicy.getName(props.name!, "class"), {
69
+ refkeys: props.refkey,
71
70
  export: props.export,
72
71
  default: props.default,
73
72
  flags:
@@ -137,10 +136,9 @@ export function ClassMember(props: ClassMemberProps) {
137
136
  tsFlags |= TSSymbolFlags.Nullish;
138
137
  }
139
138
 
140
- const sym = createTSSymbol({
141
- name,
139
+ const sym = new TSOutputSymbol(name, {
142
140
  scope,
143
- refkey: props.refkey,
141
+ refkeys: props.refkey,
144
142
  flags,
145
143
  tsFlags,
146
144
  });
@@ -6,11 +6,7 @@ import {
6
6
  Refkey,
7
7
  } from "@alloy-js/core";
8
8
  import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
9
- import {
10
- createTSSymbol,
11
- TSOutputSymbol,
12
- TSSymbolFlags,
13
- } from "../symbols/index.js";
9
+ import { TSOutputSymbol, TSSymbolFlags } from "../symbols/index.js";
14
10
 
15
11
  // imports for documentation
16
12
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -112,9 +108,8 @@ export function Declaration(props: DeclarationProps) {
112
108
  tsFlags |= TSSymbolFlags.TypeSymbol;
113
109
  }
114
110
 
115
- sym = createTSSymbol({
116
- name: namePolicy.getName(props.name!, props.nameKind!),
117
- refkey: props.refkey,
111
+ sym = new TSOutputSymbol(namePolicy.getName(props.name!, props.nameKind!), {
112
+ refkeys: props.refkey,
118
113
  export: props.export,
119
114
  default: props.default,
120
115
  flags: props.flags,
@@ -10,7 +10,7 @@ import {
10
10
  useBinder,
11
11
  } from "@alloy-js/core";
12
12
  import { useTSNamePolicy } from "../name-policy.js";
13
- import { createTSSymbol, useTSScope } from "../symbols/index.js";
13
+ import { TSOutputSymbol, useTSScope } from "../symbols/index.js";
14
14
  import { BaseDeclarationProps } from "./Declaration.js";
15
15
  import { EnumMember } from "./EnumMember.jsx";
16
16
  import { JSDoc } from "./JSDoc.jsx";
@@ -28,11 +28,10 @@ export function EnumDeclaration(props: EnumDeclarationProps) {
28
28
  const name = useTSNamePolicy().getName(props.name, "enum");
29
29
  const binder = useBinder();
30
30
  const scope = useTSScope();
31
- const sym = createTSSymbol({
31
+ const sym = new TSOutputSymbol(name, {
32
32
  binder,
33
33
  scope,
34
- name: name,
35
- refkey: props.refkey,
34
+ refkeys: props.refkey,
36
35
  default: props.default,
37
36
  export: props.export,
38
37
  flags: OutputSymbolFlags.StaticMemberContainer,
@@ -1,6 +1,6 @@
1
1
  import { Children, OutputSymbolFlags, Refkey, Show } from "@alloy-js/core";
2
2
  import { useTSNamePolicy } from "../name-policy.js";
3
- import { createTSSymbol, TSOutputSymbol } from "../symbols/ts-output-symbol.js";
3
+ import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
4
4
  import { JSDoc } from "./JSDoc.jsx";
5
5
  import { PropertyName } from "./PropertyName.jsx";
6
6
  import { ValueExpression } from "./ValueExpression.jsx";
@@ -49,9 +49,8 @@ export function EnumMember(props: EnumMemberProps) {
49
49
  const name = namer.getName(props.name, "enum-member");
50
50
  let sym: TSOutputSymbol | undefined = undefined;
51
51
  if (props.refkey) {
52
- sym = createTSSymbol({
53
- name,
54
- refkey: props.refkey,
52
+ sym = new TSOutputSymbol(name, {
53
+ refkeys: props.refkey,
55
54
  flags: OutputSymbolFlags.StaticMember,
56
55
  metadata: props.metadata,
57
56
  });
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Block,
3
3
  code,
4
+ createSymbolSlot,
4
5
  For,
5
6
  Indent,
6
7
  onCleanup,
@@ -14,11 +15,7 @@ import type {
14
15
  ParameterDescriptor,
15
16
  } from "../parameter-descriptor.js";
16
17
  import { TypeParameterDescriptor } from "../parameter-descriptor.js";
17
- import {
18
- createTSSymbol,
19
- TSOutputSymbol,
20
- TSSymbolFlags,
21
- } from "../symbols/index.js";
18
+ import { TSOutputSymbol, TSSymbolFlags } from "../symbols/index.js";
22
19
  import { TypeRefContext } from "./TypeRefContext.jsx";
23
20
 
24
21
  const functionParametersTag = Symbol();
@@ -120,6 +117,10 @@ export const FunctionTypeParameters = taggedComponent(
120
117
  );
121
118
 
122
119
  function parameter(param: DeclaredParameterDescriptor) {
120
+ const SymbolSlot = createSymbolSlot();
121
+
122
+ SymbolSlot.instantiateInto(param.symbol);
123
+
123
124
  return (
124
125
  <group>
125
126
  <Show when={param.rest}>...</Show>
@@ -127,7 +128,10 @@ function parameter(param: DeclaredParameterDescriptor) {
127
128
  <Show when={!!param.optional}>?</Show>
128
129
  <Show when={!!param.type}>
129
130
  <indent>
130
- : <TypeRefContext>{param.type}</TypeRefContext>
131
+ :{" "}
132
+ <SymbolSlot>
133
+ <TypeRefContext>{param.type}</TypeRefContext>
134
+ </SymbolSlot>
131
135
  </indent>
132
136
  </Show>
133
137
  </group>
@@ -178,11 +182,12 @@ function normalizeAndDeclareParameters(
178
182
  }
179
183
  if (typeof parameters[0] === "string") {
180
184
  return (parameters as string[]).map((paramName) => {
181
- const symbol = createTSSymbol({
182
- name: namePolicy.getName(
183
- paramName,
184
- flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
185
- ),
185
+ const name = namePolicy.getName(
186
+ paramName,
187
+ flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
188
+ );
189
+
190
+ const symbol = new TSOutputSymbol(name, {
186
191
  tsFlags: flags,
187
192
  });
188
193
 
@@ -195,15 +200,17 @@ function normalizeAndDeclareParameters(
195
200
  TSSymbolFlags.Nullish
196
201
  : TSSymbolFlags.None;
197
202
 
198
- const symbol = createTSSymbol({
199
- name: namePolicy.getName(
203
+ const symbol = new TSOutputSymbol(
204
+ namePolicy.getName(
200
205
  param.name,
201
206
  flags & TSSymbolFlags.TypeSymbol ? "type" : "parameter",
202
207
  ),
203
- refkey: param.refkey,
204
- tsFlags: flags | nullishFlag,
205
- metadata: param.metadata,
206
- });
208
+ {
209
+ refkeys: param.refkey,
210
+ tsFlags: flags | nullishFlag,
211
+ metadata: param.metadata,
212
+ },
213
+ );
207
214
 
208
215
  return {
209
216
  ...param,
@@ -236,7 +243,7 @@ export const TypeParameters = taggedComponent(
236
243
 
237
244
  onCleanup(() => {
238
245
  for (const param of typeParameters) {
239
- param.symbol.binder.deleteSymbol(param.symbol);
246
+ param.symbol.delete();
240
247
  }
241
248
  });
242
249
 
@@ -21,7 +21,6 @@ export interface ImportStatementsProps {
21
21
 
22
22
  export function ImportStatements(props: ImportStatementsProps) {
23
23
  const pkg = usePackage();
24
-
25
24
  const imports = computed(() =>
26
25
  [...props.records].sort(([a], [b]) => {
27
26
  return a.name.localeCompare(b.name);
@@ -61,7 +61,7 @@ export const InterfaceExpression = ensureTypeRefContext(
61
61
  const parentMemberSym = useMemberDeclaration();
62
62
 
63
63
  if (parentMemberSym) {
64
- parentMemberSym.binder.addStaticMembersToSymbol(parentMemberSym);
64
+ parentMemberSym.flags |= OutputSymbolFlags.StaticMemberContainer;
65
65
  }
66
66
  return (
67
67
  <group>
@@ -4,11 +4,7 @@ import {
4
4
  OutputSymbolFlags,
5
5
  } from "@alloy-js/core";
6
6
  import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
7
- import {
8
- createTSSymbol,
9
- TSOutputSymbol,
10
- TSSymbolFlags,
11
- } from "../symbols/index.js";
7
+ import { TSOutputSymbol, TSSymbolFlags } from "../symbols/index.js";
12
8
 
13
9
  export interface MemberDeclarationProps
14
10
  extends Omit<MemberDeclarationPropsWithInfo, "name"> {
@@ -61,9 +57,10 @@ export function MemberDeclaration(props: Readonly<MemberDeclarationProps>) {
61
57
  tsFlags |= TSSymbolFlags.TypeSymbol;
62
58
  }
63
59
 
64
- sym = createTSSymbol({
65
- name: props.exactName ?? namePolicy.getName(props.name!, props.nameKind!),
66
- refkey: props.refkey,
60
+ const name =
61
+ props.exactName ?? namePolicy.getName(props.name!, props.nameKind!);
62
+ sym = new TSOutputSymbol(name, {
63
+ refkeys: props.refkey,
67
64
  flags: props.flags,
68
65
  tsFlags,
69
66
  metadata: props.metadata,