@alloy-js/typescript 0.22.0-dev.2 → 0.22.0-dev.4
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/dist/src/components/MemberExpression.d.ts +6 -1
- package/dist/src/components/MemberExpression.d.ts.map +1 -1
- package/dist/src/components/MemberExpression.js +27 -8
- package/dist/src/components/MemberExpression.js.map +1 -1
- package/dist/src/components/PackageJson.d.ts +2 -0
- package/dist/src/components/PackageJson.d.ts.map +1 -1
- package/dist/src/components/PackageJson.js +1 -0
- package/dist/src/components/PackageJson.js.map +1 -1
- package/dist/test/member-expression.test.js +95 -0
- package/dist/test/member-expression.test.js.map +1 -1
- package/dist/test/package-json.test.js +6 -0
- package/dist/test/package-json.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/MemberExpression.tsx +44 -8
- package/src/components/PackageJson.tsx +4 -0
- package/temp/api.json +60 -1
- package/test/member-expression.test.tsx +78 -0
- package/test/package-json.test.tsx +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alloy-js/typescript",
|
|
3
|
-
"version": "0.22.0-dev.
|
|
3
|
+
"version": "0.22.0-dev.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"author": "brian.terlson@microsoft.com",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@alloy-js/core": "~0.21.0 || >= 0.22.0-dev.
|
|
25
|
+
"@alloy-js/core": "~0.21.0 || >= 0.22.0-dev.4",
|
|
26
26
|
"change-case": "^5.4.4",
|
|
27
27
|
"pathe": "^2.0.3"
|
|
28
28
|
},
|
|
@@ -35,6 +35,10 @@ interface PartDescriptorBase {
|
|
|
35
35
|
nullish: boolean;
|
|
36
36
|
type: boolean;
|
|
37
37
|
args?: Children[];
|
|
38
|
+
/**
|
|
39
|
+
* Whether to await the value that results from this part of the member expression.
|
|
40
|
+
*/
|
|
41
|
+
await?: boolean;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
type PartDescriptor = PartDescriptorWithId | PartDescriptorWithIndex;
|
|
@@ -47,7 +51,8 @@ type PartDescriptor = PartDescriptorWithId | PartDescriptorWithIndex;
|
|
|
47
51
|
* * **refkey**: a refkey for a symbol whose name becomes the identifier
|
|
48
52
|
* * **symbol**: a symbol whose name becomes the identifier part
|
|
49
53
|
* * **args**: create a method call with the given args
|
|
50
|
-
* * **children**: arbitrary contents for the identifier part
|
|
54
|
+
* * **children**: arbitrary contents for the identifier part
|
|
55
|
+
* * **await**: whether to await the value that results from this part of the member expression
|
|
51
56
|
*
|
|
52
57
|
* Each part can have a nullish prop, which indicates that the part may be null
|
|
53
58
|
* or undefined.
|
|
@@ -88,6 +93,10 @@ export function MemberExpression(props: MemberExpressionProps): Children {
|
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
const isCallChain = computed(() => {
|
|
96
|
+
for (const part of parts) {
|
|
97
|
+
if (part.await) return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
91
100
|
let callCount = 0;
|
|
92
101
|
for (const part of parts) {
|
|
93
102
|
if (part.args !== undefined) callCount++;
|
|
@@ -247,6 +256,7 @@ function createPartDescriptorFromProps(
|
|
|
247
256
|
(symbolSource.value as TSOutputSymbol).isTypeSymbol
|
|
248
257
|
);
|
|
249
258
|
}),
|
|
259
|
+
await: computed(() => partProps.await),
|
|
250
260
|
};
|
|
251
261
|
|
|
252
262
|
return reactive(part);
|
|
@@ -389,27 +399,47 @@ function formatCallChain(parts: PartDescriptor[]): Children {
|
|
|
389
399
|
|
|
390
400
|
function formatNonCallChain(parts: PartDescriptor[]): Children {
|
|
391
401
|
return computed(() => {
|
|
392
|
-
|
|
402
|
+
let expression: Children = [];
|
|
393
403
|
|
|
394
404
|
for (let i = 0; i < parts.length; i++) {
|
|
395
405
|
const part = parts[i];
|
|
396
406
|
const base = isIdPartDescriptor(part) ? part.id : part.index;
|
|
397
407
|
if (i === 0) {
|
|
398
|
-
expression.push(base);
|
|
408
|
+
(expression as Children[]).push(base);
|
|
399
409
|
} else {
|
|
400
410
|
// Determine if we should use nullish operator from previous part
|
|
401
411
|
const prevPart = parts[i - 1];
|
|
412
|
+
let partExpr;
|
|
402
413
|
|
|
403
414
|
if (prevPart.type) {
|
|
404
|
-
|
|
415
|
+
partExpr = formatArrayAccess(prevPart, part);
|
|
405
416
|
} else if (part.args !== undefined) {
|
|
406
417
|
// For parts with only args (no name), append function call directly with appropriate nullish operator
|
|
407
|
-
|
|
418
|
+
partExpr = formatCallExpr(prevPart, part);
|
|
408
419
|
} else if (part.accessStyle === "dot") {
|
|
409
|
-
|
|
420
|
+
partExpr = formatDotAccess(prevPart, part);
|
|
410
421
|
} else {
|
|
411
422
|
// bracket notation - don't include the dot
|
|
412
|
-
|
|
423
|
+
partExpr = formatArrayAccess(prevPart, part);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (Array.isArray(expression)) {
|
|
427
|
+
expression.push(partExpr);
|
|
428
|
+
} else {
|
|
429
|
+
expression = (
|
|
430
|
+
<>
|
|
431
|
+
{expression}
|
|
432
|
+
{partExpr}
|
|
433
|
+
</>
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (part.await) {
|
|
439
|
+
if (i < parts.length - 1) {
|
|
440
|
+
expression = <>(await {expression})</>;
|
|
441
|
+
} else {
|
|
442
|
+
expression = <>await {expression}</>;
|
|
413
443
|
}
|
|
414
444
|
}
|
|
415
445
|
}
|
|
@@ -524,6 +554,11 @@ export interface MemberExpressionPartProps {
|
|
|
524
554
|
*/
|
|
525
555
|
args?: Children[] | boolean;
|
|
526
556
|
|
|
557
|
+
/**
|
|
558
|
+
* Whether to await the value that results from this part of the member expression.
|
|
559
|
+
*/
|
|
560
|
+
await?: boolean;
|
|
561
|
+
|
|
527
562
|
/**
|
|
528
563
|
* This part is nullish. Subsequent parts use conditional access operators.
|
|
529
564
|
*/
|
|
@@ -543,7 +578,8 @@ export interface MemberExpressionPartProps {
|
|
|
543
578
|
* * **refkey**: A refkey for a symbol whose name becomes the identifier
|
|
544
579
|
* * **symbol**: a symbol whose name becomes the identifier part
|
|
545
580
|
* * **args**: create a method call with the given args
|
|
546
|
-
* * **children**: arbitrary contents for the identifier part
|
|
581
|
+
* * **children**: arbitrary contents for the identifier part
|
|
582
|
+
* * **await**: whether to await the value that results from this part of the member expression
|
|
547
583
|
*
|
|
548
584
|
* Each part can have a nullish prop, which indicates that the part may be null
|
|
549
585
|
* or undefined.
|
|
@@ -43,6 +43,9 @@ export interface PackageJsonFileProps {
|
|
|
43
43
|
/** The dev dependencies of the package. */
|
|
44
44
|
devDependencies?: Record<string, string>;
|
|
45
45
|
|
|
46
|
+
/** The peer dependencies of the package. */
|
|
47
|
+
peerDependencies?: Record<string, string>;
|
|
48
|
+
|
|
46
49
|
/** The scripts entries of the package. */
|
|
47
50
|
scripts?: Record<string, string>;
|
|
48
51
|
}
|
|
@@ -93,6 +96,7 @@ export function PackageJsonFile(props: PackageJsonFileProps) {
|
|
|
93
96
|
])
|
|
94
97
|
: undefined,
|
|
95
98
|
devDependencies: props.devDependencies,
|
|
99
|
+
peerDependencies: props.peerDependencies,
|
|
96
100
|
scripts: props.scripts,
|
|
97
101
|
exports: undefined as any,
|
|
98
102
|
};
|
package/temp/api.json
CHANGED
|
@@ -8692,7 +8692,7 @@
|
|
|
8692
8692
|
{
|
|
8693
8693
|
"kind": "Function",
|
|
8694
8694
|
"canonicalReference": "@alloy-js/typescript!MemberExpression:function(1)",
|
|
8695
|
-
"docComment": "/**\n * Create a member expression from parts. Each part can provide one of\n * the following:\n *\n * * **id**: The identifier for the member expression part\n * * **refkey**: a refkey for a symbol whose name becomes the identifier\n * * **symbol**: a symbol whose name becomes the identifier part\n * * **args**: create a method call with the given args\n * * **children**: arbitrary contents for the identifier part
|
|
8695
|
+
"docComment": "/**\n * Create a member expression from parts. Each part can provide one of\n * the following:\n *\n * * **id**: The identifier for the member expression part\n * * **refkey**: a refkey for a symbol whose name becomes the identifier\n * * **symbol**: a symbol whose name becomes the identifier part\n * * **args**: create a method call with the given args\n * * **children**: arbitrary contents for the identifier part\n * * **await**: whether to await the value that results from this part of the member expression\n *\n * Each part can have a nullish prop, which indicates that the part may be null\n * or undefined.\n *\n * Each part can also have a quoteId prop, which indicates that the identifier\n * of the part should be quoted (i.e. `[\"foo\"]` instead of `.foo`). This is only\n * necessary when providing the children prop, otherwise it is determined\n * automatically.\n *\n * @example\n *\n *\n *\n * ```tsx\n * <MemberExpression>\n * <MemberExpression.Part id=\"base\" />\n * <MemberExpression.Part refkey={rk} nullish />\n * <MemberExpression.Part symbol={sym} />\n * <MemberExpression.Part args={[\"hello\", \"world\"]} />\n * <MemberExpression.Part>SomeValue</MemberExpression.Part>\n * </MemberExpression>\n * ```\n *\n *\n * Assuming `rk` is a refkey to a symbol name \"prop1\", and `sym` is a symbol\n * with a name of \"prop2\", this will render:\n *\n * ```ts\n * base.prop1?.prop2(\"hello\", \"world\").SomeValue\n * ```\n *\n */\n",
|
|
8696
8696
|
"excerptTokens": [
|
|
8697
8697
|
{
|
|
8698
8698
|
"kind": "Content",
|
|
@@ -8841,6 +8841,33 @@
|
|
|
8841
8841
|
"endIndex": 3
|
|
8842
8842
|
}
|
|
8843
8843
|
},
|
|
8844
|
+
{
|
|
8845
|
+
"kind": "PropertySignature",
|
|
8846
|
+
"canonicalReference": "@alloy-js/typescript!MemberExpressionPartProps#await:member",
|
|
8847
|
+
"docComment": "/**\n * Whether to await the value that results from this part of the member expression.\n */\n",
|
|
8848
|
+
"excerptTokens": [
|
|
8849
|
+
{
|
|
8850
|
+
"kind": "Content",
|
|
8851
|
+
"text": "await?: "
|
|
8852
|
+
},
|
|
8853
|
+
{
|
|
8854
|
+
"kind": "Content",
|
|
8855
|
+
"text": "boolean"
|
|
8856
|
+
},
|
|
8857
|
+
{
|
|
8858
|
+
"kind": "Content",
|
|
8859
|
+
"text": ";"
|
|
8860
|
+
}
|
|
8861
|
+
],
|
|
8862
|
+
"isReadonly": false,
|
|
8863
|
+
"isOptional": true,
|
|
8864
|
+
"releaseTag": "Public",
|
|
8865
|
+
"name": "await",
|
|
8866
|
+
"propertyTypeTokenRange": {
|
|
8867
|
+
"startIndex": 1,
|
|
8868
|
+
"endIndex": 2
|
|
8869
|
+
}
|
|
8870
|
+
},
|
|
8844
8871
|
{
|
|
8845
8872
|
"kind": "PropertySignature",
|
|
8846
8873
|
"canonicalReference": "@alloy-js/typescript!MemberExpressionPartProps#children:member",
|
|
@@ -12109,6 +12136,38 @@
|
|
|
12109
12136
|
"endIndex": 2
|
|
12110
12137
|
}
|
|
12111
12138
|
},
|
|
12139
|
+
{
|
|
12140
|
+
"kind": "PropertySignature",
|
|
12141
|
+
"canonicalReference": "@alloy-js/typescript!PackageJsonFileProps#peerDependencies:member",
|
|
12142
|
+
"docComment": "/**\n * The peer dependencies of the package.\n */\n",
|
|
12143
|
+
"excerptTokens": [
|
|
12144
|
+
{
|
|
12145
|
+
"kind": "Content",
|
|
12146
|
+
"text": "peerDependencies?: "
|
|
12147
|
+
},
|
|
12148
|
+
{
|
|
12149
|
+
"kind": "Reference",
|
|
12150
|
+
"text": "Record",
|
|
12151
|
+
"canonicalReference": "!Record:type"
|
|
12152
|
+
},
|
|
12153
|
+
{
|
|
12154
|
+
"kind": "Content",
|
|
12155
|
+
"text": "<string, string>"
|
|
12156
|
+
},
|
|
12157
|
+
{
|
|
12158
|
+
"kind": "Content",
|
|
12159
|
+
"text": ";"
|
|
12160
|
+
}
|
|
12161
|
+
],
|
|
12162
|
+
"isReadonly": false,
|
|
12163
|
+
"isOptional": true,
|
|
12164
|
+
"releaseTag": "Public",
|
|
12165
|
+
"name": "peerDependencies",
|
|
12166
|
+
"propertyTypeTokenRange": {
|
|
12167
|
+
"startIndex": 1,
|
|
12168
|
+
"endIndex": 3
|
|
12169
|
+
}
|
|
12170
|
+
},
|
|
12112
12171
|
{
|
|
12113
12172
|
"kind": "PropertySignature",
|
|
12114
12173
|
"canonicalReference": "@alloy-js/typescript!PackageJsonFileProps#repository:member",
|
|
@@ -760,3 +760,81 @@ describe("formatting", () => {
|
|
|
760
760
|
});
|
|
761
761
|
});
|
|
762
762
|
});
|
|
763
|
+
|
|
764
|
+
describe("with await", () => {
|
|
765
|
+
it("renders member expression with await", () => {
|
|
766
|
+
expect(
|
|
767
|
+
toSourceText(
|
|
768
|
+
<MemberExpression>
|
|
769
|
+
<MemberExpression.Part id="foo" />
|
|
770
|
+
<MemberExpression.Part id="bar" />
|
|
771
|
+
<MemberExpression.Part args await />
|
|
772
|
+
<MemberExpression.Part id="baz" />
|
|
773
|
+
</MemberExpression>,
|
|
774
|
+
),
|
|
775
|
+
).toBe(d`
|
|
776
|
+
(await foo.bar()).baz
|
|
777
|
+
`);
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
it("renders member expression with await at the end", () => {
|
|
781
|
+
expect(
|
|
782
|
+
toSourceText(
|
|
783
|
+
<MemberExpression>
|
|
784
|
+
<MemberExpression.Part id="foo" />
|
|
785
|
+
<MemberExpression.Part id="bar" />
|
|
786
|
+
<MemberExpression.Part args await />
|
|
787
|
+
</MemberExpression>,
|
|
788
|
+
),
|
|
789
|
+
).toBe(d`
|
|
790
|
+
await foo.bar()
|
|
791
|
+
`);
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
it("renders member expression with await in the middle of property access", () => {
|
|
795
|
+
expect(
|
|
796
|
+
toSourceText(
|
|
797
|
+
<MemberExpression>
|
|
798
|
+
<MemberExpression.Part id="foo" />
|
|
799
|
+
<MemberExpression.Part id="bar" await />
|
|
800
|
+
<MemberExpression.Part id="baz" />
|
|
801
|
+
</MemberExpression>,
|
|
802
|
+
),
|
|
803
|
+
).toBe(d`
|
|
804
|
+
(await foo.bar).baz
|
|
805
|
+
`);
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
it("renders member expression with multiple awaits", () => {
|
|
809
|
+
expect(
|
|
810
|
+
toSourceText(
|
|
811
|
+
<MemberExpression>
|
|
812
|
+
<MemberExpression.Part id="foo" />
|
|
813
|
+
<MemberExpression.Part id="bar" await />
|
|
814
|
+
<MemberExpression.Part id="baz" await />
|
|
815
|
+
<MemberExpression.Part id="qux" />
|
|
816
|
+
</MemberExpression>,
|
|
817
|
+
),
|
|
818
|
+
).toBe(d`
|
|
819
|
+
(await (await foo.bar).baz).qux
|
|
820
|
+
`);
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
it("renders member expression with await and call chain (disables formatting)", () => {
|
|
824
|
+
expect(
|
|
825
|
+
toSourceText(
|
|
826
|
+
<MemberExpression>
|
|
827
|
+
<MemberExpression.Part id="foo" />
|
|
828
|
+
<MemberExpression.Part id="bar" />
|
|
829
|
+
<MemberExpression.Part args />
|
|
830
|
+
<MemberExpression.Part id="baz" />
|
|
831
|
+
<MemberExpression.Part args await />
|
|
832
|
+
<MemberExpression.Part id="qux" />
|
|
833
|
+
<MemberExpression.Part args />
|
|
834
|
+
</MemberExpression>,
|
|
835
|
+
),
|
|
836
|
+
).toBe(d`
|
|
837
|
+
(await foo.bar().baz()).qux()
|
|
838
|
+
`);
|
|
839
|
+
});
|
|
840
|
+
});
|
|
@@ -44,6 +44,9 @@ it("makes a complex package.json", () => {
|
|
|
44
44
|
devDependencies={{
|
|
45
45
|
typescript: "^5.5.2",
|
|
46
46
|
}}
|
|
47
|
+
peerDependencies={{
|
|
48
|
+
zod: "^4.1.0",
|
|
49
|
+
}}
|
|
47
50
|
exports={{
|
|
48
51
|
".": "./lib/index.js",
|
|
49
52
|
"./complex": {
|
|
@@ -70,6 +73,9 @@ it("makes a complex package.json", () => {
|
|
|
70
73
|
"devDependencies": {
|
|
71
74
|
"typescript": "^5.5.2"
|
|
72
75
|
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"zod": "^4.1.0"
|
|
78
|
+
},
|
|
73
79
|
"scripts": {
|
|
74
80
|
"build": "tsc -p .",
|
|
75
81
|
"test": "vitest run",
|