@@ -439,7 +439,7 @@ module Annotation =
439439 makeNativeTypeAnnotation com ctx [ genArg] " Array"
440440
441441 let makeListTypeAnnotation com ctx genArg =
442- makeImportTypeAnnotation com ctx [ genArg] " Types " " List"
442+ makeImportTypeAnnotation com ctx [ genArg] " List " " List"
443443
444444 let makeUnionTypeAnnotation com ctx genArgs =
445445 List.map ( typeAnnotation com ctx) genArgs
@@ -658,12 +658,6 @@ module Util =
658658 | [] -> expr
659659 | m:: ms -> get None expr m |> getParts ms
660660
661- let makeList com ctx r headAndTail =
662- match headAndTail with
663- | None -> [||]
664- | Some( TransformExpr com ctx head, TransformExpr com ctx tail) -> [| head; tail|]
665- |> libConsCall com ctx r " Types" " List"
666-
667661 let makeArray ( com : IBabelCompiler ) ctx exprs =
668662 List.mapToArray ( fun e -> com.TransformAsExpr( ctx, e)) exprs
669663 |> ArrayExpression :> Expression
@@ -896,12 +890,17 @@ module Util =
896890 | Fable.NewTuple vals -> makeArray com ctx vals
897891 // Optimization for bundle size: compile list literals as List.ofArray
898892 | Replacements.ListLiteral( exprs, t) ->
899- match exprs with
900- | [] -> makeList com ctx r None
901- | [ expr] -> Some( expr, Fable.Value( Fable.NewList ( None, t), None)) |> makeList com ctx r
902- | exprs -> [| makeArray com ctx exprs|] |> libCall com ctx r " List" " ofArray"
893+ [| List.rev exprs |> makeArray com ctx|]
894+ |> libCall com ctx r " List" " newList"
895+ // match exprs with
896+ // | [] -> libCall com ctx r "List" "empty" [||]
897+ // | [TransformExpr com ctx expr] -> libCall com ctx r "List" "singleton" [|expr|]
898+ // | exprs -> [|makeArray com ctx exprs|] |> libCall com ctx r "List" "ofArray"
903899 | Fable.NewList ( headAndTail, _) ->
904- makeList com ctx r headAndTail
900+ match headAndTail with
901+ | None -> libCall com ctx r " List" " empty" [||]
902+ | Some( TransformExpr com ctx head, TransformExpr com ctx tail) ->
903+ libCall com ctx r " List" " cons" [| head; tail|]
905904 | Fable.NewOption ( value, t) ->
906905 match value with
907906 | Some ( TransformExpr com ctx e) ->
@@ -1102,8 +1101,10 @@ module Util =
11021101 match getKind with
11031102 | Fable.ByKey( Fable.ExprKey( TransformExpr com ctx prop)) -> getExpr range expr prop
11041103 | Fable.ByKey( Fable.FieldKey field) -> get range expr field.Name
1105- | Fable.ListHead -> get range expr " head"
1106- | Fable.ListTail -> get range expr " tail"
1104+ // | Fable.ListHead -> get range expr "Head"
1105+ // | Fable.ListTail -> get range expr "Tail"
1106+ | Fable.ListHead -> libCall com ctx range " List" " head" [| expr|]
1107+ | Fable.ListTail -> libCall com ctx range " List" " tail" [| expr|]
11071108 | Fable.TupleIndex index -> getExpr range expr ( ofInt index)
11081109 | Fable.OptionValue ->
11091110 if mustWrapOption typ || com.Options.Typescript
@@ -1159,9 +1160,9 @@ module Util =
11591160 let op = if nonEmpty then BinaryUnequal else BinaryEqual
11601161 upcast BinaryExpression( op, com.TransformAsExpr( ctx, expr), NullLiteral(), ?loc= range)
11611162 | Fable.ListTest nonEmpty ->
1162- let expr = com.TransformAsExpr( ctx, expr)
1163- let op = if nonEmpty then BinaryUnequal else BinaryEqual
1164- upcast BinaryExpression ( op , get None expr " tail " , NullLiteral (), ?loc= range)
1163+ // let expr = get range ( com.TransformAsExpr(ctx, expr)) "IsEmpty"
1164+ let expr = libCall com ctx range " List " " isEmpty " [| com.TransformAsExpr ( ctx , expr )|]
1165+ if nonEmpty then upcast UnaryExpression ( UnaryNot , expr, ?loc= range) else expr
11651166 | Fable.UnionCaseTest tag ->
11661167 let expected = ofInt tag
11671168 let actual = com.TransformAsExpr( ctx, expr) |> getUnionExprTag None
0 commit comments