Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/Fable.AST/Plugins.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type CompilerOptions =
FileExtension: string
TriggeredByDependency: bool
NoReflection: bool
JsTemporal: bool
}

type PluginHelper =
Expand Down
8 changes: 7 additions & 1 deletion src/Fable.Cli/Entry.fs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ let knownCliArgs () =
[ "--trimRootModule" ], []
[ "--fableLib" ], []
[ "--replace" ], []
[ "--test:js-temporal" ], []
]

let printKnownCliArgs () =
Expand Down Expand Up @@ -314,12 +315,16 @@ type Runner =
| Some c when String.IsNullOrWhiteSpace c -> defaultConfiguration
| Some configurationArg -> configurationArg

let jsTemporal = args.FlagEnabled "--test:js-temporal"

let define =
args.Values "--define"
|> List.append
[
"FABLE_COMPILER"
"FABLE_COMPILER_5"
if jsTemporal then
"FABLE_COMPILER_JAVASCRIPT_TEMPORAL"
match language with
| Php -> "FABLE_COMPILER_PHP"
| Rust -> "FABLE_COMPILER_RUST"
Expand Down Expand Up @@ -353,7 +358,8 @@ type Runner =
debugMode = (configuration = "Debug"),
optimizeFSharpAst = args.FlagEnabled "--optimize",
noReflection = args.FlagEnabled "--noReflection",
verbosity = verbosity
verbosity = verbosity,
jsTemporal = jsTemporal
)

let cliArgs =
Expand Down
16 changes: 13 additions & 3 deletions src/Fable.Transforms/Babel/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,16 @@ module Annotation =
| Replacements.Util.BclTimeSpan -> NumberTypeAnnotation
| Replacements.Util.BclDateTime -> makeAliasTypeAnnotation com ctx "Date"
| Replacements.Util.BclDateTimeOffset -> makeAliasTypeAnnotation com ctx "Date"
| Replacements.Util.BclDateOnly -> makeAliasTypeAnnotation com ctx "Date"
| Replacements.Util.BclTimeOnly -> NumberTypeAnnotation
| Replacements.Util.BclDateOnly ->
if com.Options.JsTemporal then
makeFableLibImportTypeAnnotation com ctx [] "DateOnlyTemporal" "PlainDate"
else
makeAliasTypeAnnotation com ctx "Date"
| Replacements.Util.BclTimeOnly ->
if com.Options.JsTemporal then
makeFableLibImportTypeAnnotation com ctx [] "TimeOnlyTemporal" "PlainTime"
else
NumberTypeAnnotation
| Replacements.Util.BclTimer -> makeFableLibImportTypeAnnotation com ctx [] "Timer" "Timer"
| Replacements.Util.BclHashSet key -> makeFableLibImportTypeAnnotation com ctx [ key ] "Util" "ISet"
| Replacements.Util.BclDictionary(key, value) ->
Expand Down Expand Up @@ -3511,11 +3519,13 @@ but thanks to the optimisation done below we get
| Fable.Char -> Expression.stringLiteral "\u0000"
| Fable.Number(kind, uom) ->
com.TransformAsExpr(ctx, Fable.NumberConstant(Fable.NumberValue.GetZero kind, uom) |> makeValue None)
| Builtin BclTimeOnly when com.Options.JsTemporal ->
libCall com ctx None "TimeOnlyTemporal" "minValue" [] []
| Builtin(BclTimeSpan | BclTimeOnly) -> Expression.numericLiteral 0
| Builtin BclGuid -> Expression.stringLiteral "00000000-0000-0000-0000-000000000000"
| Builtin BclDateTime -> libCall com ctx None "Date" "minValue" [] []
| Builtin BclDateTimeOffset -> libCall com ctx None "DateOffset" "minValue" [] []
| Builtin BclDateOnly -> libCall com ctx None "DateOnly" "minValue" [] []
| Builtin BclDateOnly -> libCall com ctx None (JS.Replacements.dateOnlyModule com) "minValue" [] []
| _ -> libCall com ctx None "Util" "defaultOf" [] []

let getEntityFieldsAsIdents (ent: Fable.Entity) =
Expand Down
4 changes: 3 additions & 1 deletion src/Fable.Transforms/Global/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type CompilerOptionsHelper =
?verbosity,
?fileExtension,
?clampByteArrays,
?noReflection
?noReflection,
?jsTemporal
)
=
{
Expand All @@ -32,6 +33,7 @@ type CompilerOptionsHelper =
ClampByteArrays = defaultArg clampByteArrays false
NoReflection = defaultArg noReflection false
TriggeredByDependency = false
JsTemporal = defaultArg jsTemporal false
}

[<RequireQualifiedAccess>]
Expand Down
Loading
Loading