@@ -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,9 +821,18 @@ module Util =
814821 let getUnionCaseName ( uci : Fable.UnionCase ) =
815822 match uci.CompiledName with Some cname -> cname | None -> uci.Name
816823
824+ // let getUnionCaseFullName (uci: Fable.UnionCase) =
825+ // uci.XmlDocSig
826+ // |> Naming.replacePrefix "T:Microsoft.FSharp." "FSharp."
827+ // |> Naming.replacePrefix "T:" ""
828+
817829 let getUnionExprTag ( com : IBabelCompiler ) ctx r ( fableExpr : Fable.Expr ) =
818830 let expr = com.TransformAsExpr( ctx, fableExpr)
819- getExpr r expr ( Expression.stringLiteral( " tag" ))
831+ match fableExpr.Type with
832+ | Replacements.ErasedType com _ ->
833+ getExpr r expr ( ofInt 0 )
834+ | _ ->
835+ getExpr r expr ( Expression.stringLiteral( " tag" ))
820836
821837 /// Wrap int expressions with `| 0` to help optimization of JS VMs
822838 let wrapIntExpression typ ( e : Expression ) =
@@ -962,27 +978,40 @@ module Util =
962978 com.TransformAsExpr( ctx, x)
963979 | Fable.NewRecord( values, ent, genArgs) ->
964980 let ent = com.GetEntity( ent)
965- let values = List.mapToArray ( fun x -> com.TransformAsExpr( ctx, x)) values
966- let consRef = ent |> jsConstructor com ctx
967- let typeParamInst =
968- if com.Options.Typescript && ( ent.FullName = Types.reference)
969- then makeGenTypeParamInst com ctx genArgs
970- else None
971- Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
981+ let values = List.map ( fun x -> com.TransformAsExpr( ctx, x)) values
982+ if FSharp2Fable.Util.isErasedEntity com ent then
983+ let recordName = ent.FullName |> ofString
984+ recordName:: values |> List.toArray |> Expression.arrayExpression
985+ else
986+ let consRef = ent |> jsConstructor com ctx
987+ let values = values |> List.toArray
988+ let typeParamInst =
989+ if com.Options.Typescript && ( ent.FullName = Types.reference)
990+ then makeGenTypeParamInst com ctx genArgs
991+ else None
992+ Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
972993 | Fable.NewAnonymousRecord( values, fieldNames, _ genArgs) ->
973994 let values = List.mapToArray ( fun x -> com.TransformAsExpr( ctx, x)) values
974- Array.zip fieldNames values |> makeJsObject
995+ if com.Options.EraseTypes then
996+ values |> Expression.arrayExpression
997+ else
998+ Array.zip fieldNames values |> makeJsObject
975999 | Fable.NewUnion( values, tag, ent, genArgs) ->
9761000 let ent = com.GetEntity( ent)
9771001 let values = List.map ( fun x -> com.TransformAsExpr( ctx, x)) values
978- let consRef = ent |> jsConstructor com ctx
979- let typeParamInst =
980- if com.Options.Typescript
981- then makeGenTypeParamInst com ctx genArgs
982- else None
983- // let caseName = ent.UnionCases |> List.item tag |> getUnionCaseName |> ofString
984- let values = ( ofInt tag):: values |> List.toArray
985- Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
1002+ if FSharp2Fable.Util.isErasedEntity com ent then
1003+ let caseTag = tag |> ofInt
1004+ let caseName = ent.UnionCases |> List.item tag |> getUnionCaseName |> ofString
1005+ caseTag:: caseName:: values |> List.toArray |> Expression.arrayExpression
1006+ else
1007+ let consRef = ent |> jsConstructor com ctx
1008+ let typeParamInst =
1009+ if com.Options.Typescript
1010+ then makeGenTypeParamInst com ctx genArgs
1011+ else None
1012+ // let caseName = ent.UnionCases |> List.item tag |> getUnionCaseName |> ofString
1013+ let values = ( ofInt tag):: values |> List.toArray
1014+ Expression.newExpression( consRef, values, ?typeArguments= typeParamInst, ?loc= r)
9861015
9871016 let enumerator2iterator com ctx =
9881017 let enumerator = Expression.callExpression( get None ( Expression.identifier( " this" )) " GetEnumerator" , [||])
@@ -1201,7 +1230,14 @@ module Util =
12011230 let expr = com.TransformAsExpr( ctx, fableExpr)
12021231 match key with
12031232 | Fable.ExprKey( TransformExpr com ctx prop) -> getExpr range expr prop
1204- | Fable.FieldKey field -> get range expr field.Name
1233+ | Fable.FieldKey field ->
1234+ match fableExpr.Type with
1235+ | Replacements.ErasedType com ( fieldNames, offset, _, _) ->
1236+ let indexOpt = fieldNames |> Array.tryFindIndex ( fun name -> name = field.Name)
1237+ match indexOpt with
1238+ | Some index -> getExpr range expr ( ofInt ( offset + index))
1239+ | _ -> get range expr field.Name
1240+ | _ -> get range expr field.Name
12051241
12061242 | Fable.ListHead ->
12071243 // get range (com.TransformAsExpr(ctx, fableExpr)) "head"
@@ -1229,15 +1265,26 @@ module Util =
12291265
12301266 | Fable.UnionField( index, _) ->
12311267 let expr = com.TransformAsExpr( ctx, fableExpr)
1232- getExpr range ( getExpr None expr ( Expression.stringLiteral( " fields" ))) ( ofInt index)
1268+ match fableExpr.Type with
1269+ | Replacements.ErasedType com (_, offset, _, _) ->
1270+ getExpr range expr ( ofInt ( offset + index))
1271+ | _ ->
1272+ getExpr range ( getExpr None expr ( Expression.stringLiteral( " fields" ))) ( ofInt index)
12331273
12341274 let transformSet ( com : IBabelCompiler ) ctx range fableExpr ( value : Fable.Expr ) kind =
12351275 let expr = com.TransformAsExpr( ctx, fableExpr)
12361276 let value = com.TransformAsExpr( ctx, value) |> wrapIntExpression value.Type
12371277 let ret =
12381278 match kind with
12391279 | None -> expr
1240- | Some( Fable.FieldKey fi) -> get None expr fi.Name
1280+ | Some( Fable.FieldKey field) ->
1281+ match fableExpr.Type with
1282+ | Replacements.ErasedType com ( fieldNames, offset, _, _) ->
1283+ let indexOpt = fieldNames |> Array.tryFindIndex ( fun name -> name = field.Name)
1284+ match indexOpt with
1285+ | Some index -> getExpr None expr ( ofInt ( offset + index))
1286+ | _ -> get None expr field.Name
1287+ | _ -> get None expr field.Name
12411288 | Some( Fable.ExprKey( TransformExpr com ctx e)) -> getExpr None expr e
12421289 assign range ret value
12431290
0 commit comments