@@ -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) ->
@@ -812,9 +819,18 @@ module Util =
812819 let getUnionCaseName ( uci : Fable.UnionCase ) =
813820 match uci.CompiledName with Some cname -> cname | None -> uci.Name
814821
822+ // let getUnionCaseFullName (uci: Fable.UnionCase) =
823+ // uci.XmlDocSig
824+ // |> Naming.replacePrefix "T:Microsoft.FSharp." "FSharp."
825+ // |> Naming.replacePrefix "T:" ""
826+
815827 let getUnionExprTag ( com : IBabelCompiler ) ctx r ( fableExpr : Fable.Expr ) =
816828 let expr = com.TransformAsExpr( ctx, fableExpr)
817- getExpr r expr ( Expression.stringLiteral( " tag" ))
829+ match fableExpr.Type with
830+ | Replacements.ErasedType com _ ->
831+ getExpr r expr ( ofInt 0 )
832+ | _ ->
833+ getExpr r expr ( Expression.stringLiteral( " tag" ))
818834
819835 /// Wrap int expressions with `| 0` to help optimization of JS VMs
820836 let wrapIntExpression typ ( e : Expression ) =
@@ -960,27 +976,40 @@ module Util =
960976 com.TransformAsExpr( ctx, x)
961977 | Fable.NewRecord( values, ent, genArgs) ->
962978 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)
979+ let values = List.map ( fun x -> com.TransformAsExpr( ctx, x)) values
980+ if FSharp2Fable.Util.isErasedEntity com ent then
981+ let recordName = ent.FullName |> ofString
982+ recordName:: values |> List.toArray |> Expression.arrayExpression
983+ else
984+ let consRef = ent |> jsConstructor com ctx
985+ let values = values |> List.toArray
986+ let typeParamInst =
987+ if com.Options.Typescript && ( ent.FullName = Types.reference)
988+ then makeGenTypeParamInst com ctx genArgs
989+ else None
990+ Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
970991 | Fable.NewAnonymousRecord( values, fieldNames, _ genArgs) ->
971992 let values = List.mapToArray ( fun x -> com.TransformAsExpr( ctx, x)) values
972- Array.zip fieldNames values |> makeJsObject
993+ if com.Options.EraseTypes then
994+ values |> Expression.arrayExpression
995+ else
996+ Array.zip fieldNames values |> makeJsObject
973997 | Fable.NewUnion( values, tag, ent, genArgs) ->
974998 let ent = com.GetEntity( ent)
975999 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)
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.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)
9841013
9851014 let enumerator2iterator com ctx =
9861015 let enumerator = Expression.callExpression( get None ( Expression.identifier( " this" )) " GetEnumerator" , [||])
@@ -1199,7 +1228,14 @@ module Util =
11991228 let expr = com.TransformAsExpr( ctx, fableExpr)
12001229 match key with
12011230 | Fable.ExprKey( TransformExpr com ctx prop) -> getExpr range expr prop
1202- | 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
12031239
12041240 | Fable.ListHead ->
12051241 // get range (com.TransformAsExpr(ctx, fableExpr)) "head"
@@ -1227,15 +1263,26 @@ module Util =
12271263
12281264 | Fable.UnionField( index, _) ->
12291265 let expr = com.TransformAsExpr( ctx, fableExpr)
1230- 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)
12311271
12321272 let transformSet ( com : IBabelCompiler ) ctx range fableExpr ( value : Fable.Expr ) kind =
12331273 let expr = com.TransformAsExpr( ctx, fableExpr)
12341274 let value = com.TransformAsExpr( ctx, value) |> wrapIntExpression value.Type
12351275 let ret =
12361276 match kind with
12371277 | None -> expr
1238- | 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
12391286 | Some( Fable.ExprKey( TransformExpr com ctx e)) -> getExpr None expr e
12401287 assign range ret value
12411288
0 commit comments