@@ -115,7 +115,7 @@ export class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyTy
115
115
segments . push ( `
116
116
// instantiate fallback for ${ key } of type ${ safeTypeName ( type ) }
117
117
this${ propertyAccess ( key ) } = ${ this . alias ( `model.properties["${ key } "]` ) } .instantiate(
118
- snapshot?${ propertyAccess ( key ) } ,
118
+ snapshot?. ${ propertyAccess ( key ) . substring ( 1 ) } ,
119
119
context,
120
120
this
121
121
);
@@ -262,7 +262,11 @@ export class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyTy
262
262
}
263
263
}
264
264
265
- private expressionForDirectlyAssignableType ( key : string , type : DirectlyAssignableType , valueExpression = `snapshot?${ propertyAccess ( key ) } ` ) {
265
+ private expressionForDirectlyAssignableType (
266
+ key : string ,
267
+ type : DirectlyAssignableType ,
268
+ valueExpression = `snapshot${ propertyAccess ( key ) } ` ,
269
+ ) {
266
270
return type instanceof DateType ? `new Date(${ valueExpression } )` : valueExpression ;
267
271
}
268
272
@@ -290,7 +294,7 @@ export class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyTy
290
294
291
295
return `
292
296
// setup reference for ${ key }
293
- const ${ identifierVarName } = snapshot?${ propertyAccess ( key ) } ;
297
+ const ${ identifierVarName } = snapshot?. ${ propertyAccess ( key ) . substring ( 1 ) } ;
294
298
295
299
// eager resolve path: check the reference cache immediately for the identifier
296
300
const ${ instanceVarName } = context.referenceCache.get(${ identifierVarName } );
@@ -344,7 +348,7 @@ export class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyTy
344
348
345
349
return `
346
350
// optional type for ${ key }
347
- let ${ varName } = snapshot?${ propertyAccess ( key ) } ;
351
+ let ${ varName } = snapshot?. ${ propertyAccess ( key ) . substring ( 1 ) } ;
348
352
if (${ comparisonsToUndefinedValues . join ( " || " ) } ) {
349
353
${ varName } = ${ defaultValueExpression }
350
354
}
@@ -357,7 +361,7 @@ export class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyTy
357
361
return `
358
362
// instantiate fallback for ${ key } of type ${ safeTypeName ( type ) }
359
363
this${ propertyAccess ( key ) } = ${ this . alias ( `model.properties["${ key } "]` ) } .instantiate(
360
- snapshot?${ propertyAccess ( key ) } ,
364
+ snapshot?. ${ propertyAccess ( key ) . substring ( 1 ) } ,
361
365
context,
362
366
this
363
367
);
@@ -367,7 +371,7 @@ export class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyTy
367
371
// Directly assignable types are primitives so we don't need to worry about setting parent/env/etc. Hence, we just
368
372
// pass the snapshot straight through to the constructor.
369
373
return `
370
- const arrayData = snapshot?${ propertyAccess ( key ) } ;
374
+ const arrayData = snapshot?. ${ propertyAccess ( key ) . substring ( 1 ) } ;
371
375
if (arrayData && arrayData.length > 0) {
372
376
this${ propertyAccess ( key ) } = new QuickArray(
373
377
${ this . alias ( `model.properties["${ key } "]` ) } ,
@@ -396,7 +400,7 @@ export class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyTy
396
400
return `
397
401
const ${ mapVarName } = new QuickMap(${ this . alias ( `model.properties["${ key } "]` ) } , this, context);
398
402
this${ propertyAccess ( key ) } = ${ mapVarName } ;
399
- const ${ snapshotVarName } = snapshot?${ propertyAccess ( key ) } ;
403
+ const ${ snapshotVarName } = snapshot?. ${ propertyAccess ( key ) . substring ( 1 ) } ;
400
404
if (${ snapshotVarName } ) {
401
405
for (const key in ${ snapshotVarName } ) {
402
406
const item = ${ this . alias ( `model.properties["${ key } "].childrenType` ) } .instantiate(
@@ -422,7 +426,7 @@ export class InstantiatorBuilder<T extends IClassModelType<Record<string, IAnyTy
422
426
destinationProp = this . alias ( `Symbol.for("${ this . getters . memoSymbolName ( snapshottedView . property ) } ")` ) ;
423
427
}
424
428
425
- const valueExpression = `snapshot?${ propertyAccess ( snapshottedView . property ) } ` ;
429
+ const valueExpression = `snapshot?. ${ propertyAccess ( snapshottedView . property ) . substring ( 1 ) } ` ;
426
430
return `
427
431
// setup snapshotted view for ${ snapshottedView . property }
428
432
const ${ varName } = ${ valueExpression } ;
0 commit comments