@alloy-js/typescript 0.24.0-dev.1 → 0.25.0-dev.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 (53) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/dev/src/components/BlockScope.js +2 -2
  3. package/dist/dev/src/components/BlockScope.js.map +1 -1
  4. package/dist/dev/src/components/FunctionBase.js +10 -10
  5. package/dist/dev/src/components/FunctionBase.js.map +1 -1
  6. package/dist/dev/src/components/FunctionDeclaration.js +10 -10
  7. package/dist/dev/src/components/FunctionDeclaration.js.map +1 -1
  8. package/dist/dev/src/components/MemberDeclaration.js +1 -1
  9. package/dist/dev/src/components/MemberDeclaration.js.map +1 -1
  10. package/dist/dev/src/components/index.js.map +1 -1
  11. package/dist/dev/test/function-declaration.test.js +151 -71
  12. package/dist/dev/test/function-declaration.test.js.map +1 -1
  13. package/dist/src/components/BlockScope.d.ts.map +1 -1
  14. package/dist/src/components/BlockScope.js.map +1 -1
  15. package/dist/src/components/FunctionBase.d.ts.map +1 -1
  16. package/dist/src/components/FunctionBase.js.map +1 -1
  17. package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
  18. package/dist/src/components/FunctionDeclaration.js.map +1 -1
  19. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  20. package/dist/src/components/MemberDeclaration.js.map +1 -1
  21. package/dist/src/components/index.d.ts +1 -1
  22. package/dist/src/components/index.d.ts.map +1 -1
  23. package/dist/src/components/index.js.map +1 -1
  24. package/dist/src/parameter-descriptor.d.ts.map +1 -1
  25. package/dist/test/function-declaration.test.js +65 -1
  26. package/dist/test/function-declaration.test.js.map +1 -1
  27. package/dist/tsconfig.tsbuildinfo +1 -1
  28. package/docs/api/components/ArrowFunction.md +1 -3
  29. package/docs/api/components/FunctionDeclaration.md +1 -3
  30. package/docs/api/components/FunctionExpression.md +1 -3
  31. package/docs/api/components/InterfaceMethod.md +1 -3
  32. package/docs/api/components/MemberExpression.md +1 -6
  33. package/docs/api/components/ensureTypeRefContext.md +1 -1
  34. package/docs/api/components/index.md +0 -2
  35. package/docs/api/index.md +2 -2
  36. package/docs/api/types/NamedModuleDescriptor.md +1 -5
  37. package/docs/api/{components/Reference.md → types/ReferenceProps.md} +2 -20
  38. package/docs/api/types/TypeParametersProps.md +10 -0
  39. package/docs/api/types/TypeRefContextProps.md +7 -0
  40. package/docs/api/types/index.md +3 -0
  41. package/docs/api/variables/FunctionType.md +1 -3
  42. package/package.json +10 -9
  43. package/src/components/BlockScope.tsx +2 -4
  44. package/src/components/FunctionBase.tsx +12 -6
  45. package/src/components/FunctionDeclaration.tsx +1 -2
  46. package/src/components/MemberDeclaration.tsx +2 -4
  47. package/src/components/index.ts +1 -0
  48. package/src/parameter-descriptor.ts +1 -2
  49. package/temp/api.json +172 -62
  50. package/test/function-declaration.test.tsx +61 -0
  51. package/tsdoc-metadata.json +1 -1
  52. package/vitest.config.ts +1 -0
  53. package/docs/api/components/TypeRefContext.md +0 -35
@@ -1,4 +1,5 @@
1
1
  import {
2
+ code,
2
3
  List,
3
4
  memberRefkey,
4
5
  namekey,
@@ -157,6 +158,38 @@ it("supports type parameters by element", () => {
157
158
  `);
158
159
  });
159
160
 
161
+ it("resolves references to function-local symbols from deeply indented code blocks (#429)", () => {
162
+ const value = refkey();
163
+ expect(
164
+ <TestFile>
165
+ <FunctionDeclaration
166
+ export
167
+ name="serialize"
168
+ parameters={[{ name: "value", type: "string | null", refkey: value }]}
169
+ returnType="string"
170
+ >
171
+ {code`
172
+ if (value) {
173
+ if (!${value}) {
174
+ return ${value} as any;
175
+ }
176
+ }
177
+ return ${value};
178
+ `}
179
+ </FunctionDeclaration>
180
+ </TestFile>,
181
+ ).toRenderTo(`
182
+ export function serialize(value: string | null): string {
183
+ if (value) {
184
+ if (!value) {
185
+ return value as any;
186
+ }
187
+ }
188
+ return value;
189
+ }
190
+ `);
191
+ });
192
+
160
193
  it("do not add an extra comma when there is no parameters", () => {
161
194
  expect(
162
195
  <TestFile>
@@ -169,6 +202,34 @@ it("do not add an extra comma when there is no parameters", () => {
169
202
  `);
170
203
  });
171
204
 
205
+ it("resolves references to function-local symbols from indented code blocks (#429)", () => {
206
+ const value = refkey();
207
+ expect(
208
+ <TestFile>
209
+ <FunctionDeclaration
210
+ export
211
+ name="serialize"
212
+ parameters={[{ name: "value", type: "string | null", refkey: value }]}
213
+ returnType="string"
214
+ >
215
+ {code`
216
+ if (!${value}) {
217
+ return ${value} as any;
218
+ }
219
+ return ${value};
220
+ `}
221
+ </FunctionDeclaration>
222
+ </TestFile>,
223
+ ).toRenderTo(`
224
+ export function serialize(value: string | null): string {
225
+ if (!value) {
226
+ return value as any;
227
+ }
228
+ return value;
229
+ }
230
+ `);
231
+ });
232
+
172
233
  describe("symbols", () => {
173
234
  it("creates a nested scope", () => {
174
235
  const innerRefkey = refkey();
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.9"
8
+ "packageVersion": "7.58.8"
9
9
  }
10
10
  ]
11
11
  }
package/vitest.config.ts CHANGED
@@ -15,6 +15,7 @@ export default defineConfig({
15
15
  sourcemap: "both",
16
16
  },
17
17
  test: {
18
+ exclude: ["**/dist/**", "**/node_modules/**"],
18
19
  setupFiles: ["./test/vitest.setup.ts"],
19
20
  },
20
21
  plugins: [alloyPlugin()],
@@ -1,35 +0,0 @@
1
- # TypeRefContext
2
-
3
- Set the current context of reference to be type reference.
4
-
5
- * jsx
6
-
7
- ```tsx
8
- import { TypeRefContext } from "@alloy-js/typescript";
9
-
10
-
11
- <TypeRefContext >
12
- {children}
13
- </TypeRefContext>
14
- ```
15
-
16
- * stc
17
-
18
- ```ts
19
- import { TypeRefContext } from "@alloy-js/typescript/stc";
20
-
21
-
22
- TypeRefContext({ }).children(children)
23
- ```
24
-
25
- ## Props
26
-
27
- | | | |
28
- | -------- | ----------------------------------------- | -------- |
29
- | children | [Children](../../../core/types/children/) | Children |
30
-
31
- ## Remarks
32
-
33
- References used inside the children of this component will be treated as type reference [Reference](../reference/).
34
-
35
- Prefer using [ensureTypeRefContext](../ensuretyperefcontext/) when wrapping the whole component to reduce tree nodes.