Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Nagareyama #54

Closed
Closed
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
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"fable": {
"version": "3.0.0-nagareyama-alpha-007",
"commands": [
"fable"
]
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.fs.js
public/bundle.js*

# Node
Expand Down
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"args": [
"-r",
"esm",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/dist/tests"
],
"internalConsoleOptions": "openOnSessionStart",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
},
]
}
1,237 changes: 824 additions & 413 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
"scripts": {
"build": "webpack-cli --mode production",
"start": "webpack-dev-server",
"pretest": "fable-splitter test -o dist/tests --commonjs",
"test": "mocha dist/tests",
"headless-tests": "webpack-cli --mode production && dotnet run --project ./headless/Headless.fsproj"
"pretest": "dotnet fable test --outDir dist/tests",
"test": "mocha dist/tests -r esm",
"headless-tests": "dotnet fable test && webpack-cli --mode production && dotnet run --project ./headless/Headless.fsproj"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-loader": "^8.0.0",
"fable-compiler": "^2.10.1",
"fable-loader": "^2.1.9",
"fable-splitter": "^2.1.13",
"mocha": "^6.2.0",
"esm": "^3.2.25",
"mocha": "^8.1.3",
"webpack": "^4.27.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.0"
Expand Down
10 changes: 5 additions & 5 deletions src/Json.Converter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ module Convert =
failwithf "Union of records of type '%s' cannot be deserialized with the value of the discriminator key is not a string to match against a specific union case" unionType.Name
| otherwise ->
// TODO!!! Better error messages here
let unexpectedJson = JS.JSON.stringify otherwise
let expectedType = JS.JSON.stringify cases
let unexpectedJson = string otherwise
let expectedType = string cases
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're removing inheritance of union types because of performance reasons so we're giving up some utility methods like toJSON to avoid repetition in every class definition. We can consider to add them again, but using the string operators works here anyways.

failwithf "Expected JSON:\n%s\nto match the type\n%s" unexpectedJson expectedType
| JNull, TypeInfo.Option _ -> unbox None
| jsonValue, TypeInfo.Option optionalTypeDelayed when jsonValue <> JNull ->
Expand Down Expand Up @@ -337,8 +337,8 @@ module Convert =
FSharpValue.MakeUnion(caseInfo, parsedValues)
|> unbox
| otherwise ->
let unexpectedJson = JS.JSON.stringify otherwise
let expectedType = JS.JSON.stringify cases
let unexpectedJson = string otherwise
let expectedType = string cases
failwithf "Expected JSON:\n%s\nto match the type\n%s" unexpectedJson expectedType
// Arrays
| JArray values, TypeInfo.Array elementTypeDelayed ->
Expand Down Expand Up @@ -533,7 +533,7 @@ module Convert =
let unknownType = getType()
failwithf "Cannot convert %s to %s" (SimpleJson.toString input) unknownType.FullName
| _ ->
failwithf "Cannot convert %s to %s" (SimpleJson.toString input) (JS.JSON.stringify typeInfo)
failwithf "Cannot convert %s to %s" (SimpleJson.toString input) (string typeInfo)

let fromJson<'t> json typeInfo =
unbox<'t> (fromJsonAs json typeInfo)
Expand Down
8 changes: 4 additions & 4 deletions src/SimpleJson.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ module SimpleJson =
if isNullOrUndefined value
then JS.JSON.stringify(null)
else JS.JSON.stringify(value, (fun key v ->
if isDateOffset (get key jsThis) then
let dateOffset : DateTimeOffset = get key jsThis
if isDateOffset v then
let dateOffset : DateTimeOffset = !!v
box (dateOffset.ToString("O"))
elif isBigInt (get key jsThis) then
let bigInt : bigint = get key jsThis
elif isBigInt v then
let bigInt : bigint = !!v
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fails here if the function is compiled as an arrow function. But using the value directly works in either case.

box (string (decimal bigInt))
else
match v with
Expand Down
6 changes: 1 addition & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function (evn, argv) {
mode: mode,
devtool: isProduction ? false : "eval-source-map",
entry: {
app: ["@babel/polyfill", "./test/Tests.fsproj"]
app: ["@babel/polyfill", "./test/Tests.fs.js"]
},
output: {
filename: 'bundle.js',
Expand All @@ -30,10 +30,6 @@ module.exports = function (evn, argv) {
},
module: {
rules: [
{
test: /\.fs(x|proj)?$/,
use: "fable-loader"
},
{
test: /\.js$/,
exclude: /node_modules/,
Expand Down