@alloy-js/typescript 0.22.0-dev.0 → 0.22.0-dev.2
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/ClassDeclaration.d.ts +1 -0
- package/dist/src/components/ClassDeclaration.d.ts.map +1 -1
- package/dist/src/components/ClassDeclaration.js +10 -2
- package/dist/src/components/ClassDeclaration.js.map +1 -1
- package/dist/src/symbols/index.d.ts +7 -1
- package/dist/src/symbols/index.d.ts.map +1 -1
- package/dist/src/symbols/index.js +32 -1
- package/dist/src/symbols/index.js.map +1 -1
- package/dist/test/class.test.js +28 -0
- package/dist/test/class.test.js.map +1 -1
- package/dist/test/decl-helpers.test.d.ts +2 -0
- package/dist/test/decl-helpers.test.d.ts.map +1 -0
- package/dist/test/decl-helpers.test.js +153 -0
- package/dist/test/decl-helpers.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/ClassDeclaration.tsx +13 -1
- package/src/symbols/index.ts +51 -2
- package/temp/api.json +266 -2
- package/test/class.test.tsx +37 -0
- package/test/decl-helpers.test.tsx +129 -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.2",
|
|
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.3",
|
|
26
26
|
"change-case": "^5.4.4",
|
|
27
27
|
"pathe": "^2.0.3"
|
|
28
28
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Block,
|
|
3
3
|
Children,
|
|
4
|
+
For,
|
|
4
5
|
MemberDeclaration,
|
|
5
6
|
Name,
|
|
6
7
|
Namekey,
|
|
@@ -28,6 +29,7 @@ import { TypeRefContext } from "./TypeRefContext.jsx";
|
|
|
28
29
|
|
|
29
30
|
export interface ClassDeclarationProps extends CommonDeclarationProps {
|
|
30
31
|
extends?: Children;
|
|
32
|
+
implements?: Children[];
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -65,6 +67,15 @@ export interface ClassDeclarationProps extends CommonDeclarationProps {
|
|
|
65
67
|
*/
|
|
66
68
|
export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
67
69
|
const extendsPart = props.extends && <> extends {props.extends}</>;
|
|
70
|
+
const implementsPart = props.implements && props.implements.length > 0 && (
|
|
71
|
+
<>
|
|
72
|
+
{" "}
|
|
73
|
+
implements{" "}
|
|
74
|
+
<For each={props.implements} comma space>
|
|
75
|
+
{(implement) => implement}
|
|
76
|
+
</For>
|
|
77
|
+
</>
|
|
78
|
+
);
|
|
68
79
|
const sym = createTypeAndValueSymbol(props.name, {
|
|
69
80
|
refkeys: props.refkey,
|
|
70
81
|
export: props.export,
|
|
@@ -83,7 +94,8 @@ export function ClassDeclaration(props: ClassDeclarationProps) {
|
|
|
83
94
|
<Declaration symbol={sym} export={props.export} default={props.default}>
|
|
84
95
|
<MemberScope ownerSymbol={sym}>
|
|
85
96
|
class <Name />
|
|
86
|
-
{extendsPart}
|
|
97
|
+
{extendsPart}
|
|
98
|
+
{implementsPart} <Block>{props.children}</Block>
|
|
87
99
|
</MemberScope>
|
|
88
100
|
</Declaration>
|
|
89
101
|
</>
|
package/src/symbols/index.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
createComponent,
|
|
3
|
+
Namekey,
|
|
4
|
+
onCleanup,
|
|
5
|
+
OutputScopeOptions,
|
|
6
|
+
toRef,
|
|
7
|
+
} from "@alloy-js/core";
|
|
2
8
|
import { useLexicalScope, useMemberOwner } from "../utils.js";
|
|
3
9
|
import { useTSScope } from "./scopes.js";
|
|
4
10
|
import { TSLexicalScope } from "./ts-lexical-scope.js";
|
|
@@ -24,7 +30,7 @@ export function createTypeAndValueSymbol(
|
|
|
24
30
|
|
|
25
31
|
export function createTypeSymbol(
|
|
26
32
|
name: string | Namekey,
|
|
27
|
-
options: CreateTsSymbolOptions,
|
|
33
|
+
options: CreateTsSymbolOptions = {},
|
|
28
34
|
) {
|
|
29
35
|
const scope = useLexicalScope();
|
|
30
36
|
if (scope && !scope.types) {
|
|
@@ -125,3 +131,46 @@ export function createMemberScope(
|
|
|
125
131
|
const parent = useTSScope();
|
|
126
132
|
return new TSMemberScope(name, parent, ownerSymbol, options);
|
|
127
133
|
}
|
|
134
|
+
|
|
135
|
+
export function decl(namekey: Namekey, options?: CreateTsSymbolOptions) {
|
|
136
|
+
return createComponent(() => {
|
|
137
|
+
const symbol = createValueSymbol(namekey, options);
|
|
138
|
+
|
|
139
|
+
onCleanup(() => {
|
|
140
|
+
symbol.delete();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
return toRef(symbol, "name");
|
|
144
|
+
}, {});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function declType(namekey: Namekey, options?: CreateTsSymbolOptions) {
|
|
148
|
+
return createComponent(() => {
|
|
149
|
+
const symbol = createTypeSymbol(namekey, options);
|
|
150
|
+
|
|
151
|
+
onCleanup(() => {
|
|
152
|
+
symbol.delete();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return toRef(symbol, "name");
|
|
156
|
+
}, {});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function declMember(
|
|
160
|
+
namekey: Namekey,
|
|
161
|
+
locationOptions: { jsPrivate?: boolean; static?: boolean } = {},
|
|
162
|
+
options?: CreateTsSymbolOptions,
|
|
163
|
+
) {
|
|
164
|
+
// Create the symbol inside a component so that we only get these side
|
|
165
|
+
// effects when this function is rendered (and not from something like
|
|
166
|
+
// children()/childrenArray() invoking the memo) and we get cleanup logic.
|
|
167
|
+
return createComponent(() => {
|
|
168
|
+
const symbol = createMemberSymbol(namekey, locationOptions, options);
|
|
169
|
+
|
|
170
|
+
onCleanup(() => {
|
|
171
|
+
symbol.delete();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return toRef(symbol, "name");
|
|
175
|
+
}, {});
|
|
176
|
+
}
|
package/temp/api.json
CHANGED
|
@@ -1695,6 +1695,38 @@
|
|
|
1695
1695
|
"startIndex": 1,
|
|
1696
1696
|
"endIndex": 2
|
|
1697
1697
|
}
|
|
1698
|
+
},
|
|
1699
|
+
{
|
|
1700
|
+
"kind": "PropertySignature",
|
|
1701
|
+
"canonicalReference": "@alloy-js/typescript!ClassDeclarationProps#implements:member",
|
|
1702
|
+
"docComment": "",
|
|
1703
|
+
"excerptTokens": [
|
|
1704
|
+
{
|
|
1705
|
+
"kind": "Content",
|
|
1706
|
+
"text": "implements?: "
|
|
1707
|
+
},
|
|
1708
|
+
{
|
|
1709
|
+
"kind": "Reference",
|
|
1710
|
+
"text": "Children",
|
|
1711
|
+
"canonicalReference": "@alloy-js/core!Children:type"
|
|
1712
|
+
},
|
|
1713
|
+
{
|
|
1714
|
+
"kind": "Content",
|
|
1715
|
+
"text": "[]"
|
|
1716
|
+
},
|
|
1717
|
+
{
|
|
1718
|
+
"kind": "Content",
|
|
1719
|
+
"text": ";"
|
|
1720
|
+
}
|
|
1721
|
+
],
|
|
1722
|
+
"isReadonly": false,
|
|
1723
|
+
"isOptional": true,
|
|
1724
|
+
"releaseTag": "Public",
|
|
1725
|
+
"name": "implements",
|
|
1726
|
+
"propertyTypeTokenRange": {
|
|
1727
|
+
"startIndex": 1,
|
|
1728
|
+
"endIndex": 3
|
|
1729
|
+
}
|
|
1698
1730
|
}
|
|
1699
1731
|
],
|
|
1700
1732
|
"extendsTokenRanges": [
|
|
@@ -3572,7 +3604,7 @@
|
|
|
3572
3604
|
},
|
|
3573
3605
|
{
|
|
3574
3606
|
"kind": "Content",
|
|
3575
|
-
"text": ", options
|
|
3607
|
+
"text": ", options?: "
|
|
3576
3608
|
},
|
|
3577
3609
|
{
|
|
3578
3610
|
"kind": "Reference",
|
|
@@ -3615,7 +3647,7 @@
|
|
|
3615
3647
|
"startIndex": 4,
|
|
3616
3648
|
"endIndex": 5
|
|
3617
3649
|
},
|
|
3618
|
-
"isOptional":
|
|
3650
|
+
"isOptional": true
|
|
3619
3651
|
}
|
|
3620
3652
|
],
|
|
3621
3653
|
"name": "createTypeSymbol"
|
|
@@ -3688,6 +3720,78 @@
|
|
|
3688
3720
|
],
|
|
3689
3721
|
"name": "createValueSymbol"
|
|
3690
3722
|
},
|
|
3723
|
+
{
|
|
3724
|
+
"kind": "Function",
|
|
3725
|
+
"canonicalReference": "@alloy-js/typescript!decl:function(1)",
|
|
3726
|
+
"docComment": "",
|
|
3727
|
+
"excerptTokens": [
|
|
3728
|
+
{
|
|
3729
|
+
"kind": "Content",
|
|
3730
|
+
"text": "export declare function decl(namekey: "
|
|
3731
|
+
},
|
|
3732
|
+
{
|
|
3733
|
+
"kind": "Reference",
|
|
3734
|
+
"text": "Namekey",
|
|
3735
|
+
"canonicalReference": "@alloy-js/core!Namekey:interface"
|
|
3736
|
+
},
|
|
3737
|
+
{
|
|
3738
|
+
"kind": "Content",
|
|
3739
|
+
"text": ", options?: "
|
|
3740
|
+
},
|
|
3741
|
+
{
|
|
3742
|
+
"kind": "Reference",
|
|
3743
|
+
"text": "CreateTsSymbolOptions",
|
|
3744
|
+
"canonicalReference": "@alloy-js/typescript!CreateTsSymbolOptions:interface"
|
|
3745
|
+
},
|
|
3746
|
+
{
|
|
3747
|
+
"kind": "Content",
|
|
3748
|
+
"text": "): "
|
|
3749
|
+
},
|
|
3750
|
+
{
|
|
3751
|
+
"kind": "Content",
|
|
3752
|
+
"text": "import(\"@alloy-js/core\")."
|
|
3753
|
+
},
|
|
3754
|
+
{
|
|
3755
|
+
"kind": "Reference",
|
|
3756
|
+
"text": "ComponentCreator",
|
|
3757
|
+
"canonicalReference": "@alloy-js/core!ComponentCreator:interface"
|
|
3758
|
+
},
|
|
3759
|
+
{
|
|
3760
|
+
"kind": "Content",
|
|
3761
|
+
"text": "<{}>"
|
|
3762
|
+
},
|
|
3763
|
+
{
|
|
3764
|
+
"kind": "Content",
|
|
3765
|
+
"text": ";"
|
|
3766
|
+
}
|
|
3767
|
+
],
|
|
3768
|
+
"fileUrlPath": "src/symbols/index.ts",
|
|
3769
|
+
"returnTypeTokenRange": {
|
|
3770
|
+
"startIndex": 5,
|
|
3771
|
+
"endIndex": 8
|
|
3772
|
+
},
|
|
3773
|
+
"releaseTag": "Public",
|
|
3774
|
+
"overloadIndex": 1,
|
|
3775
|
+
"parameters": [
|
|
3776
|
+
{
|
|
3777
|
+
"parameterName": "namekey",
|
|
3778
|
+
"parameterTypeTokenRange": {
|
|
3779
|
+
"startIndex": 1,
|
|
3780
|
+
"endIndex": 2
|
|
3781
|
+
},
|
|
3782
|
+
"isOptional": false
|
|
3783
|
+
},
|
|
3784
|
+
{
|
|
3785
|
+
"parameterName": "options",
|
|
3786
|
+
"parameterTypeTokenRange": {
|
|
3787
|
+
"startIndex": 3,
|
|
3788
|
+
"endIndex": 4
|
|
3789
|
+
},
|
|
3790
|
+
"isOptional": true
|
|
3791
|
+
}
|
|
3792
|
+
],
|
|
3793
|
+
"name": "decl"
|
|
3794
|
+
},
|
|
3691
3795
|
{
|
|
3692
3796
|
"kind": "Function",
|
|
3693
3797
|
"canonicalReference": "@alloy-js/typescript!Declaration:function(1)",
|
|
@@ -4151,6 +4255,166 @@
|
|
|
4151
4255
|
}
|
|
4152
4256
|
]
|
|
4153
4257
|
},
|
|
4258
|
+
{
|
|
4259
|
+
"kind": "Function",
|
|
4260
|
+
"canonicalReference": "@alloy-js/typescript!declMember:function(1)",
|
|
4261
|
+
"docComment": "",
|
|
4262
|
+
"excerptTokens": [
|
|
4263
|
+
{
|
|
4264
|
+
"kind": "Content",
|
|
4265
|
+
"text": "export declare function declMember(namekey: "
|
|
4266
|
+
},
|
|
4267
|
+
{
|
|
4268
|
+
"kind": "Reference",
|
|
4269
|
+
"text": "Namekey",
|
|
4270
|
+
"canonicalReference": "@alloy-js/core!Namekey:interface"
|
|
4271
|
+
},
|
|
4272
|
+
{
|
|
4273
|
+
"kind": "Content",
|
|
4274
|
+
"text": ", locationOptions?: "
|
|
4275
|
+
},
|
|
4276
|
+
{
|
|
4277
|
+
"kind": "Content",
|
|
4278
|
+
"text": "{\n jsPrivate?: boolean;\n static?: boolean;\n}"
|
|
4279
|
+
},
|
|
4280
|
+
{
|
|
4281
|
+
"kind": "Content",
|
|
4282
|
+
"text": ", options?: "
|
|
4283
|
+
},
|
|
4284
|
+
{
|
|
4285
|
+
"kind": "Reference",
|
|
4286
|
+
"text": "CreateTsSymbolOptions",
|
|
4287
|
+
"canonicalReference": "@alloy-js/typescript!CreateTsSymbolOptions:interface"
|
|
4288
|
+
},
|
|
4289
|
+
{
|
|
4290
|
+
"kind": "Content",
|
|
4291
|
+
"text": "): "
|
|
4292
|
+
},
|
|
4293
|
+
{
|
|
4294
|
+
"kind": "Content",
|
|
4295
|
+
"text": "import(\"@alloy-js/core\")."
|
|
4296
|
+
},
|
|
4297
|
+
{
|
|
4298
|
+
"kind": "Reference",
|
|
4299
|
+
"text": "ComponentCreator",
|
|
4300
|
+
"canonicalReference": "@alloy-js/core!ComponentCreator:interface"
|
|
4301
|
+
},
|
|
4302
|
+
{
|
|
4303
|
+
"kind": "Content",
|
|
4304
|
+
"text": "<{}>"
|
|
4305
|
+
},
|
|
4306
|
+
{
|
|
4307
|
+
"kind": "Content",
|
|
4308
|
+
"text": ";"
|
|
4309
|
+
}
|
|
4310
|
+
],
|
|
4311
|
+
"fileUrlPath": "src/symbols/index.ts",
|
|
4312
|
+
"returnTypeTokenRange": {
|
|
4313
|
+
"startIndex": 7,
|
|
4314
|
+
"endIndex": 10
|
|
4315
|
+
},
|
|
4316
|
+
"releaseTag": "Public",
|
|
4317
|
+
"overloadIndex": 1,
|
|
4318
|
+
"parameters": [
|
|
4319
|
+
{
|
|
4320
|
+
"parameterName": "namekey",
|
|
4321
|
+
"parameterTypeTokenRange": {
|
|
4322
|
+
"startIndex": 1,
|
|
4323
|
+
"endIndex": 2
|
|
4324
|
+
},
|
|
4325
|
+
"isOptional": false
|
|
4326
|
+
},
|
|
4327
|
+
{
|
|
4328
|
+
"parameterName": "locationOptions",
|
|
4329
|
+
"parameterTypeTokenRange": {
|
|
4330
|
+
"startIndex": 3,
|
|
4331
|
+
"endIndex": 4
|
|
4332
|
+
},
|
|
4333
|
+
"isOptional": true
|
|
4334
|
+
},
|
|
4335
|
+
{
|
|
4336
|
+
"parameterName": "options",
|
|
4337
|
+
"parameterTypeTokenRange": {
|
|
4338
|
+
"startIndex": 5,
|
|
4339
|
+
"endIndex": 6
|
|
4340
|
+
},
|
|
4341
|
+
"isOptional": true
|
|
4342
|
+
}
|
|
4343
|
+
],
|
|
4344
|
+
"name": "declMember"
|
|
4345
|
+
},
|
|
4346
|
+
{
|
|
4347
|
+
"kind": "Function",
|
|
4348
|
+
"canonicalReference": "@alloy-js/typescript!declType:function(1)",
|
|
4349
|
+
"docComment": "",
|
|
4350
|
+
"excerptTokens": [
|
|
4351
|
+
{
|
|
4352
|
+
"kind": "Content",
|
|
4353
|
+
"text": "export declare function declType(namekey: "
|
|
4354
|
+
},
|
|
4355
|
+
{
|
|
4356
|
+
"kind": "Reference",
|
|
4357
|
+
"text": "Namekey",
|
|
4358
|
+
"canonicalReference": "@alloy-js/core!Namekey:interface"
|
|
4359
|
+
},
|
|
4360
|
+
{
|
|
4361
|
+
"kind": "Content",
|
|
4362
|
+
"text": ", options?: "
|
|
4363
|
+
},
|
|
4364
|
+
{
|
|
4365
|
+
"kind": "Reference",
|
|
4366
|
+
"text": "CreateTsSymbolOptions",
|
|
4367
|
+
"canonicalReference": "@alloy-js/typescript!CreateTsSymbolOptions:interface"
|
|
4368
|
+
},
|
|
4369
|
+
{
|
|
4370
|
+
"kind": "Content",
|
|
4371
|
+
"text": "): "
|
|
4372
|
+
},
|
|
4373
|
+
{
|
|
4374
|
+
"kind": "Content",
|
|
4375
|
+
"text": "import(\"@alloy-js/core\")."
|
|
4376
|
+
},
|
|
4377
|
+
{
|
|
4378
|
+
"kind": "Reference",
|
|
4379
|
+
"text": "ComponentCreator",
|
|
4380
|
+
"canonicalReference": "@alloy-js/core!ComponentCreator:interface"
|
|
4381
|
+
},
|
|
4382
|
+
{
|
|
4383
|
+
"kind": "Content",
|
|
4384
|
+
"text": "<{}>"
|
|
4385
|
+
},
|
|
4386
|
+
{
|
|
4387
|
+
"kind": "Content",
|
|
4388
|
+
"text": ";"
|
|
4389
|
+
}
|
|
4390
|
+
],
|
|
4391
|
+
"fileUrlPath": "src/symbols/index.ts",
|
|
4392
|
+
"returnTypeTokenRange": {
|
|
4393
|
+
"startIndex": 5,
|
|
4394
|
+
"endIndex": 8
|
|
4395
|
+
},
|
|
4396
|
+
"releaseTag": "Public",
|
|
4397
|
+
"overloadIndex": 1,
|
|
4398
|
+
"parameters": [
|
|
4399
|
+
{
|
|
4400
|
+
"parameterName": "namekey",
|
|
4401
|
+
"parameterTypeTokenRange": {
|
|
4402
|
+
"startIndex": 1,
|
|
4403
|
+
"endIndex": 2
|
|
4404
|
+
},
|
|
4405
|
+
"isOptional": false
|
|
4406
|
+
},
|
|
4407
|
+
{
|
|
4408
|
+
"parameterName": "options",
|
|
4409
|
+
"parameterTypeTokenRange": {
|
|
4410
|
+
"startIndex": 3,
|
|
4411
|
+
"endIndex": 4
|
|
4412
|
+
},
|
|
4413
|
+
"isOptional": true
|
|
4414
|
+
}
|
|
4415
|
+
],
|
|
4416
|
+
"name": "declType"
|
|
4417
|
+
},
|
|
4154
4418
|
{
|
|
4155
4419
|
"kind": "Function",
|
|
4156
4420
|
"canonicalReference": "@alloy-js/typescript!ElseClause:function(1)",
|
package/test/class.test.tsx
CHANGED
|
@@ -27,6 +27,43 @@ it("creates extends", () => {
|
|
|
27
27
|
`);
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
it("creates implements", () => {
|
|
31
|
+
const res = toSourceText(
|
|
32
|
+
<ts.ClassDeclaration name="Foo" implements={["SomeInterface"]} />,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(res).toEqual(d`
|
|
36
|
+
class Foo implements SomeInterface {}
|
|
37
|
+
`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("creates implements with multiple", () => {
|
|
41
|
+
const res = toSourceText(
|
|
42
|
+
<ts.ClassDeclaration
|
|
43
|
+
name="Foo"
|
|
44
|
+
implements={["SomeInterface", "OtherInterface"]}
|
|
45
|
+
/>,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
expect(res).toEqual(d`
|
|
49
|
+
class Foo implements SomeInterface, OtherInterface {}
|
|
50
|
+
`);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("creates implements with extends", () => {
|
|
54
|
+
const res = toSourceText(
|
|
55
|
+
<ts.ClassDeclaration
|
|
56
|
+
name="Foo"
|
|
57
|
+
extends="string"
|
|
58
|
+
implements={["SomeInterface"]}
|
|
59
|
+
/>,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(res).toEqual(d`
|
|
63
|
+
class Foo extends string implements SomeInterface {}
|
|
64
|
+
`);
|
|
65
|
+
});
|
|
66
|
+
|
|
30
67
|
it("takes namekeys for all elements", () => {
|
|
31
68
|
const res = toSourceText(
|
|
32
69
|
<ts.ClassDeclaration name={namekey("foo")}>
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { code, namekey, Output } from "@alloy-js/core";
|
|
2
|
+
import "@alloy-js/core/testing";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as ts from "../src/index.js";
|
|
6
|
+
import { decl, declMember, declType } from "../src/symbols/index.js";
|
|
7
|
+
|
|
8
|
+
it("declares variables", () => {
|
|
9
|
+
const hi = namekey("hi");
|
|
10
|
+
|
|
11
|
+
expect(
|
|
12
|
+
<Output>
|
|
13
|
+
<ts.SourceFile path="test1.ts">
|
|
14
|
+
{code`
|
|
15
|
+
const ${decl(hi)} = 12;
|
|
16
|
+
console.log(${hi});
|
|
17
|
+
`}
|
|
18
|
+
</ts.SourceFile>
|
|
19
|
+
<ts.SourceFile path="test2.ts">{hi};</ts.SourceFile>
|
|
20
|
+
</Output>,
|
|
21
|
+
).toRenderTo({
|
|
22
|
+
"test1.ts": d`
|
|
23
|
+
const hi = 12;
|
|
24
|
+
console.log(hi);
|
|
25
|
+
`,
|
|
26
|
+
"test2.ts": d`
|
|
27
|
+
import { hi } from "./test1.js";
|
|
28
|
+
|
|
29
|
+
hi;
|
|
30
|
+
`,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("declares types", () => {
|
|
35
|
+
const hi = namekey("hi");
|
|
36
|
+
|
|
37
|
+
expect(
|
|
38
|
+
<Output>
|
|
39
|
+
<ts.SourceFile path="test1.ts">
|
|
40
|
+
{code`
|
|
41
|
+
interface ${declType(hi)} {
|
|
42
|
+
value: number;
|
|
43
|
+
}
|
|
44
|
+
`}
|
|
45
|
+
</ts.SourceFile>
|
|
46
|
+
<ts.SourceFile path="test2.ts">
|
|
47
|
+
<ts.VarDeclaration name="test" type={hi} />
|
|
48
|
+
</ts.SourceFile>
|
|
49
|
+
</Output>,
|
|
50
|
+
).toRenderTo({
|
|
51
|
+
"test1.ts": d`
|
|
52
|
+
interface hi {
|
|
53
|
+
value: number;
|
|
54
|
+
}
|
|
55
|
+
`,
|
|
56
|
+
"test2.ts": d`
|
|
57
|
+
import type { hi } from "./test1.js";
|
|
58
|
+
|
|
59
|
+
const test: hi
|
|
60
|
+
`,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("declares variables", () => {
|
|
65
|
+
const hi = namekey("hi");
|
|
66
|
+
|
|
67
|
+
expect(
|
|
68
|
+
<Output>
|
|
69
|
+
<ts.SourceFile path="test1.ts">
|
|
70
|
+
{code`
|
|
71
|
+
interface ${declType(hi)} {
|
|
72
|
+
value: number;
|
|
73
|
+
}
|
|
74
|
+
`}
|
|
75
|
+
</ts.SourceFile>
|
|
76
|
+
<ts.SourceFile path="test2.ts">
|
|
77
|
+
<ts.VarDeclaration name="test" type={hi} />
|
|
78
|
+
</ts.SourceFile>
|
|
79
|
+
</Output>,
|
|
80
|
+
).toRenderTo({
|
|
81
|
+
"test1.ts": d`
|
|
82
|
+
interface hi {
|
|
83
|
+
value: number;
|
|
84
|
+
}
|
|
85
|
+
`,
|
|
86
|
+
"test2.ts": d`
|
|
87
|
+
import type { hi } from "./test1.js";
|
|
88
|
+
|
|
89
|
+
const test: hi
|
|
90
|
+
`,
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("declares members", () => {
|
|
95
|
+
const publicMember = namekey("publicMember");
|
|
96
|
+
const privateMember = namekey("privateMember");
|
|
97
|
+
const staticMethod = namekey("staticMethod");
|
|
98
|
+
expect(
|
|
99
|
+
<Output>
|
|
100
|
+
<ts.SourceFile path="test1.ts">
|
|
101
|
+
<ts.ClassDeclaration name="Foo">
|
|
102
|
+
{code`
|
|
103
|
+
public ${declMember(publicMember)} = 12;
|
|
104
|
+
#${declMember(privateMember, { jsPrivate: true })} = 34;
|
|
105
|
+
constructor() {
|
|
106
|
+
${publicMember} = 24;
|
|
107
|
+
${privateMember} = 10;
|
|
108
|
+
}
|
|
109
|
+
`}
|
|
110
|
+
<hbr />
|
|
111
|
+
static ${declMember(staticMethod, { static: true })}() {"{}"};
|
|
112
|
+
</ts.ClassDeclaration>
|
|
113
|
+
<hbr />
|
|
114
|
+
{staticMethod}();
|
|
115
|
+
</ts.SourceFile>
|
|
116
|
+
</Output>,
|
|
117
|
+
).toRenderTo(d`
|
|
118
|
+
class Foo {
|
|
119
|
+
public publicMember = 12;
|
|
120
|
+
#privateMember = 34;
|
|
121
|
+
constructor() {
|
|
122
|
+
this.publicMember = 24;
|
|
123
|
+
this.#privateMember = 10;
|
|
124
|
+
}
|
|
125
|
+
static $staticMethod() {};
|
|
126
|
+
}
|
|
127
|
+
Foo.staticMethod();
|
|
128
|
+
`);
|
|
129
|
+
});
|