@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.
- package/CHANGELOG.md +4 -0
- package/dist/dev/src/components/BlockScope.js +2 -2
- package/dist/dev/src/components/BlockScope.js.map +1 -1
- package/dist/dev/src/components/FunctionBase.js +10 -10
- package/dist/dev/src/components/FunctionBase.js.map +1 -1
- package/dist/dev/src/components/FunctionDeclaration.js +10 -10
- package/dist/dev/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/dev/src/components/MemberDeclaration.js +1 -1
- package/dist/dev/src/components/MemberDeclaration.js.map +1 -1
- package/dist/dev/src/components/index.js.map +1 -1
- package/dist/dev/test/function-declaration.test.js +151 -71
- package/dist/dev/test/function-declaration.test.js.map +1 -1
- package/dist/src/components/BlockScope.d.ts.map +1 -1
- package/dist/src/components/BlockScope.js.map +1 -1
- package/dist/src/components/FunctionBase.d.ts.map +1 -1
- package/dist/src/components/FunctionBase.js.map +1 -1
- package/dist/src/components/FunctionDeclaration.d.ts.map +1 -1
- package/dist/src/components/FunctionDeclaration.js.map +1 -1
- package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
- package/dist/src/components/MemberDeclaration.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -1
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/parameter-descriptor.d.ts.map +1 -1
- package/dist/test/function-declaration.test.js +65 -1
- package/dist/test/function-declaration.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/api/components/ArrowFunction.md +1 -3
- package/docs/api/components/FunctionDeclaration.md +1 -3
- package/docs/api/components/FunctionExpression.md +1 -3
- package/docs/api/components/InterfaceMethod.md +1 -3
- package/docs/api/components/MemberExpression.md +1 -6
- package/docs/api/components/ensureTypeRefContext.md +1 -1
- package/docs/api/components/index.md +0 -2
- package/docs/api/index.md +2 -2
- package/docs/api/types/NamedModuleDescriptor.md +1 -5
- package/docs/api/{components/Reference.md → types/ReferenceProps.md} +2 -20
- package/docs/api/types/TypeParametersProps.md +10 -0
- package/docs/api/types/TypeRefContextProps.md +7 -0
- package/docs/api/types/index.md +3 -0
- package/docs/api/variables/FunctionType.md +1 -3
- package/package.json +10 -9
- package/src/components/BlockScope.tsx +2 -4
- package/src/components/FunctionBase.tsx +12 -6
- package/src/components/FunctionDeclaration.tsx +1 -2
- package/src/components/MemberDeclaration.tsx +2 -4
- package/src/components/index.ts +1 -0
- package/src/parameter-descriptor.ts +1 -2
- package/temp/api.json +172 -62
- package/test/function-declaration.test.tsx +61 -0
- package/tsdoc-metadata.json +1 -1
- package/vitest.config.ts +1 -0
- 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();
|
package/tsdoc-metadata.json
CHANGED
package/vitest.config.ts
CHANGED
|
@@ -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.
|