@alloy-js/typescript 0.21.0-dev.9 → 0.22.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 +25 -0
- package/dist/src/components/CallSignature.d.ts.map +1 -1
- package/dist/src/components/CallSignature.js +6 -1
- package/dist/src/components/CallSignature.js.map +1 -1
- package/dist/src/components/ObjectExpression.d.ts +2 -2
- package/dist/src/components/ObjectExpression.d.ts.map +1 -1
- package/dist/src/components/ObjectExpression.js +24 -17
- package/dist/src/components/ObjectExpression.js.map +1 -1
- package/dist/src/components/PropertyName.d.ts.map +1 -1
- package/dist/src/components/PropertyName.js +7 -5
- package/dist/src/components/PropertyName.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/test/function-declaration.test.js +46 -3
- package/dist/test/function-declaration.test.js.map +1 -1
- package/dist/test/object.test.js +34 -2
- package/dist/test/object.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/CallSignature.tsx +5 -1
- package/src/components/ObjectExpression.tsx +19 -15
- package/src/components/PropertyName.tsx +7 -5
- package/src/components/index.ts +1 -0
- package/temp/api.json +100 -2
- package/test/function-declaration.test.tsx +37 -0
- package/test/object.test.tsx +25 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/typescript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0-dev.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"author": "brian.terlson@microsoft.com",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@alloy-js/core": "~0.
|
|
25
|
+
"@alloy-js/core": "~0.21.0 || >= 0.22.0-dev.0",
|
|
26
26
|
"change-case": "^5.4.4",
|
|
27
27
|
"pathe": "^2.0.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@alloy-js/cli": "~0.
|
|
30
|
+
"@alloy-js/cli": "~0.21.0 || >= 0.22.0-dev.0",
|
|
31
31
|
"@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.0",
|
|
32
32
|
"@microsoft/api-extractor": "~7.52.8",
|
|
33
33
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
TypeParameterDescriptor,
|
|
5
5
|
} from "../parameter-descriptor.js";
|
|
6
6
|
import { FunctionDeclaration } from "./FunctionDeclaration.jsx";
|
|
7
|
+
import { TypeRefContext } from "./TypeRefContext.jsx";
|
|
7
8
|
|
|
8
9
|
export interface CallSignatureProps {
|
|
9
10
|
/**
|
|
@@ -57,7 +58,10 @@ export function CallSignature(props: CallSignatureProps) {
|
|
|
57
58
|
<FunctionDeclaration.Parameters parameters={props.parameters} />
|
|
58
59
|
);
|
|
59
60
|
|
|
60
|
-
const sReturnType =
|
|
61
|
+
const sReturnType =
|
|
62
|
+
props.returnType ?
|
|
63
|
+
<TypeRefContext>: {props.returnType}</TypeRefContext>
|
|
64
|
+
: undefined;
|
|
61
65
|
|
|
62
66
|
return (
|
|
63
67
|
<>
|
|
@@ -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,
|
|
@@ -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
|
-
|
|
109
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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) {
|
package/src/components/index.ts
CHANGED
|
@@ -32,6 +32,7 @@ export * from "./ObjectExpression.js";
|
|
|
32
32
|
export * from "./PackageDirectory.js";
|
|
33
33
|
export * from "./PackageJson.js";
|
|
34
34
|
export * from "./Reference.js";
|
|
35
|
+
export * from "./SingleLineCommentBlock.jsx";
|
|
35
36
|
export * from "./SourceFile.js";
|
|
36
37
|
export * from "./SwitchStatement.jsx";
|
|
37
38
|
export * from "./TsConfigJson.js";
|
package/temp/api.json
CHANGED
|
@@ -10845,7 +10845,12 @@
|
|
|
10845
10845
|
},
|
|
10846
10846
|
{
|
|
10847
10847
|
"kind": "Content",
|
|
10848
|
-
"text": "string"
|
|
10848
|
+
"text": "string | "
|
|
10849
|
+
},
|
|
10850
|
+
{
|
|
10851
|
+
"kind": "Reference",
|
|
10852
|
+
"text": "Namekey",
|
|
10853
|
+
"canonicalReference": "@alloy-js/core!Namekey:interface"
|
|
10849
10854
|
},
|
|
10850
10855
|
{
|
|
10851
10856
|
"kind": "Content",
|
|
@@ -10858,7 +10863,7 @@
|
|
|
10858
10863
|
"name": "name",
|
|
10859
10864
|
"propertyTypeTokenRange": {
|
|
10860
10865
|
"startIndex": 1,
|
|
10861
|
-
"endIndex":
|
|
10866
|
+
"endIndex": 3
|
|
10862
10867
|
}
|
|
10863
10868
|
},
|
|
10864
10869
|
{
|
|
@@ -12601,6 +12606,99 @@
|
|
|
12601
12606
|
],
|
|
12602
12607
|
"extendsTokenRanges": []
|
|
12603
12608
|
},
|
|
12609
|
+
{
|
|
12610
|
+
"kind": "Function",
|
|
12611
|
+
"canonicalReference": "@alloy-js/typescript!SingleLineCommentBlock:function(1)",
|
|
12612
|
+
"docComment": "/**\n * A single line comment block. The children are rendered as a prose element, which means that they\n * are broken into multiple lines\n */\n",
|
|
12613
|
+
"excerptTokens": [
|
|
12614
|
+
{
|
|
12615
|
+
"kind": "Content",
|
|
12616
|
+
"text": "export declare function SingleLineCommentBlock(props: "
|
|
12617
|
+
},
|
|
12618
|
+
{
|
|
12619
|
+
"kind": "Reference",
|
|
12620
|
+
"text": "SingleLineCommentBlockProps",
|
|
12621
|
+
"canonicalReference": "@alloy-js/typescript!SingleLineCommentBlockProps:interface"
|
|
12622
|
+
},
|
|
12623
|
+
{
|
|
12624
|
+
"kind": "Content",
|
|
12625
|
+
"text": "): "
|
|
12626
|
+
},
|
|
12627
|
+
{
|
|
12628
|
+
"kind": "Reference",
|
|
12629
|
+
"text": "Children",
|
|
12630
|
+
"canonicalReference": "@alloy-js/core!Children:type"
|
|
12631
|
+
},
|
|
12632
|
+
{
|
|
12633
|
+
"kind": "Content",
|
|
12634
|
+
"text": ";"
|
|
12635
|
+
}
|
|
12636
|
+
],
|
|
12637
|
+
"fileUrlPath": "src/components/SingleLineCommentBlock.tsx",
|
|
12638
|
+
"returnTypeTokenRange": {
|
|
12639
|
+
"startIndex": 3,
|
|
12640
|
+
"endIndex": 4
|
|
12641
|
+
},
|
|
12642
|
+
"releaseTag": "Public",
|
|
12643
|
+
"overloadIndex": 1,
|
|
12644
|
+
"parameters": [
|
|
12645
|
+
{
|
|
12646
|
+
"parameterName": "props",
|
|
12647
|
+
"parameterTypeTokenRange": {
|
|
12648
|
+
"startIndex": 1,
|
|
12649
|
+
"endIndex": 2
|
|
12650
|
+
},
|
|
12651
|
+
"isOptional": false
|
|
12652
|
+
}
|
|
12653
|
+
],
|
|
12654
|
+
"name": "SingleLineCommentBlock"
|
|
12655
|
+
},
|
|
12656
|
+
{
|
|
12657
|
+
"kind": "Interface",
|
|
12658
|
+
"canonicalReference": "@alloy-js/typescript!SingleLineCommentBlockProps:interface",
|
|
12659
|
+
"docComment": "",
|
|
12660
|
+
"excerptTokens": [
|
|
12661
|
+
{
|
|
12662
|
+
"kind": "Content",
|
|
12663
|
+
"text": "export interface SingleLineCommentBlockProps "
|
|
12664
|
+
}
|
|
12665
|
+
],
|
|
12666
|
+
"fileUrlPath": "src/components/SingleLineCommentBlock.tsx",
|
|
12667
|
+
"releaseTag": "Public",
|
|
12668
|
+
"name": "SingleLineCommentBlockProps",
|
|
12669
|
+
"preserveMemberOrder": false,
|
|
12670
|
+
"members": [
|
|
12671
|
+
{
|
|
12672
|
+
"kind": "PropertySignature",
|
|
12673
|
+
"canonicalReference": "@alloy-js/typescript!SingleLineCommentBlockProps#children:member",
|
|
12674
|
+
"docComment": "",
|
|
12675
|
+
"excerptTokens": [
|
|
12676
|
+
{
|
|
12677
|
+
"kind": "Content",
|
|
12678
|
+
"text": "children: "
|
|
12679
|
+
},
|
|
12680
|
+
{
|
|
12681
|
+
"kind": "Reference",
|
|
12682
|
+
"text": "Children",
|
|
12683
|
+
"canonicalReference": "@alloy-js/core!Children:type"
|
|
12684
|
+
},
|
|
12685
|
+
{
|
|
12686
|
+
"kind": "Content",
|
|
12687
|
+
"text": ";"
|
|
12688
|
+
}
|
|
12689
|
+
],
|
|
12690
|
+
"isReadonly": false,
|
|
12691
|
+
"isOptional": false,
|
|
12692
|
+
"releaseTag": "Public",
|
|
12693
|
+
"name": "children",
|
|
12694
|
+
"propertyTypeTokenRange": {
|
|
12695
|
+
"startIndex": 1,
|
|
12696
|
+
"endIndex": 2
|
|
12697
|
+
}
|
|
12698
|
+
}
|
|
12699
|
+
],
|
|
12700
|
+
"extendsTokenRanges": []
|
|
12701
|
+
},
|
|
12604
12702
|
{
|
|
12605
12703
|
"kind": "Interface",
|
|
12606
12704
|
"canonicalReference": "@alloy-js/typescript!SourceDirectoryData:interface",
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
List,
|
|
3
3
|
memberRefkey,
|
|
4
4
|
namekey,
|
|
5
|
+
Output,
|
|
5
6
|
Props,
|
|
6
7
|
refkey,
|
|
7
8
|
StatementList,
|
|
@@ -14,6 +15,8 @@ import {
|
|
|
14
15
|
FunctionDeclaration,
|
|
15
16
|
InterfaceDeclaration,
|
|
16
17
|
InterfaceMember,
|
|
18
|
+
SourceFile,
|
|
19
|
+
TypeDeclaration,
|
|
17
20
|
VarDeclaration,
|
|
18
21
|
} from "../src/index.js";
|
|
19
22
|
import { ParameterDescriptor } from "../src/parameter-descriptor.js";
|
|
@@ -386,3 +389,37 @@ describe("symbols", () => {
|
|
|
386
389
|
`);
|
|
387
390
|
});
|
|
388
391
|
});
|
|
392
|
+
|
|
393
|
+
it("has parameters and return type in type ref context", () => {
|
|
394
|
+
const i1 = namekey("iface1");
|
|
395
|
+
const i2 = namekey("iface2");
|
|
396
|
+
const template = (
|
|
397
|
+
<Output>
|
|
398
|
+
<SourceFile path="test1.ts">
|
|
399
|
+
<TypeDeclaration name={i1}>any</TypeDeclaration>
|
|
400
|
+
<hbr />
|
|
401
|
+
<TypeDeclaration name={i2}>any</TypeDeclaration>
|
|
402
|
+
</SourceFile>
|
|
403
|
+
|
|
404
|
+
<SourceFile path="test2.ts">
|
|
405
|
+
<FunctionDeclaration
|
|
406
|
+
name="foo"
|
|
407
|
+
parameters={[{ name: "a", type: i1 }]}
|
|
408
|
+
returnType={i2}
|
|
409
|
+
/>
|
|
410
|
+
</SourceFile>
|
|
411
|
+
</Output>
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
expect(template).toRenderTo({
|
|
415
|
+
"test1.ts": `
|
|
416
|
+
type iface1 = any;
|
|
417
|
+
type iface2 = any;
|
|
418
|
+
`,
|
|
419
|
+
"test2.ts": `
|
|
420
|
+
import type { iface1, iface2 } from "./test1.js";
|
|
421
|
+
|
|
422
|
+
function foo(a: iface1): iface2 {}
|
|
423
|
+
`,
|
|
424
|
+
});
|
|
425
|
+
});
|
package/test/object.test.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { List } from "@alloy-js/core";
|
|
1
|
+
import { List, namekey } from "@alloy-js/core";
|
|
2
2
|
import { d } from "@alloy-js/core/testing";
|
|
3
3
|
import { expect, it } from "vitest";
|
|
4
4
|
import {
|
|
5
|
+
CommaList,
|
|
5
6
|
ObjectExpression,
|
|
6
7
|
ObjectProperty,
|
|
7
8
|
ObjectSpreadProperty,
|
|
@@ -61,3 +62,26 @@ it("Works with both children and jsvalue", () => {
|
|
|
61
62
|
}
|
|
62
63
|
`);
|
|
63
64
|
});
|
|
65
|
+
|
|
66
|
+
it("Handles name conflicts and namekeys", () => {
|
|
67
|
+
const nk1 = namekey("a");
|
|
68
|
+
const nk2 = namekey("a");
|
|
69
|
+
const nk3 = namekey("a", { ignoreNameConflict: true });
|
|
70
|
+
|
|
71
|
+
const comp = (
|
|
72
|
+
<ObjectExpression>
|
|
73
|
+
<CommaList>
|
|
74
|
+
<ObjectProperty name={nk1} value={3} />
|
|
75
|
+
<ObjectProperty name={nk2} value={1} />
|
|
76
|
+
<ObjectProperty name={nk3} value={1} />
|
|
77
|
+
</CommaList>
|
|
78
|
+
</ObjectExpression>
|
|
79
|
+
);
|
|
80
|
+
expect(toSourceText(comp)).toBe(d`
|
|
81
|
+
{
|
|
82
|
+
a: 3,
|
|
83
|
+
a_2: 1,
|
|
84
|
+
a: 1,
|
|
85
|
+
}
|
|
86
|
+
`);
|
|
87
|
+
});
|