11import { JsExpression } from '@jsonjoy.com/util/lib/codegen/util/JsExpression' ;
22import { MaxEncodingOverhead , maxEncodingCapacity } from '@jsonjoy.com/util/lib/json-size' ;
33import { CapacityEstimatorCodegenContext } from './CapacityEstimatorCodegenContext' ;
4- import type { CapacityEstimatorCodegenContextOptions , CompiledCapacityEstimator } from './CapacityEstimatorCodegenContext' ;
4+ import type {
5+ CapacityEstimatorCodegenContextOptions ,
6+ CompiledCapacityEstimator ,
7+ } from './CapacityEstimatorCodegenContext' ;
58import type { Type } from '../../type' ;
69
710type EstimatorFunction = ( ctx : CapacityEstimatorCodegenContext , value : JsExpression , type : Type ) => void ;
@@ -102,7 +105,12 @@ export const tup = (ctx: CapacityEstimatorCodegenContext, value: JsExpression, t
102105 }
103106} ;
104107
105- export const obj = ( ctx : CapacityEstimatorCodegenContext , value : JsExpression , type : Type , estimateCapacityFn : EstimatorFunction ) : void => {
108+ export const obj = (
109+ ctx : CapacityEstimatorCodegenContext ,
110+ value : JsExpression ,
111+ type : Type ,
112+ estimateCapacityFn : EstimatorFunction ,
113+ ) : void => {
106114 const codegen = ctx . codegen ;
107115 const r = codegen . var ( value . use ( ) ) ;
108116 const objectType = type as any ; // ObjectType
@@ -117,7 +125,7 @@ export const obj = (ctx: CapacityEstimatorCodegenContext, value: JsExpression, t
117125 for ( const field of fields ) {
118126 ctx . inc ( maxEncodingCapacity ( field . key ) ) ;
119127 const accessor = normalizeAccessor ( field . key ) ;
120- const isOptional = field . optional || ( field . constructor ?. name === 'ObjectOptionalFieldType' ) ;
128+ const isOptional = field . optional || field . constructor ?. name === 'ObjectOptionalFieldType' ;
121129 const block = ( ) => estimateCapacityFn ( ctx , new JsExpression ( ( ) => `${ r } ${ accessor } ` ) , field . value ) ;
122130 if ( isOptional ) {
123131 codegen . if ( `${ r } ${ accessor } !== undefined` , block ) ;
@@ -156,7 +164,12 @@ export const ref = (ctx: CapacityEstimatorCodegenContext, value: JsExpression, t
156164 ctx . codegen . js ( `size += ${ d } (${ value . use ( ) } );` ) ;
157165} ;
158166
159- export const or = ( ctx : CapacityEstimatorCodegenContext , value : JsExpression , type : Type , estimateCapacityFn : EstimatorFunction ) : void => {
167+ export const or = (
168+ ctx : CapacityEstimatorCodegenContext ,
169+ value : JsExpression ,
170+ type : Type ,
171+ estimateCapacityFn : EstimatorFunction ,
172+ ) : void => {
160173 const codegen = ctx . codegen ;
161174 const orType = type as any ; // OrType
162175 const discriminator = orType . discriminator ( ) ;
@@ -179,7 +192,7 @@ export const or = (ctx: CapacityEstimatorCodegenContext, value: JsExpression, ty
179192 */
180193export const generate = ( ctx : CapacityEstimatorCodegenContext , value : JsExpression , type : Type ) : void => {
181194 const kind = type . getTypeName ( ) ;
182-
195+
183196 switch ( kind ) {
184197 case 'any' :
185198 any ( ctx , value , type ) ;
@@ -239,4 +252,4 @@ export const codegen = (
239252 // Use the centralized router instead of the abstract method
240253 generate ( ctx , value , type ) ;
241254 return ctx . compile ( ) ;
242- } ;
255+ } ;
0 commit comments