Skip to content
Draft
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
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
38 changes: 38 additions & 0 deletions src/Fable.Build/Test/JavaScript.fs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,41 @@ let private testAdaptive (isWatch: bool) =
else
Command.Fable(fableArgs, workingDirectory = destinationDir)

// Second JS pass with the Temporal date/time representation enabled (--test:js-temporal).
// Compiles the whole Main project under the flag but only runs the date/time suites,
// which are the ones whose representation the flag changes.
let private handleMainTestsTemporal () =
let folderName = "Main"
let sourceDir = Path.Resolve("tests", "Js", folderName)

let destinationDir = Path.Resolve("temp", "tests", "JavaScriptTemporal", folderName)

Directory.clean destinationDir

// Compile the whole Main project with the Temporal representation enabled
let fableArgs =
CmdLine.empty
|> CmdLine.appendRaw sourceDir
|> CmdLine.appendPrefix "--outDir" destinationDir
|> CmdLine.appendPrefix "--lang" "javascript"
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
|> CmdLine.appendRaw "--noCache"
|> CmdLine.appendRaw "--test:js-temporal"

Command.Fable(fableArgs, workingDirectory = destinationDir)

// Run only the date/time suites directly (no shell), so the regex alternation
// in --test-name-pattern is passed to node as a single, unmangled argument.
let nodeArgs =
CmdLine.empty
|> CmdLine.appendPrefix "--test-reporter" "spec"
|> CmdLine.appendPrefix "--test-timeout" "20000"
|> CmdLine.appendPrefix "--test-name-pattern" "^(DateTime|DateTimeOffset|DateOnly|TimeOnly|TimeSpan)$"
|> CmdLine.appendPrefix "--test" (destinationDir </> "Main.js")
|> CmdLine.toString

Command.Run("node", nodeArgs, workingDirectory = destinationDir)

let private handleMainTests (isWatch: bool) (noDotnet: bool) =
let folderName = "Main"
let sourceDir = Path.Resolve("tests", "Js", folderName)
Expand Down Expand Up @@ -144,6 +179,9 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =
// Test the Main tests against JavaScript
Command.Fable(fableArgs, workingDirectory = destinationDir)

// Re-run the date/time suites with the Temporal representation enabled
handleMainTestsTemporal ()

testReact false
testAdaptive false

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
40 changes: 32 additions & 8 deletions src/Fable.Transforms/Babel/Fable2Babel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -742,11 +742,31 @@ module Annotation =
let makeBuiltinTypeAnnotation com ctx typ kind =
match kind with
| Replacements.Util.BclGuid -> StringTypeAnnotation
| 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.BclTimeSpan ->
if com.Options.JsTemporal then
makeFableLibImportTypeAnnotation com ctx [] "TimeSpanTemporal" "Duration"
else
NumberTypeAnnotation
| Replacements.Util.BclDateTime ->
if com.Options.JsTemporal then
makeFableLibImportTypeAnnotation com ctx [] "DateTimeTemporal" "PlainDateTime"
else
makeAliasTypeAnnotation com ctx "Date"
| Replacements.Util.BclDateTimeOffset ->
if com.Options.JsTemporal then
makeFableLibImportTypeAnnotation com ctx [] "DateTimeOffsetTemporal" "ZonedDateTime"
else
makeAliasTypeAnnotation com ctx "Date"
| 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 +3531,15 @@ 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 when com.Options.JsTemporal -> libCall com ctx None "TimeSpanTemporal" "zero" [] []
| 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 BclDateTime -> libCall com ctx None (JS.Replacements.dateTimeModule com) "minValue" [] []
| Builtin BclDateTimeOffset ->
libCall com ctx None (JS.Replacements.dateTimeOffsetModule com) "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