Skip to content

Commit 07d0311

Browse files
Fix new records with Erase attribute
1 parent 4e24d35 commit 07d0311

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,12 +1106,20 @@ module Util =
11061106
| Fable.NewRecord(values, ent, genArgs) ->
11071107
let ent = com.GetEntity(ent)
11081108
let values = List.mapToArray (fun x -> com.TransformAsExpr(ctx, x)) values
1109-
let consRef = ent |> jsConstructor com ctx
1110-
let typeParamInst =
1111-
if com.Options.Language = TypeScript && (ent.FullName = Types.refCell)
1112-
then makeTypeParamInstantiation com ctx genArgs |> Some
1113-
else None
1114-
Expression.newExpression(consRef, values, ?typeParameters=typeParamInst, ?loc=r)
1109+
if hasAttribute Atts.erase ent.Attributes then
1110+
Seq.zip ent.FSharpFields values
1111+
|> Seq.map (fun (fi, v) ->
1112+
let prop, computed = memberFromName fi.Name
1113+
ObjectMember.objectProperty(prop, v, computed_=computed))
1114+
|> Seq.toArray
1115+
|> Expression.objectExpression
1116+
else
1117+
let consRef = ent |> jsConstructor com ctx
1118+
let typeParamInst =
1119+
if com.Options.Language = TypeScript && (ent.FullName = Types.refCell)
1120+
then makeTypeParamInstantiation com ctx genArgs |> Some
1121+
else None
1122+
Expression.newExpression(consRef, values, ?typeParameters=typeParamInst, ?loc=r)
11151123
| Fable.NewAnonymousRecord(values, fieldNames, _genArgs, _isStruct) ->
11161124
let values = List.mapToArray (fun x -> com.TransformAsExpr(ctx, x)) values
11171125
Array.zip fieldNames values |> makeJsObject
@@ -1203,7 +1211,7 @@ module Util =
12031211
)
12041212

12051213
if not compileAsClass then
1206-
Expression.objectExpression(List.toArray members)
1214+
Expression.objectExpression(List.toArray members)
12071215
else
12081216
let classMembers =
12091217
members |> List.choose (function

0 commit comments

Comments
 (0)