Skip to content

Commit e0eada6

Browse files
committed
Using F# List type
1 parent 0e83285 commit e0eada6

File tree

5 files changed

+434
-375
lines changed

5 files changed

+434
-375
lines changed

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ module Annotation =
435435
makeNativeTypeAnnotation com ctx [genArg] "Array"
436436

437437
let makeListTypeAnnotation com ctx genArg =
438-
makeImportTypeAnnotation com ctx [genArg] "Types" "List"
438+
makeImportTypeAnnotation com ctx [genArg] "List" "List"
439439

440440
let makeUnionTypeAnnotation com ctx genArgs =
441441
List.map (typeAnnotation com ctx) genArgs
@@ -662,12 +662,6 @@ module Util =
662662
| [] -> expr
663663
| m::ms -> get None expr m |> getParts ms
664664

665-
let makeList com ctx r headAndTail =
666-
match headAndTail with
667-
| None -> [||]
668-
| Some(TransformExpr com ctx head, TransformExpr com ctx tail) -> [|head; tail|]
669-
|> libConsCall com ctx r "Types" "List"
670-
671665
let makeArray (com: IBabelCompiler) ctx exprs =
672666
List.mapToArray (fun e -> com.TransformAsExpr(ctx, e)) exprs
673667
|> Expression.arrayExpression
@@ -933,8 +927,8 @@ module Util =
933927
| Fable.NewArray (values, typ) -> makeTypedArray com ctx typ values
934928
| Fable.NewArrayFrom (size, typ) -> makeTypedAllocatedFrom com ctx typ size
935929
| Fable.NewTuple vals -> makeArray com ctx vals
936-
| Fable.NewList (headAndTail, _) when List.contains "FABLE_LIBRARY" com.Options.Define ->
937-
makeList com ctx r headAndTail
930+
// | Fable.NewList (headAndTail, _) when List.contains "FABLE_LIBRARY" com.Options.Define ->
931+
// makeList com ctx r headAndTail
938932
// Optimization for bundle size: compile list literals as List.ofArray
939933
| Fable.NewList (headAndTail, _) ->
940934
let rec getItems acc = function
@@ -1206,10 +1200,12 @@ module Util =
12061200
| Fable.FieldKey field -> get range expr field.Name
12071201

12081202
| Fable.ListHead ->
1209-
get range (com.TransformAsExpr(ctx, fableExpr)) "head"
1203+
// get range (com.TransformAsExpr(ctx, fableExpr)) "head"
1204+
libCall com ctx range "List" "head" [|com.TransformAsExpr(ctx, fableExpr)|]
12101205

12111206
| Fable.ListTail ->
1212-
get range (com.TransformAsExpr(ctx, fableExpr)) "tail"
1207+
// get range (com.TransformAsExpr(ctx, fableExpr)) "tail"
1208+
libCall com ctx range "List" "tail" [|com.TransformAsExpr(ctx, fableExpr)|]
12131209

12141210
| Fable.TupleIndex index ->
12151211
match fableExpr with
@@ -1274,8 +1270,10 @@ module Util =
12741270
Expression.binaryExpression(op, com.TransformAsExpr(ctx, expr), Expression.nullLiteral(), ?loc=range)
12751271
| Fable.ListTest nonEmpty ->
12761272
let expr = com.TransformAsExpr(ctx, expr)
1277-
let op = if nonEmpty then BinaryUnequal else BinaryEqual
1278-
Expression.binaryExpression(op, get None expr "tail", Expression.nullLiteral(), ?loc=range)
1273+
// let op = if nonEmpty then BinaryUnequal else BinaryEqual
1274+
// Expression.binaryExpression(op, get None expr "tail", Expression.nullLiteral(), ?loc=range)
1275+
let expr = libCall com ctx range "List" "isEmpty" [|expr|]
1276+
if nonEmpty then Expression.unaryExpression(UnaryNot, expr, ?loc=range) else expr
12791277
| Fable.UnionCaseTest tag ->
12801278
let expected = ofInt tag
12811279
let actual = com.TransformAsExpr(ctx, expr) |> getUnionExprTag None

0 commit comments

Comments
 (0)