@@ -57,9 +57,11 @@ const bigIntExpressions = ({
57
57
58
58
const dateExpressions = ( {
59
59
dataExpression,
60
+ completeFieldSchema,
60
61
} : {
61
62
dataExpression ?: ts . Expression | string ;
62
- } ) : Array < ts . Expression > => {
63
+ completeFieldSchema : IR . SchemaObject [ ] ,
64
+ } ) : Array < ts . Expression | ts . Statement > => {
63
65
const identifierDate = compiler . identifier ( { text : 'Date' } ) ;
64
66
65
67
if ( typeof dataExpression === 'string' ) {
@@ -72,6 +74,25 @@ const dateExpressions = ({
72
74
}
73
75
74
76
if ( dataExpression ) {
77
+
78
+ if ( completeFieldSchema [ 1 ] ?. type === 'null' ) {
79
+ const ifStatement = ts . factory . createIfStatement (
80
+ ts . factory . createBinaryExpression (
81
+ dataExpression ,
82
+ ts . SyntaxKind . EqualsEqualsEqualsToken ,
83
+ ts . factory . createNull ( )
84
+ ) ,
85
+ ts . factory . createExpressionStatement (
86
+ ts . factory . createNewExpression (
87
+ identifierDate ,
88
+ undefined ,
89
+ [ dataExpression ]
90
+ )
91
+ ) ,
92
+ ) ;
93
+ return [ ifStatement ] ;
94
+ }
95
+
75
96
return [
76
97
compiler . assignment ( {
77
98
left : dataExpression ,
@@ -186,11 +207,13 @@ const processSchemaType = ({
186
207
dataExpression,
187
208
plugin,
188
209
schema,
210
+ completeFieldSchema,
189
211
} : {
190
212
context : IR . Context ;
191
213
dataExpression ?: ts . Expression | string ;
192
214
plugin : Plugin . Instance < Config > ;
193
215
schema : IR . SchemaObject ;
216
+ completeFieldSchema ?: IR . SchemaObject [ ] ;
194
217
} ) : Array < ts . Expression | ts . Statement > => {
195
218
const file = context . file ( { id : transformersId } ) ! ;
196
219
@@ -369,7 +392,7 @@ const processSchemaType = ({
369
392
schema . type === 'string' &&
370
393
( schema . format === 'date' || schema . format === 'date-time' )
371
394
) {
372
- return dateExpressions ( { dataExpression } ) ;
395
+ return dateExpressions ( { dataExpression, completeFieldSchema : completeFieldSchema ?? [ ] } ) ;
373
396
}
374
397
375
398
if ( plugin . bigInt && schema . type === 'integer' && schema . format === 'int64' ) {
@@ -382,7 +405,7 @@ const processSchemaType = ({
382
405
context,
383
406
dataExpression : 'item' ,
384
407
plugin,
385
- schema : schema . items [ 0 ] ! ,
408
+ schema : schema . items [ 0 ] !
386
409
} ) ;
387
410
}
388
411
@@ -401,6 +424,7 @@ const processSchemaType = ({
401
424
dataExpression : dataExpression || 'item' ,
402
425
plugin,
403
426
schema : item ,
427
+ completeFieldSchema : [ ...schema . items ] ,
404
428
} ) ;
405
429
if ( nodes . length ) {
406
430
if ( dataExpression ) {
0 commit comments