@@ -310,6 +310,12 @@ module Reflection =
310
310
let ent = com.GetEntity( ent)
311
311
if ent.IsInterface then
312
312
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)
313
319
else
314
320
match tryJsConstructor com ctx ent with
315
321
| Some cons ->
@@ -382,6 +388,7 @@ module Annotation =
382
388
| Fable.LambdaType _ -> Util.uncurryLambdaType typ ||> makeFunctionTypeAnnotation com ctx typ
383
389
| Fable.DelegateType( argTypes, returnType) -> makeFunctionTypeAnnotation com ctx typ argTypes returnType
384
390
| Fable.GenericParam name -> makeSimpleTypeAnnotation com ctx name
391
+ | Replacements.ErasedType com (_, _, _, genArgs) -> makeTupleTypeAnnotation com ctx genArgs
385
392
| Fable.DeclaredType( ent, genArgs) ->
386
393
makeEntityTypeAnnotation com ctx ent genArgs
387
394
| Fable.AnonymousRecordType( fieldNames, genArgs) ->
@@ -813,9 +820,18 @@ module Util =
813
820
let getUnionCaseName ( uci : Fable.UnionCase ) =
814
821
match uci.CompiledName with Some cname -> cname | None -> uci.Name
815
822
823
+ // let getUnionCaseFullName (uci: Fable.UnionCase) =
824
+ // uci.XmlDocSig
825
+ // |> Naming.replacePrefix "T:Microsoft.FSharp." "FSharp."
826
+ // |> Naming.replacePrefix "T:" ""
827
+
816
828
let getUnionExprTag ( com : IBabelCompiler ) ctx r ( fableExpr : Fable.Expr ) =
817
829
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" ))
819
835
820
836
/// Wrap int expressions with `| 0` to help optimization of JS VMs
821
837
let wrapIntExpression typ ( e : Expression ) =
@@ -961,27 +977,39 @@ module Util =
961
977
com.TransformAsExpr( ctx, x)
962
978
| Fable.NewRecord( values, ent, genArgs) ->
963
979
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)
971
991
| Fable.NewAnonymousRecord( values, fieldNames, _ genArgs) ->
972
992
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
974
997
| Fable.NewUnion( values, tag, ent, genArgs) ->
975
998
let ent = com.GetEntity( ent)
976
999
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)
985
1013
986
1014
let enumerator2iterator com ctx =
987
1015
let enumerator = Expression.callExpression( get None ( Expression.identifier( " this" )) " GetEnumerator" , [||])
@@ -1200,7 +1228,14 @@ module Util =
1200
1228
let expr = com.TransformAsExpr( ctx, fableExpr)
1201
1229
match key with
1202
1230
| 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
1204
1239
1205
1240
| Fable.ListHead ->
1206
1241
// get range (com.TransformAsExpr(ctx, fableExpr)) "head"
@@ -1228,15 +1263,26 @@ module Util =
1228
1263
1229
1264
| Fable.UnionField( index, _) ->
1230
1265
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)
1232
1271
1233
1272
let transformSet ( com : IBabelCompiler ) ctx range fableExpr ( value : Fable.Expr ) kind =
1234
1273
let expr = com.TransformAsExpr( ctx, fableExpr)
1235
1274
let value = com.TransformAsExpr( ctx, value) |> wrapIntExpression value.Type
1236
1275
let ret =
1237
1276
match kind with
1238
1277
| 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
1240
1286
| Some( Fable.ExprKey( TransformExpr com ctx e)) -> getExpr None expr e
1241
1287
assign range ret value
1242
1288
0 commit comments