@alloy-js/typescript 0.21.0-dev.0 → 0.21.0-dev.11

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 (122) hide show
  1. package/dist/src/components/ClassDeclaration.d.ts +5 -5
  2. package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
  3. package/dist/src/components/ClassDeclaration.js +7 -12
  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/ObjectExpression.d.ts +2 -2
  37. package/dist/src/components/ObjectExpression.d.ts.map +1 -1
  38. package/dist/src/components/ObjectExpression.js +25 -18
  39. package/dist/src/components/ObjectExpression.js.map +1 -1
  40. package/dist/src/components/PropertyName.d.ts.map +1 -1
  41. package/dist/src/components/PropertyName.js +7 -5
  42. package/dist/src/components/PropertyName.js.map +1 -1
  43. package/dist/src/components/TypeDeclaration.d.ts +2 -2
  44. package/dist/src/components/TypeDeclaration.d.ts.map +1 -1
  45. package/dist/src/components/TypeDeclaration.js.map +1 -1
  46. package/dist/src/components/VarDeclaration.d.ts +2 -2
  47. package/dist/src/components/VarDeclaration.d.ts.map +1 -1
  48. package/dist/src/components/VarDeclaration.js +16 -4
  49. package/dist/src/components/VarDeclaration.js.map +1 -1
  50. package/dist/src/parameter-descriptor.d.ts +3 -3
  51. package/dist/src/parameter-descriptor.d.ts.map +1 -1
  52. package/dist/src/symbols/index.d.ts +9 -9
  53. package/dist/src/symbols/index.d.ts.map +1 -1
  54. package/dist/src/symbols/index.js.map +1 -1
  55. package/dist/src/symbols/reference.d.ts.map +1 -1
  56. package/dist/src/symbols/reference.js +2 -2
  57. package/dist/src/symbols/reference.js.map +1 -1
  58. package/dist/src/symbols/ts-output-symbol.d.ts +2 -2
  59. package/dist/src/symbols/ts-output-symbol.d.ts.map +1 -1
  60. package/dist/src/symbols/ts-output-symbol.js.map +1 -1
  61. package/dist/test/class.test.js +29 -1
  62. package/dist/test/class.test.js.map +1 -1
  63. package/dist/test/enum.test.js +30 -1
  64. package/dist/test/enum.test.js.map +1 -1
  65. package/dist/test/function-declaration.test.js +18 -1
  66. package/dist/test/function-declaration.test.js.map +1 -1
  67. package/dist/test/imports.test.js +3 -2
  68. package/dist/test/imports.test.js.map +1 -1
  69. package/dist/test/interface.test.d.ts.map +1 -1
  70. package/dist/test/interface.test.js +25 -1
  71. package/dist/test/interface.test.js.map +1 -1
  72. package/dist/test/object.test.js +55 -2
  73. package/dist/test/object.test.js.map +1 -1
  74. package/dist/test/reference.test.js +14 -0
  75. package/dist/test/reference.test.js.map +1 -1
  76. package/dist/test/var-declaration.test.d.ts.map +1 -1
  77. package/dist/test/var-declaration.test.js +33 -1
  78. package/dist/test/var-declaration.test.js.map +1 -1
  79. package/dist/testing/create-wrapper.d.ts +3 -0
  80. package/dist/testing/create-wrapper.d.ts.map +1 -0
  81. package/dist/testing/create-wrapper.js +12 -0
  82. package/dist/testing/create-wrapper.js.map +1 -0
  83. package/dist/testing/create-wrapper.test.d.ts +2 -0
  84. package/dist/testing/create-wrapper.test.d.ts.map +1 -0
  85. package/dist/testing/create-wrapper.test.js +159 -0
  86. package/dist/testing/create-wrapper.test.js.map +1 -0
  87. package/dist/testing/index.d.ts +2 -0
  88. package/dist/testing/index.d.ts.map +1 -0
  89. package/dist/testing/index.js +2 -0
  90. package/dist/testing/index.js.map +1 -0
  91. package/dist/tsconfig.tsbuildinfo +1 -1
  92. package/package.json +10 -2
  93. package/src/components/ClassDeclaration.tsx +10 -13
  94. package/src/components/Declaration.tsx +39 -32
  95. package/src/components/EnumDeclaration.tsx +4 -4
  96. package/src/components/EnumMember.tsx +8 -13
  97. package/src/components/FunctionBase.tsx +7 -9
  98. package/src/components/FunctionDeclaration.tsx +3 -3
  99. package/src/components/Interface.tsx +57 -51
  100. package/src/components/InterfaceMethod.tsx +12 -7
  101. package/src/components/MemberDeclaration.tsx +20 -24
  102. package/src/components/ObjectExpression.tsx +20 -16
  103. package/src/components/PropertyName.tsx +7 -5
  104. package/src/components/TypeDeclaration.tsx +2 -2
  105. package/src/components/VarDeclaration.tsx +11 -6
  106. package/src/parameter-descriptor.ts +3 -3
  107. package/src/symbols/index.ts +12 -9
  108. package/src/symbols/reference.tsx +3 -1
  109. package/src/symbols/ts-output-symbol.ts +2 -1
  110. package/temp/api.json +745 -492
  111. package/test/class.test.tsx +19 -1
  112. package/test/enum.test.tsx +21 -1
  113. package/test/function-declaration.test.tsx +15 -0
  114. package/test/imports.test.tsx +2 -1
  115. package/test/interface.test.tsx +29 -0
  116. package/test/object.test.tsx +40 -1
  117. package/test/reference.test.tsx +12 -2
  118. package/test/var-declaration.test.tsx +27 -1
  119. package/testing/create-wrapper.test.tsx +107 -0
  120. package/testing/create-wrapper.tsx +12 -0
  121. package/testing/index.ts +1 -0
  122. package/tsconfig.json +8 -1
@@ -4,8 +4,10 @@ import {
4
4
  computed,
5
5
  emitSymbol,
6
6
  For,
7
+ isNamekey,
7
8
  Match,
8
9
  moveTakenMembersTo,
10
+ Namekey,
9
11
  Refkey,
10
12
  Switch,
11
13
  takeSymbols,
@@ -68,7 +70,7 @@ export function ObjectExpression(props: ObjectExpressionProps) {
68
70
  <>
69
71
  {jsValueProperties.value.length > 0 && (
70
72
  <>
71
- ,<sbr />
73
+ <sbr />
72
74
  </>
73
75
  )}
74
76
  {props.children}
@@ -83,7 +85,7 @@ export function ObjectExpression(props: ObjectExpressionProps) {
83
85
  }
84
86
 
85
87
  export interface ObjectPropertyProps {
86
- name?: string;
88
+ name?: string | Namekey;
87
89
  nameExpression?: Children;
88
90
  value?: Children;
89
91
  jsValue?: unknown;
@@ -92,22 +94,12 @@ export interface ObjectPropertyProps {
92
94
  }
93
95
 
94
96
  export function ObjectProperty(props: ObjectPropertyProps) {
95
- let name;
96
- let symbolName = props.name;
97
- if (props.name) {
98
- const namer = useTSNamePolicy();
99
- symbolName = namer.getName(props.name, "object-member-data");
100
- name = <PropertyName name={symbolName} />;
101
- } else if (props.nameExpression) {
102
- name = <>[{props.nameExpression}]</>;
103
- } else {
104
- throw new Error("ObjectProperty either a name or a nameExpression.");
105
- }
106
-
107
97
  let sym = undefined;
108
- if (props.refkey && props.name) {
109
- sym = createStaticMemberSymbol(symbolName!, {
98
+
99
+ if (isNamekey(props.name) || (props.refkey && props.name)) {
100
+ sym = createStaticMemberSymbol(props.name, {
110
101
  refkeys: props.refkey,
102
+ namePolicy: useTSNamePolicy().for("object-member-data"),
111
103
  });
112
104
 
113
105
  moveTakenMembersTo(sym);
@@ -117,6 +109,18 @@ export function ObjectProperty(props: ObjectPropertyProps) {
117
109
  takeSymbols();
118
110
  }
119
111
 
112
+ let name: Children;
113
+ if (sym) {
114
+ name = <PropertyName name={sym.name} />;
115
+ } else if (props.name) {
116
+ // can't be a namekey if we get here
117
+ name = <PropertyName name={props.name as string} />;
118
+ } else if (props.nameExpression) {
119
+ name = <>[{props.nameExpression}]</>;
120
+ } else {
121
+ throw new Error("ObjectProperty either a name or a nameExpression.");
122
+ }
123
+
120
124
  let value;
121
125
  if (props.value) {
122
126
  value = props.value;
@@ -1,4 +1,4 @@
1
- import { MemberDeclarationContext, useContext } from "@alloy-js/core";
1
+ import { MemberDeclarationContext, memo, useContext } from "@alloy-js/core";
2
2
  import { TSOutputSymbol } from "../symbols/ts-output-symbol.js";
3
3
  import { isValidJSIdentifier } from "../utils.js";
4
4
 
@@ -23,10 +23,12 @@ export interface PropertyNameProps {
23
23
  */
24
24
  export function PropertyName(props: PropertyNameProps) {
25
25
  if (props.name) {
26
- if (props.private) {
27
- return "#" + props.name;
28
- }
29
- return quoteIfNeeded(props.name);
26
+ return memo(() => {
27
+ if (props.private) {
28
+ return "#" + props.name;
29
+ }
30
+ return quoteIfNeeded(props.name!);
31
+ });
30
32
  } else {
31
33
  const declSymbol = useContext(MemberDeclarationContext) as TSOutputSymbol;
32
34
  if (!declSymbol) {
@@ -1,9 +1,9 @@
1
1
  import { Name, Show } from "@alloy-js/core";
2
- import { BaseDeclarationProps, Declaration } from "./Declaration.js";
2
+ import { CommonDeclarationProps, Declaration } from "./Declaration.js";
3
3
  import { JSDoc } from "./JSDoc.jsx";
4
4
  import { ensureTypeRefContext } from "./TypeRefContext.jsx";
5
5
 
6
- export interface TypeDeclarationProps extends BaseDeclarationProps {}
6
+ export interface TypeDeclarationProps extends CommonDeclarationProps {}
7
7
 
8
8
  export const TypeDeclaration = ensureTypeRefContext(
9
9
  (props: TypeDeclarationProps) => {
@@ -8,11 +8,11 @@ import {
8
8
  import { useTSNamePolicy } from "../name-policy.js";
9
9
  import { createValueSymbol } from "../symbols/index.js";
10
10
  import { TSSymbolFlags } from "../symbols/ts-output-symbol.js";
11
- import { BaseDeclarationProps } from "./Declaration.js";
11
+ import { CommonDeclarationProps } from "./Declaration.js";
12
12
  import { JSDoc } from "./JSDoc.jsx";
13
13
  import { TypeRefContext } from "./TypeRefContext.jsx";
14
14
 
15
- export interface VarDeclarationProps extends BaseDeclarationProps {
15
+ export interface VarDeclarationProps extends CommonDeclarationProps {
16
16
  const?: boolean;
17
17
  let?: boolean;
18
18
  var?: boolean;
@@ -24,14 +24,14 @@ export interface VarDeclarationProps extends BaseDeclarationProps {
24
24
  export function VarDeclaration(props: VarDeclarationProps) {
25
25
  const TypeSymbolSlot = createSymbolSlot();
26
26
  const ValueTypeSymbolSlot = createSymbolSlot();
27
- const name = useTSNamePolicy().getName(props.name, "variable");
28
- const sym = createValueSymbol(name, {
27
+ const sym = createValueSymbol(props.name, {
29
28
  refkeys: props.refkey,
30
29
  default: props.default,
31
30
  export: props.export,
32
31
  metadata: props.metadata,
33
32
  tsFlags: props.nullish ? TSSymbolFlags.Nullish : TSSymbolFlags.None,
34
33
  type: props.type ? TypeSymbolSlot.firstSymbol : undefined,
34
+ namePolicy: useTSNamePolicy().for("variable"),
35
35
  });
36
36
 
37
37
  if (!props.type) {
@@ -58,8 +58,13 @@ export function VarDeclaration(props: VarDeclarationProps) {
58
58
  <CoreDeclaration symbol={sym}>
59
59
  {props.export ? "export " : ""}
60
60
  {props.default ? "default " : ""}
61
- {keyword} <Name />
62
- {type} ={" "}
61
+ <Show when={!props.default}>
62
+ {keyword} <Name />
63
+ {type}
64
+ <Show when={Boolean(props.initializer || props.children)}>
65
+ {" = "}
66
+ </Show>
67
+ </Show>
63
68
  <ValueTypeSymbolSlot>
64
69
  {props.initializer ?? props.children}
65
70
  </ValueTypeSymbolSlot>
@@ -1,4 +1,4 @@
1
- import type { Children, Refkey } from "@alloy-js/core";
1
+ import type { Children, Namekey, Refkey } from "@alloy-js/core";
2
2
 
3
3
  /**
4
4
  * Common properties for ParameterDescriptor and FunctionTypeParameterDescriptor.
@@ -7,7 +7,7 @@ export interface ParameterDescriptorBase {
7
7
  /**
8
8
  * The name of the parameter.
9
9
  */
10
- readonly name: string;
10
+ readonly name: string | Namekey;
11
11
 
12
12
  /**
13
13
  * The type of the parameter.
@@ -75,7 +75,7 @@ export interface TypeParameterDescriptor {
75
75
  /**
76
76
  * The name of the type parameter.
77
77
  */
78
- readonly name: string;
78
+ readonly name: string | Namekey;
79
79
 
80
80
  /**
81
81
  * The extends constraint for the type parameter.
@@ -1,4 +1,4 @@
1
- import { OutputScopeOptions } from "@alloy-js/core";
1
+ import { Namekey, OutputScopeOptions } from "@alloy-js/core";
2
2
  import { useLexicalScope, useMemberOwner } from "../utils.js";
3
3
  import { useTSScope } from "./scopes.js";
4
4
  import { TSLexicalScope } from "./ts-lexical-scope.js";
@@ -14,7 +14,7 @@ export * from "./ts-output-symbol.js";
14
14
  export * from "./ts-package-scope.js";
15
15
 
16
16
  export function createTypeAndValueSymbol(
17
- name: string,
17
+ name: string | Namekey,
18
18
  options: CreateTsSymbolOptions = {},
19
19
  ) {
20
20
  const scope = useLexicalScope();
@@ -22,7 +22,10 @@ export function createTypeAndValueSymbol(
22
22
  return new TSOutputSymbol(name, spaces, options);
23
23
  }
24
24
 
25
- export function createTypeSymbol(name: string, options: CreateTsSymbolOptions) {
25
+ export function createTypeSymbol(
26
+ name: string | Namekey,
27
+ options: CreateTsSymbolOptions,
28
+ ) {
26
29
  const scope = useLexicalScope();
27
30
  if (scope && !scope.types) {
28
31
  throw new Error(
@@ -34,7 +37,7 @@ export function createTypeSymbol(name: string, options: CreateTsSymbolOptions) {
34
37
  }
35
38
 
36
39
  export function createValueSymbol(
37
- name: string,
40
+ name: string | Namekey,
38
41
  options: CreateTsSymbolOptions = {},
39
42
  ) {
40
43
  const scope = useLexicalScope();
@@ -54,7 +57,7 @@ export function createTransientValueSymbol() {
54
57
  }
55
58
 
56
59
  export function createStaticMemberSymbol(
57
- name: string,
60
+ name: string | Namekey,
58
61
  options: CreateTsSymbolOptions = {},
59
62
  ) {
60
63
  const owner = useMemberOwner();
@@ -62,7 +65,7 @@ export function createStaticMemberSymbol(
62
65
  }
63
66
 
64
67
  export function createInstanceMemberSymbol(
65
- name: string,
68
+ name: string | Namekey,
66
69
  options: CreateTsSymbolOptions = {},
67
70
  ) {
68
71
  const owner = useMemberOwner();
@@ -70,7 +73,7 @@ export function createInstanceMemberSymbol(
70
73
  }
71
74
 
72
75
  export function createPrivateStaticMemberSymbol(
73
- name: string,
76
+ name: string | Namekey,
74
77
  options: CreateTsSymbolOptions = {},
75
78
  ) {
76
79
  const owner = useMemberOwner();
@@ -78,7 +81,7 @@ export function createPrivateStaticMemberSymbol(
78
81
  }
79
82
 
80
83
  export function createPrivateInstanceMemberSymbol(
81
- name: string,
84
+ name: string | Namekey,
82
85
  options: CreateTsSymbolOptions = {},
83
86
  ) {
84
87
  const owner = useMemberOwner();
@@ -86,7 +89,7 @@ export function createPrivateInstanceMemberSymbol(
86
89
  }
87
90
 
88
91
  export function createMemberSymbol(
89
- name: string,
92
+ name: string | Namekey,
90
93
  locationOptions: { jsPrivate?: boolean; static?: boolean },
91
94
  options: CreateTsSymbolOptions = {},
92
95
  ) {
@@ -5,6 +5,7 @@ import {
5
5
  memo,
6
6
  Refkey,
7
7
  resolve,
8
+ unresolvedRefkey,
8
9
  untrack,
9
10
  useContext,
10
11
  } from "@alloy-js/core";
@@ -20,6 +21,7 @@ import { TSPackageScope } from "./ts-package-scope.js";
20
21
  export interface RefOptions {
21
22
  type?: boolean;
22
23
  }
24
+
23
25
  export function ref(
24
26
  refkey: Refkey,
25
27
  options?: RefOptions,
@@ -32,7 +34,7 @@ export function ref(
32
34
 
33
35
  return memo(() => {
34
36
  if (resolveResult.value === undefined) {
35
- return ["<Unresolved Symbol>", undefined];
37
+ return [unresolvedRefkey(refkey), undefined];
36
38
  }
37
39
 
38
40
  const { symbol, pathDown, memberPath, lexicalDeclaration, commonScope } =
@@ -1,4 +1,5 @@
1
1
  import {
2
+ Namekey,
2
3
  OutputSpace,
3
4
  OutputSymbol,
4
5
  OutputSymbolOptions,
@@ -36,7 +37,7 @@ export class TSOutputSymbol extends OutputSymbol {
36
37
  ] as const;
37
38
 
38
39
  constructor(
39
- name: string,
40
+ name: string | Namekey,
40
41
  spaces: OutputSpace[] | OutputSpace | undefined,
41
42
  options: CreateTsSymbolOptions = {},
42
43
  ) {