2
2
import type { FuncCallNode } from '../nodeTypes'
3
3
import { Scope } from './scope'
4
4
import { walk } from './typeEvaluate'
5
- import { mapConcrete , nullUnion } from './typeHelpers'
5
+ import { mapNode , nullUnion } from './typeHelpers'
6
6
import type { NullTypeNode , TypeNode } from './types'
7
7
8
8
function unionWithoutNull ( unionTypeNode : TypeNode ) : TypeNode {
@@ -21,15 +21,15 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
21
21
case 'array.compact' : {
22
22
const arg = walk ( { node : node . args [ 0 ] , scope} )
23
23
24
- return mapConcrete ( arg , scope , ( arg ) => {
24
+ return mapNode ( arg , scope , ( arg ) => {
25
25
if ( arg . type === 'unknown' ) {
26
26
return nullUnion ( { type : 'array' , of : { type : 'unknown' } } )
27
27
}
28
28
if ( arg . type !== 'array' ) {
29
29
return { type : 'null' }
30
30
}
31
31
32
- const of = mapConcrete ( arg . of , scope , ( of ) => of )
32
+ const of = mapNode ( arg . of , scope , ( of ) => of )
33
33
return {
34
34
type : 'array' ,
35
35
of : unionWithoutNull ( of ) ,
@@ -41,16 +41,16 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
41
41
const arrayArg = walk ( { node : node . args [ 0 ] , scope} )
42
42
const sepArg = walk ( { node : node . args [ 1 ] , scope} )
43
43
44
- return mapConcrete ( arrayArg , scope , ( arrayArg ) =>
45
- mapConcrete ( sepArg , scope , ( sepArg ) => {
44
+ return mapNode ( arrayArg , scope , ( arrayArg ) =>
45
+ mapNode ( sepArg , scope , ( sepArg ) => {
46
46
if ( arrayArg . type === 'unknown' || sepArg . type === 'unknown' ) {
47
47
return nullUnion ( { type : 'string' } )
48
48
}
49
49
if ( arrayArg . type !== 'array' || sepArg . type !== 'string' ) {
50
50
return { type : 'null' }
51
51
}
52
52
53
- return mapConcrete ( arrayArg . of , scope , ( of ) => {
53
+ return mapNode ( arrayArg . of , scope , ( of ) => {
54
54
if ( of . type === 'unknown' ) {
55
55
return nullUnion ( { type : 'string' } )
56
56
}
@@ -68,7 +68,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
68
68
case 'array.unique' : {
69
69
const arg = walk ( { node : node . args [ 0 ] , scope} )
70
70
71
- return mapConcrete ( arg , scope , ( arg ) => {
71
+ return mapNode ( arg , scope , ( arg ) => {
72
72
if ( arg . type === 'unknown' ) {
73
73
return nullUnion ( { type : 'array' , of : { type : 'unknown' } } )
74
74
}
@@ -83,7 +83,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
83
83
case 'global.lower' : {
84
84
const arg = walk ( { node : node . args [ 0 ] , scope} )
85
85
86
- return mapConcrete ( arg , scope , ( arg ) => {
86
+ return mapNode ( arg , scope , ( arg ) => {
87
87
if ( arg . type === 'unknown' ) {
88
88
return nullUnion ( { type : 'string' } )
89
89
}
@@ -103,7 +103,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
103
103
case 'global.upper' : {
104
104
const arg = walk ( { node : node . args [ 0 ] , scope} )
105
105
106
- return mapConcrete ( arg , scope , ( arg ) => {
106
+ return mapNode ( arg , scope , ( arg ) => {
107
107
if ( arg . type === 'unknown' ) {
108
108
return nullUnion ( { type : 'string' } )
109
109
}
@@ -130,7 +130,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
130
130
}
131
131
case 'global.path' : {
132
132
const arg = walk ( { node : node . args [ 0 ] , scope} )
133
- return mapConcrete ( arg , scope , ( arg ) => {
133
+ return mapNode ( arg , scope , ( arg ) => {
134
134
if ( arg . type === 'unknown' ) {
135
135
return nullUnion ( { type : 'string' } )
136
136
}
@@ -168,7 +168,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
168
168
case 'global.count' : {
169
169
const arg = walk ( { node : node . args [ 0 ] , scope} )
170
170
171
- return mapConcrete ( arg , scope , ( arg ) => {
171
+ return mapNode ( arg , scope , ( arg ) => {
172
172
if ( arg . type === 'unknown' ) {
173
173
return nullUnion ( { type : 'string' } )
174
174
}
@@ -184,7 +184,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
184
184
case 'global.dateTime' : {
185
185
const arg = walk ( { node : node . args [ 0 ] , scope} )
186
186
187
- return mapConcrete ( arg , scope , ( arg ) => {
187
+ return mapNode ( arg , scope , ( arg ) => {
188
188
if ( arg . type === 'unknown' ) {
189
189
return nullUnion ( { type : 'string' } )
190
190
}
@@ -200,7 +200,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
200
200
case 'global.length' : {
201
201
const arg = walk ( { node : node . args [ 0 ] , scope} )
202
202
203
- return mapConcrete ( arg , scope , ( arg ) => {
203
+ return mapNode ( arg , scope , ( arg ) => {
204
204
if ( arg . type === 'unknown' ) {
205
205
return nullUnion ( { type : 'number' } )
206
206
}
@@ -219,7 +219,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
219
219
case 'global.round' : {
220
220
const numNode = walk ( { node : node . args [ 0 ] , scope} )
221
221
222
- return mapConcrete ( numNode , scope , ( num ) => {
222
+ return mapNode ( numNode , scope , ( num ) => {
223
223
if ( num . type === 'unknown' ) {
224
224
return nullUnion ( { type : 'number' } )
225
225
}
@@ -229,7 +229,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
229
229
}
230
230
if ( node . args . length === 2 ) {
231
231
const precisionNode = walk ( { node : node . args [ 1 ] , scope} )
232
- return mapConcrete ( precisionNode , scope , ( precision ) => {
232
+ return mapNode ( precisionNode , scope , ( precision ) => {
233
233
if ( precision . type === 'unknown' ) {
234
234
return nullUnion ( { type : 'number' } )
235
235
}
@@ -248,7 +248,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
248
248
249
249
case 'global.string' : {
250
250
const arg = walk ( { node : node . args [ 0 ] , scope} )
251
- return mapConcrete ( arg , scope , ( node ) => {
251
+ return mapNode ( arg , scope , ( node ) => {
252
252
if ( node . type === 'unknown' ) {
253
253
return nullUnion ( { type : 'string' } )
254
254
}
@@ -272,8 +272,8 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
272
272
273
273
case 'math.sum' : {
274
274
const values = walk ( { node : node . args [ 0 ] , scope} )
275
- // use mapConcrete to get concrete resolved value, it will also handle cases where the value is a union
276
- return mapConcrete ( values , scope , ( node ) => {
275
+ // use mapNode to get concrete resolved value, it will also handle cases where the value is a union
276
+ return mapNode ( values , scope , ( node ) => {
277
277
if ( node . type === 'unknown' ) {
278
278
return nullUnion ( { type : 'number' } )
279
279
}
@@ -284,7 +284,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
284
284
}
285
285
286
286
// Resolve the concrete type of the array elements
287
- return mapConcrete ( node . of , scope , ( node ) => {
287
+ return mapNode ( node . of , scope , ( node ) => {
288
288
if ( node . type === 'unknown' ) {
289
289
return nullUnion ( { type : 'number' } )
290
290
}
@@ -300,8 +300,8 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
300
300
301
301
case 'math.avg' : {
302
302
const values = walk ( { node : node . args [ 0 ] , scope} )
303
- // use mapConcrete to get concrete resolved value, it will also handle cases where the value is a union
304
- return mapConcrete ( values , scope , ( node ) => {
303
+ // use mapNode to get concrete resolved value, it will also handle cases where the value is a union
304
+ return mapNode ( values , scope , ( node ) => {
305
305
if ( node . type === 'unknown' ) {
306
306
return nullUnion ( { type : 'number' } )
307
307
}
@@ -311,7 +311,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
311
311
return { type : 'null' }
312
312
}
313
313
// Resolve the concrete type of the array elements
314
- return mapConcrete ( node . of , scope , ( node ) => {
314
+ return mapNode ( node . of , scope , ( node ) => {
315
315
if ( node . type === 'unknown' ) {
316
316
return nullUnion ( { type : 'number' } )
317
317
}
@@ -328,8 +328,8 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
328
328
case 'math.max' :
329
329
case 'math.min' : {
330
330
const values = walk ( { node : node . args [ 0 ] , scope} )
331
- // use mapConcrete to get concrete resolved value, it will also handle cases where the value is a union
332
- return mapConcrete ( values , scope , ( node ) => {
331
+ // use mapNode to get concrete resolved value, it will also handle cases where the value is a union
332
+ return mapNode ( values , scope , ( node ) => {
333
333
if ( node . type === 'unknown' ) {
334
334
return nullUnion ( { type : 'number' } )
335
335
}
@@ -340,7 +340,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
340
340
}
341
341
342
342
// Resolve the concrete type of the array elements
343
- return mapConcrete ( node . of , scope , ( node ) => {
343
+ return mapNode ( node . of , scope , ( node ) => {
344
344
if ( node . type === 'unknown' ) {
345
345
return nullUnion ( { type : 'number' } )
346
346
}
@@ -366,8 +366,8 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
366
366
case 'string.startsWith' : {
367
367
const strTypeNode = walk ( { node : node . args [ 0 ] , scope} )
368
368
const prefixTypeNode = walk ( { node : node . args [ 1 ] , scope} )
369
- return mapConcrete ( strTypeNode , scope , ( strNode ) => {
370
- return mapConcrete ( prefixTypeNode , scope , ( prefixNode ) => {
369
+ return mapNode ( strTypeNode , scope , ( strNode ) => {
370
+ return mapNode ( prefixTypeNode , scope , ( prefixNode ) => {
371
371
if ( strNode . type === 'unknown' || prefixNode . type === 'unknown' ) {
372
372
return nullUnion ( { type : 'boolean' } )
373
373
}
@@ -383,8 +383,8 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
383
383
case 'string.split' : {
384
384
const strTypeNode = walk ( { node : node . args [ 0 ] , scope} )
385
385
const sepTypeNode = walk ( { node : node . args [ 1 ] , scope} )
386
- return mapConcrete ( strTypeNode , scope , ( strNode ) => {
387
- return mapConcrete ( sepTypeNode , scope , ( sepNode ) => {
386
+ return mapNode ( strTypeNode , scope , ( strNode ) => {
387
+ return mapNode ( sepTypeNode , scope , ( sepNode ) => {
388
388
if ( strNode . type === 'unknown' || sepNode . type === 'unknown' ) {
389
389
return nullUnion ( { type : 'array' , of : { type : 'string' } } )
390
390
}
@@ -399,7 +399,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
399
399
}
400
400
case 'sanity.versionOf' : {
401
401
const typeNode = walk ( { node : node . args [ 0 ] , scope} )
402
- return mapConcrete ( typeNode , scope , ( typeNode ) => {
402
+ return mapNode ( typeNode , scope , ( typeNode ) => {
403
403
if ( typeNode . type === 'unknown' ) {
404
404
return nullUnion ( { type : 'array' , of : { type : 'string' } } )
405
405
}
@@ -411,7 +411,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
411
411
}
412
412
case 'sanity.documentsOf' : {
413
413
const typeNode = walk ( { node : node . args [ 0 ] , scope} )
414
- return mapConcrete ( typeNode , scope , ( typeNode ) => {
414
+ return mapNode ( typeNode , scope , ( typeNode ) => {
415
415
if ( typeNode . type === 'unknown' ) {
416
416
return nullUnion ( { type : 'array' , of : { type : 'string' } } )
417
417
}
0 commit comments