Skip to content

Commit af737be

Browse files
committed
Rename IntrinsicNode's name to intrinsic and add new name (alias) property
1 parent f4c6227 commit af737be

File tree

43 files changed

+306
-300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+306
-300
lines changed

src/models/types/compoundTypeUtils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,26 @@ export function deduplicateMemberTypes(types: TypeNode[]): TypeNode[] {
2828
return x.value;
2929
}
3030

31-
if (x instanceof IntrinsicNode || x instanceof ReferenceNode) {
31+
if (x instanceof ReferenceNode) {
3232
return x.name;
3333
}
3434

35+
if (x instanceof IntrinsicNode) {
36+
return x.name ?? x.intrinsic;
37+
}
38+
3539
return x;
3640
});
3741
}
3842

3943
export function sortMemberTypes(members: TypeNode[]) {
4044
// move undefined and null to the end
4145

42-
const nullIndex = members.findIndex((x) => x instanceof IntrinsicNode && x.name === 'null');
46+
const nullIndex = members.findIndex((x) => x instanceof IntrinsicNode && x.intrinsic === 'null');
4347
members.push(members.splice(nullIndex, 1)[0]);
4448

4549
const undefinedIndex = members.findIndex(
46-
(x) => x instanceof IntrinsicNode && x.name === 'undefined',
50+
(x) => x instanceof IntrinsicNode && x.intrinsic === 'undefined',
4751
);
4852
members.push(members.splice(undefinedIndex, 1)[0]);
4953
}

src/models/types/intrinsic.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ type IntrinsicType =
1515
export class IntrinsicNode implements TypeNode {
1616
kind = 'intrinsic';
1717
parentNamespaces: string[];
18-
name: IntrinsicType;
19-
alias: string | undefined;
18+
intrinsic: IntrinsicType;
19+
name: string | undefined;
2020

2121
constructor(
22-
name: IntrinsicType,
23-
alias: string | undefined = undefined,
22+
intrinsic: IntrinsicType,
23+
name: string | undefined = undefined,
2424
parentNamespaces: string[] = [],
2525
) {
26+
this.intrinsic = intrinsic;
2627
this.name = name;
27-
this.alias = alias;
2828
this.parentNamespaces = parentNamespaces;
2929
}
3030
}

src/parsers/componentParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ function squashComponentProps(callSignatures: CallSignature[], context: ParserCo
135135
function markPropertyAsOptional(property: PropertyNode, context: ParserContext) {
136136
const canBeUndefined =
137137
property.type instanceof UnionNode &&
138-
property.type.types.some((type) => type instanceof IntrinsicNode && type.name === 'undefined');
138+
property.type.types.some(
139+
(type) => type instanceof IntrinsicNode && type.intrinsic === 'undefined',
140+
);
139141

140142
const { compilerOptions } = context;
141143
if (!canBeUndefined && !compilerOptions.exactOptionalPropertyTypes) {

test/aliases/output.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
"type": {
5656
"kind": "intrinsic",
5757
"parentNamespaces": [],
58-
"name": "any",
59-
"alias": "AliasedAny"
58+
"intrinsic": "any",
59+
"name": "AliasedAny"
6060
},
6161
"name": "n",
6262
"optional": false
@@ -65,8 +65,8 @@
6565
"type": {
6666
"kind": "intrinsic",
6767
"parentNamespaces": [],
68-
"name": "unknown",
69-
"alias": "AliasedUnknown"
68+
"intrinsic": "unknown",
69+
"name": "AliasedUnknown"
7070
},
7171
"name": "u",
7272
"optional": false
@@ -95,7 +95,7 @@
9595
{
9696
"kind": "intrinsic",
9797
"parentNamespaces": [],
98-
"name": "undefined"
98+
"intrinsic": "undefined"
9999
}
100100
]
101101
},
@@ -115,7 +115,7 @@
115115
{
116116
"kind": "intrinsic",
117117
"parentNamespaces": [],
118-
"name": "undefined"
118+
"intrinsic": "undefined"
119119
}
120120
]
121121
},
@@ -135,7 +135,7 @@
135135
{
136136
"kind": "intrinsic",
137137
"parentNamespaces": [],
138-
"name": "undefined"
138+
"intrinsic": "undefined"
139139
}
140140
]
141141
},
@@ -146,8 +146,8 @@
146146
"type": {
147147
"kind": "intrinsic",
148148
"parentNamespaces": [],
149-
"name": "any",
150-
"alias": "AliasedAny"
149+
"intrinsic": "any",
150+
"name": "AliasedAny"
151151
},
152152
"name": "on",
153153
"optional": true
@@ -156,8 +156,8 @@
156156
"type": {
157157
"kind": "intrinsic",
158158
"parentNamespaces": [],
159-
"name": "unknown",
160-
"alias": "AliasedUnknown"
159+
"intrinsic": "unknown",
160+
"name": "AliasedUnknown"
161161
},
162162
"name": "ou",
163163
"optional": true
@@ -166,7 +166,7 @@
166166
"returnValueType": {
167167
"kind": "intrinsic",
168168
"parentNamespaces": [],
169-
"name": "void"
169+
"intrinsic": "void"
170170
}
171171
}
172172
]
@@ -225,8 +225,8 @@
225225
"type": {
226226
"kind": "intrinsic",
227227
"parentNamespaces": [],
228-
"name": "any",
229-
"alias": "AliasedAny"
228+
"intrinsic": "any",
229+
"name": "AliasedAny"
230230
},
231231
"optional": false
232232
},
@@ -235,8 +235,8 @@
235235
"type": {
236236
"kind": "intrinsic",
237237
"parentNamespaces": [],
238-
"name": "unknown",
239-
"alias": "AliasedUnknown"
238+
"intrinsic": "unknown",
239+
"name": "AliasedUnknown"
240240
},
241241
"optional": false
242242
},
@@ -265,7 +265,7 @@
265265
{
266266
"kind": "intrinsic",
267267
"parentNamespaces": [],
268-
"name": "undefined"
268+
"intrinsic": "undefined"
269269
}
270270
]
271271
},
@@ -285,7 +285,7 @@
285285
{
286286
"kind": "intrinsic",
287287
"parentNamespaces": [],
288-
"name": "undefined"
288+
"intrinsic": "undefined"
289289
}
290290
]
291291
},
@@ -305,7 +305,7 @@
305305
{
306306
"kind": "intrinsic",
307307
"parentNamespaces": [],
308-
"name": "undefined"
308+
"intrinsic": "undefined"
309309
}
310310
]
311311
},
@@ -316,8 +316,8 @@
316316
"type": {
317317
"kind": "intrinsic",
318318
"parentNamespaces": [],
319-
"name": "any",
320-
"alias": "AliasedAny"
319+
"intrinsic": "any",
320+
"name": "AliasedAny"
321321
},
322322
"optional": true
323323
},
@@ -326,8 +326,8 @@
326326
"type": {
327327
"kind": "intrinsic",
328328
"parentNamespaces": [],
329-
"name": "unknown",
330-
"alias": "AliasedUnknown"
329+
"intrinsic": "unknown",
330+
"name": "AliasedUnknown"
331331
},
332332
"optional": true
333333
}

test/arrays/output.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"elementType": {
2525
"kind": "intrinsic",
2626
"parentNamespaces": [],
27-
"name": "string"
27+
"intrinsic": "string"
2828
}
2929
},
3030
"optional": false
@@ -37,7 +37,7 @@
3737
"elementType": {
3838
"kind": "intrinsic",
3939
"parentNamespaces": [],
40-
"name": "number"
40+
"intrinsic": "number"
4141
}
4242
},
4343
"optional": false
@@ -53,13 +53,13 @@
5353
"elementType": {
5454
"kind": "intrinsic",
5555
"parentNamespaces": [],
56-
"name": "string"
56+
"intrinsic": "string"
5757
}
5858
},
5959
{
6060
"kind": "intrinsic",
6161
"parentNamespaces": [],
62-
"name": "undefined"
62+
"intrinsic": "undefined"
6363
}
6464
]
6565
},
@@ -76,13 +76,13 @@
7676
"elementType": {
7777
"kind": "intrinsic",
7878
"parentNamespaces": [],
79-
"name": "number"
79+
"intrinsic": "number"
8080
}
8181
},
8282
{
8383
"kind": "intrinsic",
8484
"parentNamespaces": [],
85-
"name": "undefined"
85+
"intrinsic": "undefined"
8686
}
8787
]
8888
},
@@ -97,7 +97,7 @@
9797
"returnValueType": {
9898
"kind": "intrinsic",
9999
"parentNamespaces": [],
100-
"name": "void"
100+
"intrinsic": "void"
101101
}
102102
}
103103
]
@@ -119,7 +119,7 @@
119119
"elementType": {
120120
"kind": "intrinsic",
121121
"parentNamespaces": [],
122-
"name": "string"
122+
"intrinsic": "string"
123123
}
124124
},
125125
"name": "a1",
@@ -132,7 +132,7 @@
132132
"elementType": {
133133
"kind": "intrinsic",
134134
"parentNamespaces": [],
135-
"name": "number"
135+
"intrinsic": "number"
136136
}
137137
},
138138
"name": "a2",
@@ -142,7 +142,7 @@
142142
"returnValueType": {
143143
"kind": "intrinsic",
144144
"parentNamespaces": [],
145-
"name": "void"
145+
"intrinsic": "void"
146146
}
147147
}
148148
]

0 commit comments

Comments
 (0)