@@ -311,6 +311,12 @@ module Reflection =
311311 let ent = com.GetEntity( ent)
312312 if ent.IsInterface then
313313 warnAndEvalToFalse " interfaces"
314+ elif FSharp2Fable.Util.isErasedEntity com ent then
315+ let expr = com.TransformAsExpr( ctx, expr)
316+ let idx = if ent.IsFSharpUnion then 1 else 0
317+ let actual = Util.getExpr None expr ( Util.ofInt idx)
318+ let expected = Util.ofString ent.FullName
319+ Expression.binaryExpression( BinaryEqualStrict, actual, expected, ?loc= range)
314320 else
315321 match tryJsConstructor com ctx ent with
316322 | Some cons ->
@@ -383,6 +389,7 @@ module Annotation =
383389 | Fable.LambdaType _ -> Util.uncurryLambdaType typ ||> makeFunctionTypeAnnotation com ctx typ
384390 | Fable.DelegateType( argTypes, returnType) -> makeFunctionTypeAnnotation com ctx typ argTypes returnType
385391 | Fable.GenericParam name -> makeSimpleTypeAnnotation com ctx name
392+ | Replacements.ErasedType com (_, _, genArgs) -> makeTupleTypeAnnotation com ctx genArgs
386393 | Fable.DeclaredType( ent, genArgs) ->
387394 makeEntityTypeAnnotation com ctx ent genArgs
388395 | Fable.AnonymousRecordType( fieldNames, genArgs) ->
@@ -814,7 +821,11 @@ module Util =
814821
815822 let getUnionExprTag ( com : IBabelCompiler ) ctx r ( fableExpr : Fable.Expr ) =
816823 let expr = com.TransformAsExpr( ctx, fableExpr)
817- getExpr r expr ( Expression.stringLiteral( " tag" ))
824+ match fableExpr.Type with
825+ | Replacements.ErasedType com _ ->
826+ getExpr r expr ( ofInt 0 )
827+ | _ ->
828+ getExpr r expr ( Expression.stringLiteral( " tag" ))
818829
819830 /// Wrap int expressions with `| 0` to help optimization of JS VMs
820831 let wrapIntExpression typ ( e : Expression ) =
@@ -960,27 +971,41 @@ module Util =
960971 com.TransformAsExpr( ctx, x)
961972 | Fable.NewRecord( values, ent, genArgs) ->
962973 let ent = com.GetEntity( ent)
963- let values = List.mapToArray ( fun x -> com.TransformAsExpr( ctx, x)) values
964- let consRef = ent |> jsConstructor com ctx
965- let typeParamInst =
966- if com.Options.Typescript && ( ent.FullName = Types.reference)
967- then makeGenTypeParamInst com ctx genArgs
968- else None
969- Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
974+ let values = List.map ( fun x -> com.TransformAsExpr( ctx, x)) values
975+ if FSharp2Fable.Util.isErasedEntity com ent then
976+ let recordName = ent.FullName |> ofString
977+ recordName:: values |> List.toArray |> Expression.arrayExpression
978+ else
979+ let consRef = ent |> jsConstructor com ctx
980+ let values = values |> List.toArray
981+ let typeParamInst =
982+ if com.Options.Typescript && ( ent.FullName = Types.reference)
983+ then makeGenTypeParamInst com ctx genArgs
984+ else None
985+ Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
970986 | Fable.NewAnonymousRecord( values, fieldNames, _ genArgs) ->
971987 let values = List.mapToArray ( fun x -> com.TransformAsExpr( ctx, x)) values
972- Array.zip fieldNames values |> makeJsObject
988+ if com.Options.EraseTypes then
989+ values |> Expression.arrayExpression
990+ else
991+ Array.zip fieldNames values |> makeJsObject
973992 | Fable.NewUnion( values, tag, ent, genArgs) ->
974993 let ent = com.GetEntity( ent)
975994 let values = List.map ( fun x -> com.TransformAsExpr( ctx, x)) values
976- let consRef = ent |> jsConstructor com ctx
977- let typeParamInst =
978- if com.Options.Typescript
979- then makeGenTypeParamInst com ctx genArgs
980- else None
981- // let caseName = ent.UnionCases |> List.item tag |> getUnionCaseName |> ofString
982- let values = ( ofInt tag):: values |> List.toArray
983- Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
995+ if FSharp2Fable.Util.isErasedEntity com ent then
996+ let unionCase = ent.UnionCases |> List.item tag
997+ let caseTag = tag |> ofInt
998+ let caseName = unionCase.FullName |> ofString
999+ caseTag:: caseName:: values |> List.toArray |> Expression.arrayExpression
1000+ else
1001+ let consRef = ent |> jsConstructor com ctx
1002+ let typeParamInst =
1003+ if com.Options.Typescript
1004+ then makeGenTypeParamInst com ctx genArgs
1005+ else None
1006+ // let caseName = ent.UnionCases |> List.item tag |> getUnionCaseName |> ofString
1007+ let values = ( ofInt tag):: values |> List.toArray
1008+ Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
9841009
9851010 let enumerator2iterator com ctx =
9861011 let enumerator = Expression.callExpression( get None ( Expression.identifier( " this" )) " GetEnumerator" , [||])
@@ -1203,7 +1228,10 @@ module Util =
12031228
12041229 | Fable.FieldGet ( field, index) ->
12051230 let expr = com.TransformAsExpr( ctx, fableExpr)
1206- get range expr field.Name
1231+ match fableExpr.Type with
1232+ | Replacements.ErasedType com ( offset, _, _) ->
1233+ getExpr range expr ( ofInt ( index + offset))
1234+ | _ -> get range expr field.Name
12071235
12081236 | Fable.ListHead ->
12091237 // get range (com.TransformAsExpr(ctx, fableExpr)) "head"
@@ -1231,7 +1259,11 @@ module Util =
12311259
12321260 | Fable.UnionField( index, _) ->
12331261 let expr = com.TransformAsExpr( ctx, fableExpr)
1234- getExpr range ( getExpr None expr ( Expression.stringLiteral( " fields" ))) ( ofInt index)
1262+ match fableExpr.Type with
1263+ | Replacements.ErasedType com ( offset, _, _) ->
1264+ getExpr range expr ( ofInt ( index + offset))
1265+ | _ ->
1266+ getExpr range ( getExpr None expr ( Expression.stringLiteral( " fields" ))) ( ofInt index)
12351267
12361268 let transformSet ( com : IBabelCompiler ) ctx range fableExpr ( value : Fable.Expr ) kind =
12371269 let expr = com.TransformAsExpr( ctx, fableExpr)
@@ -1241,7 +1273,12 @@ module Util =
12411273 | Fable.ValueSet -> expr
12421274 | Fable.ByKeySet( Fable.FieldKey fi) -> get None expr fi.Name
12431275 | Fable.ByKeySet( Fable.ExprKey( TransformExpr com ctx e)) -> getExpr None expr e
1244- | Fable.FieldSet ( field, index) -> get None expr field.Name
1276+ | Fable.FieldSet ( field, index) ->
1277+ match fableExpr.Type with
1278+ | Replacements.ErasedType com ( offset, _, _) ->
1279+ getExpr None expr ( ofInt ( index + offset))
1280+ | _ ->
1281+ get None expr field.Name
12451282 assign range ret value
12461283
12471284 let transformBindingExprBody ( com : IBabelCompiler ) ( ctx : Context ) ( var : Fable.Ident ) ( value : Fable.Expr ) =
0 commit comments