@@ -310,6 +310,12 @@ module Reflection =
310310 let ent = com.GetEntity( ent)
311311 if ent.IsInterface then
312312 warnAndEvalToFalse " interfaces"
313+ elif FSharp2Fable.Util.isErasedEntity com ent then
314+ let expr = com.TransformAsExpr( ctx, expr)
315+ let idx = if ent.IsFSharpUnion then 1 else 0
316+ let actual = Util.getExpr None expr ( Util.ofInt idx)
317+ let expected = Util.ofString ent.FullName
318+ Expression.binaryExpression( BinaryEqualStrict, actual, expected, ?loc= range)
313319 else
314320 match tryJsConstructor com ctx ent with
315321 | Some cons ->
@@ -382,6 +388,7 @@ module Annotation =
382388 | Fable.LambdaType _ -> Util.uncurryLambdaType typ ||> makeFunctionTypeAnnotation com ctx typ
383389 | Fable.DelegateType( argTypes, returnType) -> makeFunctionTypeAnnotation com ctx typ argTypes returnType
384390 | Fable.GenericParam name -> makeSimpleTypeAnnotation com ctx name
391+ | Replacements.ErasedType com (_, _, _, genArgs) -> makeTupleTypeAnnotation com ctx genArgs
385392 | Fable.DeclaredType( ent, genArgs) ->
386393 makeEntityTypeAnnotation com ctx ent genArgs
387394 | Fable.AnonymousRecordType( fieldNames, genArgs) ->
@@ -813,9 +820,18 @@ module Util =
813820 let getUnionCaseName ( uci : Fable.UnionCase ) =
814821 match uci.CompiledName with Some cname -> cname | None -> uci.Name
815822
823+ // let getUnionCaseFullName (uci: Fable.UnionCase) =
824+ // uci.XmlDocSig
825+ // |> Naming.replacePrefix "T:Microsoft.FSharp." "FSharp."
826+ // |> Naming.replacePrefix "T:" ""
827+
816828 let getUnionExprTag ( com : IBabelCompiler ) ctx r ( fableExpr : Fable.Expr ) =
817829 let expr = com.TransformAsExpr( ctx, fableExpr)
818- getExpr r expr ( Expression.stringLiteral( " tag" ))
830+ match fableExpr.Type with
831+ | Replacements.ErasedType com _ ->
832+ getExpr r expr ( ofInt 0 )
833+ | _ ->
834+ getExpr r expr ( Expression.stringLiteral( " tag" ))
819835
820836 /// Wrap int expressions with `| 0` to help optimization of JS VMs
821837 let wrapIntExpression typ ( e : Expression ) =
@@ -961,27 +977,39 @@ module Util =
961977 com.TransformAsExpr( ctx, x)
962978 | Fable.NewRecord( values, ent, genArgs) ->
963979 let ent = com.GetEntity( ent)
964- let values = List.mapToArray ( fun x -> com.TransformAsExpr( ctx, x)) values
965- let consRef = ent |> jsConstructor com ctx
966- let typeParamInst =
967- if com.Options.Language = TypeScript && ( ent.FullName = Types.reference)
968- then makeGenTypeParamInst com ctx genArgs
969- else None
970- Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
980+ let values = List.map ( fun x -> com.TransformAsExpr( ctx, x)) values
981+ if FSharp2Fable.Util.isErasedEntity com ent then
982+ let recordName = ent.FullName |> ofString
983+ recordName:: values |> List.toArray |> Expression.arrayExpression
984+ else
985+ let consRef = ent |> jsConstructor com ctx
986+ let typeParamInst =
987+ if com.Options.Language = TypeScript && ( ent.FullName = Types.reference)
988+ then makeGenTypeParamInst com ctx genArgs
989+ else None
990+ Expression.newExpression( consRef, values |> List.toArray, ?typeArguments= typeParamInst, ?loc= r)
971991 | Fable.NewAnonymousRecord( values, fieldNames, _ genArgs) ->
972992 let values = List.mapToArray ( fun x -> com.TransformAsExpr( ctx, x)) values
973- Array.zip fieldNames values |> makeJsObject
993+ if com.Options.EraseTypes then
994+ values |> Expression.arrayExpression
995+ else
996+ Array.zip fieldNames values |> makeJsObject
974997 | Fable.NewUnion( values, tag, ent, genArgs) ->
975998 let ent = com.GetEntity( ent)
976999 let values = List.map ( fun x -> com.TransformAsExpr( ctx, x)) values
977- let consRef = ent |> jsConstructor com ctx
978- let typeParamInst =
979- if com.Options.Language = TypeScript
980- then makeGenTypeParamInst com ctx genArgs
981- else None
982- // let caseName = ent.UnionCases |> List.item tag |> getUnionCaseName |> ofString
983- let values = ( ofInt tag):: values |> List.toArray
984- Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
1000+ if FSharp2Fable.Util.isErasedEntity com ent then
1001+ let caseTag = tag |> ofInt
1002+ let caseName = ent.UnionCases |> List.item tag |> getUnionCaseName |> ofString
1003+ caseTag:: caseName:: values |> List.toArray |> Expression.arrayExpression
1004+ else
1005+ let consRef = ent |> jsConstructor com ctx
1006+ let typeParamInst =
1007+ if com.Options.Language = TypeScript
1008+ then makeGenTypeParamInst com ctx genArgs
1009+ else None
1010+ // let caseName = ent.UnionCases |> List.item tag |> getUnionCaseName |> ofString
1011+ let values = ( ofInt tag):: values |> List.toArray
1012+ Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
9851013
9861014 let enumerator2iterator com ctx =
9871015 let enumerator = Expression.callExpression( get None ( Expression.identifier( " this" )) " GetEnumerator" , [||])
@@ -1200,7 +1228,14 @@ module Util =
12001228 let expr = com.TransformAsExpr( ctx, fableExpr)
12011229 match key with
12021230 | Fable.ExprKey( TransformExpr com ctx prop) -> getExpr range expr prop
1203- | Fable.FieldKey field -> get range expr field.Name
1231+ | Fable.FieldKey field ->
1232+ match fableExpr.Type with
1233+ | Replacements.ErasedType com ( fieldNames, offset, _, _) ->
1234+ let indexOpt = fieldNames |> Array.tryFindIndex ( fun name -> name = field.Name)
1235+ match indexOpt with
1236+ | Some index -> getExpr range expr ( ofInt ( offset + index))
1237+ | _ -> get range expr field.Name
1238+ | _ -> get range expr field.Name
12041239
12051240 | Fable.ListHead ->
12061241 // get range (com.TransformAsExpr(ctx, fableExpr)) "head"
@@ -1228,15 +1263,26 @@ module Util =
12281263
12291264 | Fable.UnionField( index, _) ->
12301265 let expr = com.TransformAsExpr( ctx, fableExpr)
1231- getExpr range ( getExpr None expr ( Expression.stringLiteral( " fields" ))) ( ofInt index)
1266+ match fableExpr.Type with
1267+ | Replacements.ErasedType com (_, offset, _, _) ->
1268+ getExpr range expr ( ofInt ( offset + index))
1269+ | _ ->
1270+ getExpr range ( getExpr None expr ( Expression.stringLiteral( " fields" ))) ( ofInt index)
12321271
12331272 let transformSet ( com : IBabelCompiler ) ctx range fableExpr ( value : Fable.Expr ) kind =
12341273 let expr = com.TransformAsExpr( ctx, fableExpr)
12351274 let value = com.TransformAsExpr( ctx, value) |> wrapIntExpression value.Type
12361275 let ret =
12371276 match kind with
12381277 | None -> expr
1239- | Some( Fable.FieldKey fi) -> get None expr fi.Name
1278+ | Some( Fable.FieldKey field) ->
1279+ match fableExpr.Type with
1280+ | Replacements.ErasedType com ( fieldNames, offset, _, _) ->
1281+ let indexOpt = fieldNames |> Array.tryFindIndex ( fun name -> name = field.Name)
1282+ match indexOpt with
1283+ | Some index -> getExpr None expr ( ofInt ( offset + index))
1284+ | _ -> get None expr field.Name
1285+ | _ -> get None expr field.Name
12401286 | Some( Fable.ExprKey( TransformExpr com ctx e)) -> getExpr None expr e
12411287 assign range ret value
12421288
0 commit comments