Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fable.Compiler/Globbing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Glob =
| Drive name :: t ->
let subDirs = List.collect (checkSubDirs true name) acc
buildPaths subDirs t
| Recursive :: [] ->
| [ Recursive ] ->
let dirs =
Seq.collect
(fun dir ->
Expand Down
4 changes: 2 additions & 2 deletions src/Fable.Transforms/Dart/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2406,13 +2406,13 @@ let intrinsicFunctions (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr
Helper.LibCall(com, "Decimal", "pow", t, args, i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r)
|> Some
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangechar-function-%5bfsharp%5d
// Type: RangeChar : char -> char -> seq<char>
// Type: RangeChar : char -> char -> char seq
// Usage: RangeChar start stop
| "RangeChar", None, _ ->
Helper.LibCall(com, "Range", "rangeChar", t, args, i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r)
|> Some
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangedouble-function-%5bfsharp%5d
// Type: RangeDouble: float -> float -> float -> seq<float>
// Type: RangeDouble: float -> float -> float -> float seq
// Usage: RangeDouble start step stop
| ("RangeSByte" | "RangeByte" | "RangeInt16" | "RangeUInt16" | "RangeInt32" | "RangeUInt32" | "RangeSingle" | "RangeDouble"),
None,
Expand Down
6 changes: 3 additions & 3 deletions src/Fable.Transforms/FSharp2Fable.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ module Helpers =
if ent.IsFSharpModule then
match trimRootModule, entName with
| TrimRootModule com, _ when com.Options.Language = Rust -> memb.CompiledName, Naming.NoMemberPart // module prefix for Rust
| _, "" -> memb.CompiledName, Naming.NoMemberPart
| _, s when System.String.IsNullOrEmpty(s) -> memb.CompiledName, Naming.NoMemberPart
| _, moduleName -> moduleName, Naming.StaticMemberPart(memb.CompiledName, "")
else
let overloadSuffix = getOverloadSuffixFrom ent memb
Expand Down Expand Up @@ -1374,7 +1374,7 @@ module TypeHelpers =

// Filter measure generic arguments here? (for that we need to pass the compiler, which needs a bigger refactoring)
// Currently for Dart we're doing it in the Fable2Dart step
let makeTypeGenArgsWithConstraints withConstraints ctxTypeArgs (genArgs: seq<FSharpType>) =
let makeTypeGenArgsWithConstraints withConstraints ctxTypeArgs (genArgs: FSharpType seq) =
genArgs
|> Seq.mapToList (fun genArg ->
if genArg.IsGenericParameter then
Expand All @@ -1383,7 +1383,7 @@ module TypeHelpers =
makeTypeWithConstraints withConstraints ctxTypeArgs genArg
)

let makeTypeGenArgs ctxTypeArgs (genArgs: seq<FSharpType>) =
let makeTypeGenArgs ctxTypeArgs (genArgs: FSharpType seq) =
makeTypeGenArgsWithConstraints true ctxTypeArgs genArgs

let makeTypeFromDelegate withConstraints ctxTypeArgs (genArgs: IList<FSharpType>) (tdef: FSharpEntity) =
Expand Down
4 changes: 2 additions & 2 deletions src/Fable.Transforms/FSharp2Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ let rec private getUsedRootNames (com: Compiler) (usedNames: Set<string>) decls
usedNames
else
match getEntityDeclarationName com entRef with
| "" -> usedNames
| s when System.String.IsNullOrEmpty(s) -> usedNames
| entName ->
let reflectionSuffix =
match com.Options.Language with
Expand Down Expand Up @@ -2056,7 +2056,7 @@ let rec private transformDeclarations (com: FableCompiler) ctx fsDecls =
// If the file is empty F# creates a class for the module, but Fable clears the name
// because it matches the root module so it becomes invalid JS, see #2350
match getEntityDeclarationName com entRef with
| "" -> []
| s when System.String.IsNullOrEmpty(s) -> []
| name ->
[
Fable.ClassDeclaration
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ module Util =
str.Split('\n')
|> Array.skipWhile (fun line ->
match line.Trim() with
| "" -> true
| s when System.String.IsNullOrEmpty(s) -> true
| Naming.Regex IMPORT_REGEX (_ :: selector :: path :: _) ->
if selector.StartsWith("{", StringComparison.Ordinal) then
for selector in selector.TrimStart('{').TrimEnd('}').Split(',') do
Expand Down
4 changes: 2 additions & 2 deletions src/Fable.Transforms/Global/Prelude.fs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ module Path =
let toPath = addDummyFile toIsDir toFullPath |> normalizePath

match (pathDifference fromPath toPath).Replace(dummyFile, "") with
| "" -> "."
| s when System.String.IsNullOrEmpty(s) -> "."
// Some folders start with a period, see #1599
| path when isRelativePath path -> path
| path -> "./" + path
Expand Down Expand Up @@ -458,7 +458,7 @@ module Path =

commonPrefix.Length >= parent.Length

let getCommonBaseDir (filePaths: seq<string>) =
let getCommonBaseDir (filePaths: string seq) =
filePaths
|> Seq.map (fun filePath ->
filePath
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Php/Fable2Php.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ let rec convertExpr (com: IPhpCompiler) (expr: Fable.Expr) =
//| _ -> printfn "%A" t

match fixNsName (Path.GetFileNameWithoutExtension(info.Path)) with
| "" ->
| s when System.String.IsNullOrEmpty(s) ->
match com.IsImport info.Selector with
| Some true ->
let name = fixName info.Selector
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Python/Fable2Python.Annotation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ let stdlibModuleTypeHint com ctx moduleName memberName genArgs repeatedGenerics
let makeGenTypeParamInst com ctx (genArgs: Fable.Type list) (repeatedGenerics: Set<string> option) =
match genArgs with
| [] -> []
| _ -> genArgs |> List.map (typeAnnotation com ctx repeatedGenerics) |> List.map fst
| _ -> genArgs |> List.map (typeAnnotation com ctx repeatedGenerics >> fst)

let makeGenericTypeAnnotation
(com: IPythonCompiler)
Expand Down
55 changes: 31 additions & 24 deletions src/Fable.Transforms/Python/Fable2Python.Transforms.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ let private getExceptionTypeExpr (com: IPythonCompiler) ctx =
| Fable.DeclaredType(entRef, _) -> Annotation.tryPyConstructor com ctx (com.GetEntity(entRef))
| _ -> None

let transformTryCatch com (ctx: Context) r returnStrategy (body, catch: option<Fable.Ident * Fable.Expr>, finalizer) =
let transformTryCatch com (ctx: Context) r returnStrategy (body, catch: (Fable.Ident * Fable.Expr) option, finalizer) =
// try .. catch statements cannot be tail call optimized
let ctx = { ctx with TailCallOpportunity = None }

Expand Down Expand Up @@ -3278,32 +3278,35 @@ let declareDataClassType
let interfaceBases =
ent.AllInterfaces
|> List.ofSeq
|> List.filter (fun int ->
|> List.choose (fun int ->
let name = Helpers.removeNamespace (int.Entity.FullName)
allowedInterfaces |> List.contains name
)
|> List.map (fun int ->
// Filter out self-referential generic arguments to avoid forward reference errors
let genericArgs =
int.GenericArgs
|> List.filter (fun genArg ->
match genArg with
| Fable.DeclaredType({ FullName = fullName }, _) -> Helpers.removeNamespace (fullName) <> entName
| _ -> true
)

// Generate the EnumerableBase reference from bases module
if List.isEmpty genericArgs then
libValue com ctx "bases" "EnumerableBase"
if not (allowedInterfaces |> List.contains name) then
None
else
let typeArgs =
genericArgs
|> List.map (fun genArg ->
let arg, _ = Annotation.typeAnnotation com ctx None genArg
arg
// Filter out self-referential generic arguments to avoid forward reference errors
let genericArgs =
int.GenericArgs
|> List.filter (fun genArg ->
match genArg with
| Fable.DeclaredType({ FullName = fullName }, _) ->
Helpers.removeNamespace (fullName) <> entName
| _ -> true
)

Expression.subscript (libValue com ctx "bases" "EnumerableBase", Expression.tuple typeArgs)
// Generate the EnumerableBase reference from bases module
if List.isEmpty genericArgs then
libValue com ctx "bases" "EnumerableBase" |> Some
else
let typeArgs =
genericArgs
|> List.map (fun genArg ->
let arg, _ = Annotation.typeAnnotation com ctx None genArg
arg
)

Expression.subscript (libValue com ctx "bases" "EnumerableBase", Expression.tuple typeArgs)
|> Some
)

let bases = (baseExpr |> Option.toList) @ interfaceBases
Expand Down Expand Up @@ -4473,8 +4476,12 @@ let transformInterface (com: IPythonCompiler) ctx (classEnt: Fable.Entity) (_cla
let interfaces =
classEnt.AllInterfaces
|> List.ofSeq
|> List.map (fun int -> int.Entity)
|> List.filter (fun ent -> ent.FullName <> classEnt.FullName)
|> List.choose (fun int ->
if int.Entity.FullName <> classEnt.FullName then
Some int.Entity
else
None
)

for ref in interfaces do
let entity = com.TryGetEntity(ref)
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Python/Fable2Python.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ module Util =
let makeStringArray strings =
strings |> List.map (fun x -> Expression.stringConstant x) |> Expression.list

let makePyObject (pairs: seq<string * Expression>) =
let makePyObject (pairs: (string * Expression) seq) =
pairs
|> Seq.map (fun (name, value) ->
let prop = Expression.stringConstant name
Expand Down
4 changes: 2 additions & 2 deletions src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2510,13 +2510,13 @@ let intrinsicFunctions (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr
Helper.LibCall(com, "decimal", "pow", t, args, i.SignatureArgTypes, ?loc = r)
|> Some
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangechar-function-%5bfsharp%5d
// Type: RangeChar : char -> char -> seq<char>
// Type: RangeChar : char -> char -> char seq
// Usage: RangeChar start stop
| "RangeChar", None, _ ->
Helper.LibCall(com, "range", "rangeChar", t, args, i.SignatureArgTypes, ?loc = r)
|> Some
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangedouble-function-%5bfsharp%5d
// Type: RangeDouble: float -> float -> float -> seq<float>
// Type: RangeDouble: float -> float -> float -> float seq
// Usage: RangeDouble start step stop
| ("RangeSByte" | "RangeByte" | "RangeInt16" | "RangeUInt16" | "RangeInt32" | "RangeUInt32" | "RangeSingle" | "RangeDouble"),
None,
Expand Down
4 changes: 2 additions & 2 deletions src/Fable.Transforms/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2760,13 +2760,13 @@ let intrinsicFunctions (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr
Helper.LibCall(com, "Decimal", "pow", t, args, i.SignatureArgTypes, ?loc = r)
|> Some
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangechar-function-%5bfsharp%5d
// Type: RangeChar : char -> char -> seq<char>
// Type: RangeChar : char -> char -> char seq
// Usage: RangeChar start stop
| "RangeChar", None, _ ->
Helper.LibCall(com, "Range", "rangeChar", t, args, i.SignatureArgTypes, ?loc = r)
|> Some
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangedouble-function-%5bfsharp%5d
// Type: RangeDouble: float -> float -> float -> seq<float>
// Type: RangeDouble: float -> float -> float -> float seq
// Usage: RangeDouble start step stop
| ("RangeSByte" | "RangeByte" | "RangeInt16" | "RangeUInt16" | "RangeInt32" | "RangeUInt32" | "RangeSingle" | "RangeDouble"),
None,
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Rust/AST/Rust.AST.Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ module Funcs =

let mkExtern (extOpt: Symbol option) : Extern =
match extOpt with
| Some("") -> Extern.Implicit
| Some(s) when System.String.IsNullOrEmpty(s) -> Extern.Implicit
| Some(abi) -> Extern.Explicit(mkStrLitFrom abi None)
| None -> Extern.None

Expand Down
51 changes: 34 additions & 17 deletions src/Fable.Transforms/Rust/Fable2Rust.fs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,12 @@ module TypeInfo =

let getEntityGenParamNames (ent: Fable.Entity) =
ent.GenericParameters
|> List.filter (fun p -> not p.IsMeasure)
|> List.map (fun p -> p.Name)
|> List.choose (fun p ->
if not p.IsMeasure then
Some p.Name
else
None
)
|> Set.ofList

let hasMutableFields (com: IRustCompiler) (ent: Fable.Entity) =
Expand Down Expand Up @@ -707,8 +711,12 @@ module TypeInfo =

let transformGenTypes com ctx genArgs : Rust.Ty list =
genArgs
|> List.filter (isUnitOfMeasure >> not)
|> List.map (transformType com ctx)
|> List.choose (fun g ->
if isUnitOfMeasure g then
None
else
Some(transformType com ctx g)
)

let transformGenArgs com ctx genArgs : Rust.GenericArgs option =
genArgs |> transformGenTypes com ctx |> mkTypesGenericArgs
Expand Down Expand Up @@ -1365,8 +1373,7 @@ module Util =
let genParams =
argTypes @ [ body.Type ]
|> FSharp2Fable.Util.getGenParams
|> List.filter (fst >> isLambdaOrGenArgNotInScope)
|> List.filter (fst >> isNotLambdaOrGenArgInScope)
|> List.filter (fun (name, _) -> isLambdaOrGenArgNotInScope name && isNotLambdaOrGenArgInScope name)

let genArgTypes = genParams |> List.map snd
let genArgNames = genParams |> List.map fst |> Set.ofList
Expand Down Expand Up @@ -3989,11 +3996,13 @@ module Util =

let makeGenericParams com ctx (genParams: Fable.GenericParam list) =
genParams
|> List.filter (fun p -> not p.IsMeasure)
|> List.map (fun p ->
let typeBounds = makeTypeBounds com ctx p.Name p.Constraints
let typeBounds = typeBounds @ defaultTypeBounds
mkGenericParamFromName [] p.Name typeBounds
|> List.choose (fun p ->
if p.IsMeasure then
None
else
let typeBounds = makeTypeBounds com ctx p.Name p.Constraints
let typeBounds = typeBounds @ defaultTypeBounds
mkGenericParamFromName [] p.Name typeBounds |> Some
)

let makeGenericParamsFromArgs com ctx (genArgs: Fable.Type list) =
Expand Down Expand Up @@ -4928,8 +4937,12 @@ module Util =
let nonInterfaceImpls =
let memberItems =
nonInterfaceMembers
|> List.filter (snd >> isIgnoredMember >> not)
|> List.map (makeMemberItem com ctx true)
|> List.choose (fun m ->
if isIgnoredMember (snd m) then
None
else
Some(makeMemberItem com ctx true m)
)

let memberItems =
if isObjectExpr then
Expand Down Expand Up @@ -4985,8 +4998,12 @@ module Util =

let memberItems =
interfaceMembers
|> List.filter (fun (d, m) -> Set.contains m.FullName memberNames)
|> List.map (makeMemberItem com ctx false)
|> List.choose (fun (d, m) ->
if Set.contains m.FullName memberNames then
Some(makeMemberItem com ctx false (d, m))
else
None
)

memberItems
|> makeInterfaceTraitImpls com ctx entName genParams ifcEntRef ifcGenArgs
Expand Down Expand Up @@ -5225,7 +5242,7 @@ module Util =
[ "crate" ]

match import.Selector with
| ""
| s when System.String.IsNullOrEmpty(s) -> []
| "*"
| "default" ->
// let useItem = mkGlobUseItem [] modPath
Expand All @@ -5248,7 +5265,7 @@ module Util =

let getIdentForImport (ctx: Context) (path: string) (selector: string) =
match selector with
| ""
| s when System.String.IsNullOrEmpty(s) -> Path.GetFileNameWithoutExtension(path)
| "*"
| "default" -> Path.GetFileNameWithoutExtension(path)
| _ -> splitNameParts selector |> List.last
Expand Down
4 changes: 2 additions & 2 deletions src/Fable.Transforms/Rust/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2286,13 +2286,13 @@ let intrinsicFunctions (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr
Helper.LibCall(com, "Decimal", "pown", t, args, i.SignatureArgTypes, ?loc = r)
|> Some
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangechar-function-%5bfsharp%5d
// Type: RangeChar : char -> char -> seq<char>
// Type: RangeChar : char -> char -> char seq
// Usage: RangeChar start stop
| "RangeChar", None, _ ->
Helper.LibCall(com, "Range", "rangeChar", t, args, i.SignatureArgTypes, ?loc = r)
|> Some
// reference: https://msdn.microsoft.com/visualfsharpdocs/conceptual/operatorintrinsics.rangedouble-function-%5bfsharp%5d
// Type: RangeDouble: float -> float -> float -> seq<float>
// Type: RangeDouble: float -> float -> float -> float seq
// Usage: RangeDouble start step stop
| ("RangeSByte" | "RangeByte" | "RangeInt16" | "RangeUInt16" | "RangeInt32" | "RangeUInt32" | "RangeInt64" | "RangeUInt64" | "RangeSingle" | "RangeDouble"),
None,
Expand Down
Loading