@alloy-js/typescript 0.20.0 → 0.21.0-dev.3

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 (87) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +4 -4
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  3. package/dist/src/components/ClassDeclaration.js +6 -11
  4. package/dist/src/components/ClassDeclaration.js.map +1 -1
  5. package/dist/src/components/Declaration.d.ts +27 -24
  6. package/dist/src/components/Declaration.d.ts.map +1 -1
  7. package/dist/src/components/Declaration.js +12 -8
  8. package/dist/src/components/Declaration.js.map +1 -1
  9. package/dist/src/components/EnumDeclaration.d.ts +2 -2
  10. package/dist/src/components/EnumDeclaration.d.ts.map +1 -1
  11. package/dist/src/components/EnumDeclaration.js +3 -3
  12. package/dist/src/components/EnumDeclaration.js.map +1 -1
  13. package/dist/src/components/EnumMember.d.ts +2 -2
  14. package/dist/src/components/EnumMember.d.ts.map +1 -1
  15. package/dist/src/components/EnumMember.js +8 -10
  16. package/dist/src/components/EnumMember.js.map +1 -1
  17. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  18. package/dist/src/components/FunctionBase.js +3 -2
  19. package/dist/src/components/FunctionBase.js.map +1 -1
  20. package/dist/src/components/FunctionDeclaration.d.ts +2 -2
  21. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  22. package/dist/src/components/FunctionDeclaration.js +0 -3
  23. package/dist/src/components/FunctionDeclaration.js.map +1 -1
  24. package/dist/src/components/Interface.d.ts +13 -8
  25. package/dist/src/components/Interface.d.ts.map +1 -1
  26. package/dist/src/components/Interface.js +46 -43
  27. package/dist/src/components/Interface.js.map +1 -1
  28. package/dist/src/components/InterfaceMethod.d.ts +2 -2
  29. package/dist/src/components/InterfaceMethod.d.ts.map +1 -1
  30. package/dist/src/components/InterfaceMethod.js +3 -8
  31. package/dist/src/components/InterfaceMethod.js.map +1 -1
  32. package/dist/src/components/MemberDeclaration.d.ts +10 -13
  33. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  34. package/dist/src/components/MemberDeclaration.js +4 -5
  35. package/dist/src/components/MemberDeclaration.js.map +1 -1
  36. package/dist/src/components/TypeDeclaration.d.ts +2 -2
  37. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  38. package/dist/src/components/TypeDeclaration.js.map +1 -1
  39. package/dist/src/components/VarDeclaration.d.ts +2 -2
  40. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  41. package/dist/src/components/VarDeclaration.js +3 -3
  42. package/dist/src/components/VarDeclaration.js.map +1 -1
  43. package/dist/src/parameter-descriptor.d.ts +3 -3
  44. package/dist/src/parameter-descriptor.d.ts.map +1 -1
  45. package/dist/src/symbols/index.d.ts +9 -9
  46. package/dist/src/symbols/index.d.ts.map +1 -1
  47. package/dist/src/symbols/index.js.map +1 -1
  48. package/dist/src/symbols/ts-output-symbol.d.ts +2 -2
  49. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  50. package/dist/src/symbols/ts-output-symbol.js.map +1 -1
  51. package/dist/test/class.test.js +29 -1
  52. package/dist/test/class.test.js.map +1 -1
  53. package/dist/test/enum.test.js +30 -1
  54. package/dist/test/enum.test.js.map +1 -1
  55. package/dist/test/function-declaration.test.js +18 -1
  56. package/dist/test/function-declaration.test.js.map +1 -1
  57. package/dist/test/interface.test.d.ts.map +1 -1
  58. package/dist/test/interface.test.js +25 -1
  59. package/dist/test/interface.test.js.map +1 -1
  60. package/dist/test/reference.test.js +2 -0
  61. package/dist/test/reference.test.js.map +1 -1
  62. package/dist/test/var-declaration.test.d.ts.map +1 -1
  63. package/dist/test/var-declaration.test.js +18 -1
  64. package/dist/test/var-declaration.test.js.map +1 -1
  65. package/dist/tsconfig.tsbuildinfo +1 -1
  66. package/package.json +6 -6
  67. package/src/components/ClassDeclaration.tsx +9 -12
  68. package/src/components/Declaration.tsx +39 -32
  69. package/src/components/EnumDeclaration.tsx +4 -4
  70. package/src/components/EnumMember.tsx +8 -13
  71. package/src/components/FunctionBase.tsx +7 -9
  72. package/src/components/FunctionDeclaration.tsx +3 -3
  73. package/src/components/Interface.tsx +57 -51
  74. package/src/components/InterfaceMethod.tsx +12 -7
  75. package/src/components/MemberDeclaration.tsx +20 -24
  76. package/src/components/TypeDeclaration.tsx +2 -2
  77. package/src/components/VarDeclaration.tsx +4 -4
  78. package/src/parameter-descriptor.ts +3 -3
  79. package/src/symbols/index.ts +12 -9
  80. package/src/symbols/ts-output-symbol.ts +2 -1
  81. package/temp/api.json +756 -508
  82. package/test/class.test.tsx +19 -1
  83. package/test/enum.test.tsx +21 -1
  84. package/test/function-declaration.test.tsx +15 -0
  85. package/test/interface.test.tsx +29 -0
  86. package/test/reference.test.tsx +2 -2
  87. package/test/var-declaration.test.tsx +17 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/typescript",
3
- "version": "0.20.0",
3
+ "version": "0.21.0-dev.3",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -14,18 +14,18 @@
14
14
  "author": "brian.terlson@microsoft.com",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
+ "@alloy-js/core": "~0.20.0 || >= 0.21.0-dev.1",
17
18
  "change-case": "^5.4.4",
18
- "pathe": "^2.0.3",
19
- "@alloy-js/core": "~0.20.0"
19
+ "pathe": "^2.0.3"
20
20
  },
21
21
  "devDependencies": {
22
+ "@alloy-js/cli": "~0.20.0 || >= 0.21.0-dev.0",
23
+ "@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.0",
22
24
  "@microsoft/api-extractor": "~7.52.8",
23
25
  "@rollup/plugin-typescript": "^12.1.2",
24
26
  "concurrently": "^9.2.0",
25
27
  "typescript": "^5.8.3",
26
- "vitest": "^3.2.4",
27
- "@alloy-js/rollup-plugin": "~0.1.0",
28
- "@alloy-js/cli": "~0.20.0"
28
+ "vitest": "^3.2.4"
29
29
  },
30
30
  "type": "module",
31
31
  "scripts": {
@@ -3,6 +3,7 @@ import {
3
3
  Children,
4
4
  MemberDeclaration,
5
5
  Name,
6
+ Namekey,
6
7
  Prose,
7
8
  Refkey,
8
9
  Show,
@@ -17,7 +18,7 @@ import {
17
18
  import { TSSymbolFlags } from "../symbols/ts-output-symbol.js";
18
19
  import { getCallSignatureProps } from "../utils.js";
19
20
  import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
20
- import { BaseDeclarationProps, Declaration } from "./Declaration.jsx";
21
+ import { CommonDeclarationProps, Declaration } from "./Declaration.jsx";
21
22
  import { JSDoc } from "./JSDoc.jsx";
22
23
  import { JSDocParams } from "./JSDocParam.jsx";
23
24
  import { LexicalScope } from "./LexicalScope.jsx";
@@ -25,7 +26,7 @@ import { MemberScope } from "./MemberScope.jsx";
25
26
  import { PropertyName } from "./PropertyName.jsx";
26
27
  import { TypeRefContext } from "./TypeRefContext.jsx";
27
28
 
28
- export interface ClassDeclarationProps extends BaseDeclarationProps {
29
+ export interface ClassDeclarationProps extends CommonDeclarationProps {
29
30
  extends?: Children;
30
31
  }
31
32
 
@@ -63,16 +64,14 @@ export interface ClassDeclarationProps extends BaseDeclarationProps {
63
64
  * ```
64
65
  */
65
66
  export function ClassDeclaration(props: ClassDeclarationProps) {
66
- const namePolicy = useTSNamePolicy();
67
- const name = namePolicy.getName(props.name!, "class");
68
-
69
67
  const extendsPart = props.extends && <> extends {props.extends}</>;
70
- const sym = createTypeAndValueSymbol(name, {
68
+ const sym = createTypeAndValueSymbol(props.name, {
71
69
  refkeys: props.refkey,
72
70
  export: props.export,
73
71
  default: props.default,
74
72
  metadata: props.metadata,
75
73
  hasInstanceMembers: true,
74
+ namePolicy: useTSNamePolicy().for("class"),
76
75
  });
77
76
 
78
77
  return (
@@ -92,7 +91,7 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
92
91
  }
93
92
 
94
93
  export interface ClassMemberProps {
95
- name: string;
94
+ name: string | Namekey;
96
95
  refkey?: Refkey;
97
96
  public?: boolean;
98
97
  private?: boolean;
@@ -105,17 +104,15 @@ export interface ClassMemberProps {
105
104
  }
106
105
 
107
106
  export function ClassMember(props: ClassMemberProps) {
108
- const namer = useTSNamePolicy();
109
- const name = namer.getName(props.name, "class-member-data");
110
-
111
107
  let tsFlags = TSSymbolFlags.None;
112
108
  if (props.nullish) {
113
109
  tsFlags |= TSSymbolFlags.Nullish;
114
110
  }
115
111
 
116
- const sym = createMemberSymbol(name, props, {
112
+ const sym = createMemberSymbol(props.name, props, {
117
113
  refkeys: props.refkey,
118
114
  tsFlags,
115
+ namePolicy: useTSNamePolicy().for("class-member-data"),
119
116
  });
120
117
 
121
118
  return (
@@ -183,7 +180,7 @@ export function ClassMethod(props: ClassMethodProps) {
183
180
  <ClassMember {...rest}>
184
181
  {props.async && "async "}
185
182
  <PropertyName />
186
- <LexicalScope name={props.name}>
183
+ <LexicalScope>
187
184
  <CallSignature {...callProps} /> <Block>{props.children}</Block>
188
185
  </LexicalScope>
189
186
  </ClassMember>
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  Children,
3
3
  Declaration as CoreDeclaration,
4
+ Namekey,
4
5
  Refkey,
5
6
  } from "@alloy-js/core";
6
7
  import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
@@ -17,29 +18,33 @@ import { TypeDeclaration } from "./TypeDeclaration.jsx";
17
18
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
19
  import { EnumDeclaration } from "./EnumDeclaration.jsx";
19
20
 
20
- export interface BaseDeclarationProps {
21
+ export interface DeclarationPropsBase {
22
+ children?: Children;
23
+
21
24
  /**
22
- * The base name of this declaration. May change depending on naming policy
23
- * and any conflicts.
25
+ * Documentation for this declaration
24
26
  */
25
- name: string;
27
+ doc?: Children;
28
+ }
26
29
 
30
+ export interface DeclarationPropsWithSymbol extends DeclarationPropsBase {
27
31
  /**
28
- * The refkey or array of refkeys for this declaration.
32
+ * The symbol to use for this declaration.
29
33
  */
30
- refkey?: Refkey | Refkey[];
34
+ symbol: TSOutputSymbol;
35
+ }
31
36
 
37
+ export interface DeclarationPropsWithInfo extends DeclarationPropsBase {
32
38
  /**
33
- * Whether to export this declaration from the module.
39
+ * The name policy kind to apply to the declaration.
34
40
  */
35
- export?: boolean;
41
+ nameKind: TypeScriptElements;
36
42
 
37
43
  /**
38
- * Whether this is the default export of the module.
44
+ * The base name of this declaration. May change depending on naming policy
45
+ * and any conflicts.
39
46
  */
40
- default?: boolean;
41
-
42
- children?: Children;
47
+ name: string | Namekey;
43
48
 
44
49
  /**
45
50
  * Whether this is a declaration of a type (e.g. interface, type alias) or a
@@ -53,28 +58,30 @@ export interface BaseDeclarationProps {
53
58
  metadata?: Record<string, unknown>;
54
59
 
55
60
  /**
56
- * Documentation for this declaration
57
- */
58
- doc?: Children;
59
- }
60
-
61
- export interface DeclarationProps extends Omit<BaseDeclarationProps, "name"> {
62
- /**
63
- * The name of this declaration.
61
+ * The refkey or array of refkeys for this declaration.
64
62
  */
65
- name?: string;
63
+ refkey?: Refkey | Refkey[];
66
64
 
67
65
  /**
68
- * The name policy kind to apply to the declaration.
66
+ * Whether to export this declaration from the module.
69
67
  */
70
- nameKind?: TypeScriptElements;
68
+ export?: boolean;
71
69
 
72
70
  /**
73
- * The symbol to use for this declaration.
71
+ * Whether this is the default export of the module.
74
72
  */
75
- symbol?: TSOutputSymbol;
73
+ default?: boolean;
76
74
  }
77
75
 
76
+ /**
77
+ * The base props for declaration components.
78
+ */
79
+ export type CommonDeclarationProps = Omit<DeclarationPropsWithInfo, "nameKind">;
80
+
81
+ export type DeclarationProps =
82
+ | DeclarationPropsWithSymbol
83
+ | DeclarationPropsWithInfo;
84
+
78
85
  /**
79
86
  * Create a TypeScript declaration. Generally, this component shouldn't be used
80
87
  * directly, and instead prefer components for specific declarations, e.g.
@@ -89,32 +96,32 @@ export interface DeclarationProps extends Omit<BaseDeclarationProps, "name"> {
89
96
  export function Declaration(props: DeclarationProps) {
90
97
  let sym: TSOutputSymbol;
91
98
 
92
- if (props.symbol) {
99
+ if ("symbol" in props) {
93
100
  sym = props.symbol;
94
101
  } else {
95
- const namePolicy = useTSNamePolicy();
96
- const name = namePolicy.getName(props.name!, props.nameKind!);
97
102
  if (props.kind === "type") {
98
- sym = createTypeSymbol(name, {
103
+ sym = createTypeSymbol(props.name!, {
99
104
  refkeys: props.refkey,
100
105
  export: props.export,
101
106
  default: props.default,
102
107
  metadata: props.metadata,
108
+ namePolicy: useTSNamePolicy().for(props.nameKind!),
103
109
  });
104
110
  } else {
105
- sym = createValueSymbol(name, {
111
+ sym = createValueSymbol(props.name!, {
106
112
  refkeys: props.refkey,
107
113
  export: props.export,
108
114
  default: props.default,
109
115
  metadata: props.metadata,
116
+ namePolicy: useTSNamePolicy().for(props.nameKind!),
110
117
  });
111
118
  }
112
119
  }
113
120
 
114
121
  return (
115
122
  <CoreDeclaration symbol={sym}>
116
- {props.export ? "export " : ""}
117
- {props.default ? "default " : ""}
123
+ {sym.export ? "export " : ""}
124
+ {sym.default ? "default " : ""}
118
125
  {props.children}
119
126
  </CoreDeclaration>
120
127
  );
@@ -8,11 +8,11 @@ import {
8
8
  } from "@alloy-js/core";
9
9
  import { useTSNamePolicy } from "../name-policy.js";
10
10
  import { createTypeAndValueSymbol } from "../symbols/index.js";
11
- import { BaseDeclarationProps } from "./Declaration.js";
11
+ import { CommonDeclarationProps } from "./Declaration.js";
12
12
  import { EnumMember } from "./EnumMember.jsx";
13
13
  import { JSDoc } from "./JSDoc.jsx";
14
14
  import { MemberScope } from "./MemberScope.jsx";
15
- export interface EnumDeclarationProps extends BaseDeclarationProps {
15
+ export interface EnumDeclarationProps extends CommonDeclarationProps {
16
16
  /**
17
17
  * A JS object representing the enum member names and values.
18
18
  */
@@ -23,12 +23,12 @@ export interface EnumDeclarationProps extends BaseDeclarationProps {
23
23
  * A TypeScript enum declaration.
24
24
  */
25
25
  export function EnumDeclaration(props: EnumDeclarationProps) {
26
- const name = useTSNamePolicy().getName(props.name, "enum");
27
- const sym = createTypeAndValueSymbol(name, {
26
+ const sym = createTypeAndValueSymbol(props.name, {
28
27
  refkeys: props.refkey,
29
28
  default: props.default,
30
29
  export: props.export,
31
30
  metadata: props.metadata,
31
+ namePolicy: useTSNamePolicy().for("enum"),
32
32
  });
33
33
 
34
34
  const valueEntries = computed(() => Object.entries(props.jsValue ?? {}));
@@ -1,7 +1,6 @@
1
- import { Children, Refkey, Show } from "@alloy-js/core";
1
+ import { Children, Namekey, Refkey, Show } from "@alloy-js/core";
2
2
  import { useTSNamePolicy } from "../name-policy.js";
3
3
  import { createStaticMemberSymbol } from "../symbols/index.js";
4
- import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
5
4
  import { JSDoc } from "./JSDoc.jsx";
6
5
  import { PropertyName } from "./PropertyName.jsx";
7
6
  import { ValueExpression } from "./ValueExpression.jsx";
@@ -13,7 +12,7 @@ export interface EnumMemberProps {
13
12
  * If a naming policy is provided in context, the policy name "enum-member" is
14
13
  * used.
15
14
  */
16
- name: string;
15
+ name: string | Namekey;
17
16
 
18
17
  /**
19
18
  * Refkey for the enum member symbol. If the refkey is not provided, a symbol
@@ -47,15 +46,11 @@ export interface EnumMemberProps {
47
46
  */
48
47
  export function EnumMember(props: EnumMemberProps) {
49
48
  const namer = useTSNamePolicy();
50
- const name = namer.getName(props.name, "enum-member");
51
- let sym: TSOutputSymbol | undefined = undefined;
52
- if (props.refkey) {
53
- sym = createStaticMemberSymbol(name, {
54
- refkeys: props.refkey,
55
- metadata: props.metadata,
56
- });
57
- }
58
- const actualName = sym ? sym.name : name;
49
+ const sym = createStaticMemberSymbol(props.name, {
50
+ refkeys: props.refkey,
51
+ metadata: props.metadata,
52
+ namePolicy: namer.for("enum-member"),
53
+ });
59
54
  const valueCode =
60
55
  props.jsValue !== undefined ?
61
56
  <ValueExpression jsValue={props.jsValue} />
@@ -67,7 +62,7 @@ export function EnumMember(props: EnumMemberProps) {
67
62
  <JSDoc children={props.doc} />
68
63
  <hbr />
69
64
  </Show>
70
- <PropertyName name={actualName} />
65
+ <PropertyName name={sym.name} />
71
66
  <Show when={valueCode !== undefined}> = {valueCode}</Show>
72
67
  </>
73
68
  );
@@ -216,15 +216,13 @@ function normalizeAndDeclareParameters(
216
216
  TSSymbolFlags.Nullish
217
217
  : TSSymbolFlags.None;
218
218
  const TypeSlot = createSymbolSlot();
219
- const symbol = createValueSymbol(
220
- namePolicy.getName(param.name, "parameter"),
221
- {
222
- refkeys: param.refkey,
223
- tsFlags: flags | nullishFlag,
224
- metadata: param.metadata,
225
- type: TypeSlot.firstSymbol,
226
- },
227
- );
219
+ const symbol = createValueSymbol(param.name, {
220
+ refkeys: param.refkey,
221
+ tsFlags: flags | nullishFlag,
222
+ metadata: param.metadata,
223
+ type: TypeSlot.firstSymbol,
224
+ namePolicy: namePolicy.for("parameter"),
225
+ });
228
226
 
229
227
  return {
230
228
  ...param,
@@ -9,7 +9,7 @@ import {
9
9
  } from "@alloy-js/core";
10
10
  import { getCallSignatureProps } from "../utils.js";
11
11
  import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
12
- import { BaseDeclarationProps, Declaration } from "./Declaration.js";
12
+ import { CommonDeclarationProps, Declaration } from "./Declaration.js";
13
13
  import {
14
14
  FunctionBody,
15
15
  FunctionParameters,
@@ -21,7 +21,7 @@ import { JSDocParams } from "./JSDocParam.jsx";
21
21
  import { LexicalScope } from "./LexicalScope.jsx";
22
22
 
23
23
  export interface FunctionDeclarationProps
24
- extends BaseDeclarationProps,
24
+ extends CommonDeclarationProps,
25
25
  CallSignatureProps {
26
26
  async?: boolean;
27
27
  children?: Children;
@@ -77,7 +77,7 @@ export function FunctionDeclaration(props: FunctionDeclarationProps) {
77
77
  </Show>
78
78
  <Declaration {...props} nameKind="function">
79
79
  {asyncKwd}function <Name />
80
- <LexicalScope name={props.name}>
80
+ <LexicalScope>
81
81
  <CallSignature {...callSignatureProps} returnType={returnType} />{" "}
82
82
  {sBody}
83
83
  </LexicalScope>
@@ -8,24 +8,24 @@ import {
8
8
  findKeyedChild,
9
9
  findUnkeyedChildren,
10
10
  Name,
11
+ Namekey,
11
12
  Refkey,
12
13
  Show,
13
14
  takeSymbols,
14
15
  } from "@alloy-js/core";
15
16
  import { useTSNamePolicy } from "../name-policy.js";
16
- import { BaseDeclarationProps, Declaration } from "./Declaration.js";
17
- import { JSDoc } from "./JSDoc.jsx";
18
-
19
17
  import { TypeParameterDescriptor } from "../parameter-descriptor.js";
20
18
  import { useTSLexicalScope, useTSMemberScope } from "../symbols/scopes.js";
21
19
  import { TSOutputSymbol, TSSymbolFlags } from "../symbols/ts-output-symbol.js";
20
+ import { CommonDeclarationProps, Declaration } from "./Declaration.js";
22
21
  import { TypeParameters } from "./FunctionBase.jsx";
22
+ import { JSDoc } from "./JSDoc.jsx";
23
23
  import { MemberDeclaration } from "./MemberDeclaration.jsx";
24
24
  import { MemberScope } from "./MemberScope.jsx";
25
25
  import { PropertyName } from "./PropertyName.jsx";
26
26
  import { ensureTypeRefContext } from "./TypeRefContext.jsx";
27
27
 
28
- export interface InterfaceDeclarationProps extends BaseDeclarationProps {
28
+ export interface InterfaceDeclarationProps extends CommonDeclarationProps {
29
29
  extends?: Children;
30
30
 
31
31
  /**
@@ -65,16 +65,16 @@ const _InterfaceDeclaration = ensureTypeRefContext(
65
65
  : <TypeParameters parameters={props.typeParameters} />;
66
66
 
67
67
  const extendsPart = props.extends ? <> extends {props.extends}</> : "";
68
- const name = useTSNamePolicy().getName(props.name, "interface");
69
68
  const filteredChildren = findUnkeyedChildren(children);
70
69
  const currentScope = useTSLexicalScope();
71
70
 
72
- const sym = new TSOutputSymbol(name, currentScope.types, {
71
+ const sym = new TSOutputSymbol(props.name, currentScope.types, {
73
72
  refkeys: props.refkey,
74
73
  default: props.default,
75
74
  export: props.export,
76
75
  metadata: props.metadata,
77
76
  tsFlags: TSSymbolFlags.TypeSymbol,
77
+ namePolicy: useTSNamePolicy().for("interface"),
78
78
  });
79
79
  return (
80
80
  <>
@@ -132,17 +132,26 @@ export const InterfaceExpression = ensureTypeRefContext(
132
132
  },
133
133
  );
134
134
 
135
- export interface InterfaceMemberProps {
136
- name?: string;
137
- indexer?: Children;
135
+ export interface InterfaceMemberPropsBase {
138
136
  type?: Children;
139
137
  children?: Children;
140
- optional?: boolean;
141
- nullish?: boolean;
142
138
  readonly?: boolean;
143
139
  doc?: Children;
144
140
  refkey?: Refkey | Refkey[];
145
141
  }
142
+ export interface InterfacePropertyMemberProps extends InterfaceMemberPropsBase {
143
+ name: string | Namekey;
144
+ optional?: boolean;
145
+ nullish?: boolean;
146
+ }
147
+
148
+ export interface InterfaceIndexerMemberProps extends InterfaceMemberPropsBase {
149
+ indexer: Children;
150
+ }
151
+
152
+ export type InterfaceMemberProps =
153
+ | InterfacePropertyMemberProps
154
+ | InterfaceIndexerMemberProps;
146
155
 
147
156
  /**
148
157
  * Create a TypeScript interface member.
@@ -155,54 +164,51 @@ export interface InterfaceMemberProps {
155
164
  */
156
165
  export function InterfaceMember(props: InterfaceMemberProps) {
157
166
  const type = props.type ?? props.children;
158
- const optionality = props.optional ? "?" : "";
159
167
  const readonly = props.readonly ? "readonly " : "";
160
168
 
161
- if (props.indexer) {
169
+ if ("indexer" in props) {
162
170
  return (
163
171
  <>
164
- {readonly}[{props.indexer}]: {type}
165
- </>
166
- );
167
- } else {
168
- const namer = useTSNamePolicy();
169
- const name = namer.getName(props.name!, "interface-member");
170
- let sym = undefined;
171
- if (props.name) {
172
- const scope = useTSMemberScope();
173
- sym = new TSOutputSymbol(name, scope.ownerSymbol.staticMembers, {
174
- refkeys: props.refkey,
175
- tsFlags:
176
- TSSymbolFlags.TypeSymbol |
177
- ((props.nullish ?? props.optional) ?
178
- TSSymbolFlags.Nullish
179
- : TSSymbolFlags.None),
180
- });
181
-
182
- const taken = takeSymbols();
183
-
184
- effect(() => {
185
- if (taken.size > 1) return;
186
- const symbol = Array.from(taken)[0];
187
- if (symbol?.isTransient) {
188
- symbol.moveMembersTo(sym!);
189
- }
190
- });
191
- } else {
192
- // noop
193
- takeSymbols();
194
- }
195
-
196
- return (
197
- <MemberDeclaration symbol={sym}>
198
172
  <Show when={Boolean(props.doc)}>
199
173
  <JSDoc children={props.doc} />
200
174
  <hbr />
201
175
  </Show>
202
- {readonly}
203
- <PropertyName />
204
- {optionality}: {type}
205
- </MemberDeclaration>
176
+ {readonly}[{props.indexer}]: {type}
177
+ </>
206
178
  );
207
179
  }
180
+
181
+ const optionality = props.optional ? "?" : "";
182
+ const scope = useTSMemberScope();
183
+ const sym = new TSOutputSymbol(props.name, scope.ownerSymbol.staticMembers, {
184
+ refkeys: props.refkey,
185
+ tsFlags:
186
+ TSSymbolFlags.TypeSymbol |
187
+ ((props.nullish ?? props.optional) ?
188
+ TSSymbolFlags.Nullish
189
+ : TSSymbolFlags.None),
190
+ namePolicy: useTSNamePolicy().for("interface-member"),
191
+ });
192
+
193
+ const taken = takeSymbols();
194
+
195
+ effect(() => {
196
+ if (taken.size > 1) return;
197
+ const symbol = Array.from(taken)[0];
198
+ if (symbol?.isTransient) {
199
+ symbol.moveMembersTo(sym!);
200
+ }
201
+ });
202
+
203
+ return (
204
+ <MemberDeclaration symbol={sym}>
205
+ <Show when={Boolean(props.doc)}>
206
+ <JSDoc children={props.doc} />
207
+ <hbr />
208
+ </Show>
209
+ {readonly}
210
+ <PropertyName />
211
+ {optionality}: {type}
212
+ </MemberDeclaration>
213
+ );
208
214
  }
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  childrenArray,
3
3
  findKeyedChild,
4
+ MemberName,
5
+ Namekey,
4
6
  Prose,
5
7
  Refkey,
6
8
  Show,
7
9
  type Children,
8
10
  } from "@alloy-js/core";
9
- import { useTSNamePolicy } from "../name-policy.js";
10
11
  import { getCallSignatureProps } from "../utils.js";
11
12
  import { CallSignature, CallSignatureProps } from "./CallSignature.jsx";
12
13
  import {
@@ -23,7 +24,7 @@ import { MemberDeclaration } from "./MemberDeclaration.jsx";
23
24
  /** Props for {@link (InterfaceMethod:namespace)} component */
24
25
  export interface InterfaceMethodProps extends CallSignatureProps {
25
26
  /** Interface member name */
26
- readonly name: string;
27
+ readonly name: string | Namekey;
27
28
  /** If the method is async. It will change the returnType from `T` to `Promise<T>` */
28
29
  readonly async?: boolean;
29
30
  /** Documentation for this method. */
@@ -69,8 +70,7 @@ export function InterfaceMethod(props: InterfaceMethodProps) {
69
70
  parametersChildren,
70
71
  typeParametersChildren,
71
72
  });
72
- const namer = useTSNamePolicy();
73
- const name = namer.getName(props.name!, "interface-member");
73
+
74
74
  return (
75
75
  <>
76
76
  <Show when={Boolean(props.doc)}>
@@ -82,9 +82,14 @@ export function InterfaceMethod(props: InterfaceMethodProps) {
82
82
  </JSDoc>
83
83
  <hbr />
84
84
  </Show>
85
- <MemberDeclaration static {...props} refkey={props.refkey}>
86
- {name}
87
- <LexicalScope name={props.name}>
85
+ <MemberDeclaration
86
+ static
87
+ {...props}
88
+ refkey={props.refkey}
89
+ nameKind="interface-member"
90
+ >
91
+ <MemberName />
92
+ <LexicalScope>
88
93
  <CallSignature {...callSignatureProps} returnType={returnType} />
89
94
  </LexicalScope>
90
95
  </MemberDeclaration>
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  MemberDeclaration as CoreMemberDeclaration,
3
- MemberDeclarationPropsWithInfo,
3
+ MemberDeclarationPropsWithInfo as CoreMemberDeclarationPropsWithInfo,
4
+ MemberDeclarationPropsWithSymbol as CoreMemberDeclarationPropsWithSymbol,
4
5
  } from "@alloy-js/core";
5
6
  import { TypeScriptElements, useTSNamePolicy } from "../name-policy.js";
6
7
  import {
@@ -9,49 +10,44 @@ import {
9
10
  TSSymbolFlags,
10
11
  } from "../symbols/index.js";
11
12
 
12
- export interface MemberDeclarationProps
13
- extends Omit<MemberDeclarationPropsWithInfo, "name"> {
14
- /**
15
- * The name of this member declaration.
16
- */
17
- name?: string;
18
-
19
- /** Name that shouldn't go through the name policy resolver again. */
20
- exactName?: string;
21
-
13
+ export interface MemberDeclarationPropsWithInfo
14
+ extends CoreMemberDeclarationPropsWithInfo {
22
15
  /**
23
16
  * The name policy kind to apply to the memberdeclaration.
24
17
  */
25
- nameKind?: TypeScriptElements;
26
-
27
- /**
28
- * The symbol to use for this memberdeclaration.
29
- */
30
- symbol?: TSOutputSymbol;
18
+ nameKind: TypeScriptElements;
31
19
  /**
32
20
  * Whether this member can be null or undefined.
33
21
  */
34
22
  nullish?: boolean;
35
23
  }
36
24
 
25
+ export interface MemberDeclarationPropsWithSymbol
26
+ extends CoreMemberDeclarationPropsWithSymbol {
27
+ /**
28
+ * The symbol for the member declaration.
29
+ */
30
+ symbol: TSOutputSymbol;
31
+ }
32
+
33
+ export type MemberDeclarationProps =
34
+ | MemberDeclarationPropsWithInfo
35
+ | MemberDeclarationPropsWithSymbol;
36
+
37
37
  export function MemberDeclaration(props: Readonly<MemberDeclarationProps>) {
38
38
  let sym: TSOutputSymbol;
39
39
 
40
- if (props.symbol) {
40
+ if ("symbol" in props) {
41
41
  sym = props.symbol;
42
42
  } else {
43
- const namePolicy = useTSNamePolicy();
44
-
45
43
  const tsFlags: TSSymbolFlags =
46
44
  props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None;
47
45
 
48
- const name =
49
- props.exactName ?? namePolicy.getName(props.name!, props.nameKind!);
50
-
51
- sym = createStaticMemberSymbol(name, {
46
+ sym = createStaticMemberSymbol(props.name!, {
52
47
  refkeys: props.refkey,
53
48
  tsFlags,
54
49
  metadata: props.metadata,
50
+ namePolicy: useTSNamePolicy().for(props.nameKind!),
55
51
  });
56
52
  }
57
53