@@ -438,7 +438,7 @@ module Annotation =
438438 makeNativeTypeAnnotation com ctx [ genArg] " Array"
439439
440440 let makeListTypeAnnotation com ctx genArg =
441- makeImportTypeAnnotation com ctx [ genArg] " Types " " List"
441+ makeImportTypeAnnotation com ctx [ genArg] " List " " List"
442442
443443 let makeUnionTypeAnnotation com ctx genArgs =
444444 List.map ( typeAnnotation com ctx) genArgs
@@ -659,12 +659,6 @@ module Util =
659659 | [] -> expr
660660 | m:: ms -> get None expr m |> getParts ms
661661
662- let makeList com ctx r headAndTail =
663- match headAndTail with
664- | None -> [||]
665- | Some( TransformExpr com ctx head, TransformExpr com ctx tail) -> [| head; tail|]
666- |> libConsCall com ctx r " Types" " List"
667-
668662 let makeArray ( com : IBabelCompiler ) ctx exprs =
669663 List.mapToArray ( fun e -> com.TransformAsExpr( ctx, e)) exprs
670664 |> ArrayExpression :> Expression
@@ -911,27 +905,21 @@ module Util =
911905 | Fable.NewArray ( values, typ) -> makeTypedArray com ctx typ values
912906 | Fable.NewArrayFrom ( size, typ) -> makeTypedAllocatedFrom com ctx typ size
913907 | Fable.NewTuple vals -> makeArray com ctx vals
914- | Fable.NewList ( headAndTail, _) when List.contains " FABLE_LIBRARY" com.Options.Define ->
915- makeList com ctx r headAndTail
908+ // | Fable.NewList (headAndTail, _) when List.contains "FABLE_LIBRARY" com.Options.Define ->
909+ // makeList com ctx r headAndTail
916910 // Optimization for bundle size: compile list literals as List.ofArray
911+ | Replacements.ListLiteral( exprs, t) ->
912+ [| List.rev exprs |> makeArray com ctx|]
913+ |> libCall com ctx r " List" " newList"
914+ // match exprs with
915+ // | [] -> libCall com ctx r "List" "empty" [||]
916+ // | [TransformExpr com ctx expr] -> libCall com ctx r "List" "singleton" [|expr|]
917+ // | exprs -> [|makeArray com ctx exprs|] |> libCall com ctx r "List" "ofArray"
917918 | Fable.NewList ( headAndTail, _) ->
918- let rec getItems acc = function
919- | None -> List.rev acc, None
920- | Some( head, Fable.Value( Fable.NewList( tail, _),_)) -> getItems ( head:: acc) tail
921- | Some( head, tail) -> List.rev ( head:: acc), Some tail
922- match getItems [] headAndTail with
923- | [], None ->
924- libCall com ctx r " List" " empty" [||]
925- | [ TransformExpr com ctx expr], None ->
926- libCall com ctx r " List" " singleton" [| expr|]
927- | exprs, None ->
928- [| makeArray com ctx exprs|]
929- |> libCall com ctx r " List" " ofArray"
930- | [ TransformExpr com ctx head], Some( TransformExpr com ctx tail) ->
919+ match headAndTail with
920+ | None -> libCall com ctx r " List" " empty" [||]
921+ | Some( TransformExpr com ctx head, TransformExpr com ctx tail) ->
931922 libCall com ctx r " List" " cons" [| head; tail|]
932- | exprs, Some( TransformExpr com ctx tail) ->
933- [| makeArray com ctx exprs; tail|]
934- |> libCall com ctx r " List" " ofArrayWithTail"
935923 | Fable.NewOption ( value, t) ->
936924 match value with
937925 | Some ( TransformExpr com ctx e) ->
@@ -1196,10 +1184,12 @@ module Util =
11961184 | Fable.FieldKey field -> get range expr field.Name
11971185
11981186 | Fable.ListHead ->
1199- get range ( com.TransformAsExpr( ctx, fableExpr)) " head"
1187+ // get range (com.TransformAsExpr(ctx, fableExpr)) "head"
1188+ libCall com ctx range " List" " head" [| com.TransformAsExpr( ctx, fableExpr)|]
12001189
12011190 | Fable.ListTail ->
1202- get range ( com.TransformAsExpr( ctx, fableExpr)) " tail"
1191+ // get range (com.TransformAsExpr(ctx, fableExpr)) "tail"
1192+ libCall com ctx range " List" " tail" [| com.TransformAsExpr( ctx, fableExpr)|]
12031193
12041194 | Fable.TupleIndex index ->
12051195 match fableExpr with
@@ -1267,9 +1257,9 @@ module Util =
12671257 let op = if nonEmpty then BinaryUnequal else BinaryEqual
12681258 upcast BinaryExpression( op, com.TransformAsExpr( ctx, expr), NullLiteral(), ?loc= range)
12691259 | Fable.ListTest nonEmpty ->
1270- let expr = com.TransformAsExpr( ctx, expr)
1271- let op = if nonEmpty then BinaryUnequal else BinaryEqual
1272- upcast BinaryExpression ( op , get None expr " tail " , NullLiteral (), ?loc= range)
1260+ // let expr = get range ( com.TransformAsExpr(ctx, expr)) "IsEmpty"
1261+ let expr = libCall com ctx range " List " " isEmpty " [| com.TransformAsExpr ( ctx , expr )|]
1262+ if nonEmpty then upcast UnaryExpression ( UnaryNot , expr, ?loc= range) else expr
12731263 | Fable.UnionCaseTest tag ->
12741264 let expected = ofInt tag
12751265 let actual = com.TransformAsExpr( ctx, expr) |> getUnionExprTag None
0 commit comments