Skip to content

Commit 7ba6ca2

Browse files
Sync with main
1 parent f5a56a5 commit 7ba6ca2

File tree

12 files changed

+71
-26
lines changed

12 files changed

+71
-26
lines changed

src/Fable.Cli/ProjectCracker.fs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,9 @@ let copyDirIfDoesNotExist replaceFsprojExt (source: string) (target: string) =
494494
IO.File.Copy(fromPath, toPath, true)
495495

496496
let getFableLibraryPath (opts: CrackerOptions) =
497-
match opts.PrecompiledLib, opts.FableLib with
498-
| Some _, _ -> "" // Fable Library path will be taken from the precompiled info
499-
| None, Some path -> Path.normalizeFullPath path
500-
| None, None ->
497+
match opts.FableLib with
498+
| Some path -> Path.normalizeFullPath path
499+
| None ->
501500
let buildDir, libDir =
502501
match opts.FableOptions.Language with
503502
| Python -> "fable-library-py/fable_library", "fable_library"

src/Fable.Core/Fable.Core.JS.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ module JS =
247247
and [<AllowNullLiteral>] WeakSetConstructor =
248248
[<Emit("new $0($1...)")>] abstract Create: ?iterable: seq<'T> -> WeakSet<'T>
249249

250+
and [<AllowNullLiteral>] AsyncIterable =
251+
interface end
252+
253+
and [<AllowNullLiteral>] AsyncIterable<'T> =
254+
inherit AsyncIterable
255+
250256
and [<AllowNullLiteral>] Promise<'T> =
251257
abstract ``then``: ?onfulfilled: ('T->'TResult) * ?onrejected: (obj->'TResult) -> Promise<'TResult>
252258
abstract catch: ?onrejected: (obj->'T) -> Promise<'T>

src/Fable.Transforms/Dart/Replacements.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,12 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o
10601060

10611061
match i.CompiledName, args with
10621062
| ("DefaultArg" | "DefaultValueArg"), [nullable; defValue] ->
1063-
ifNullOp r t nullable defValue |> Some
1063+
match nullable with
1064+
| MaybeInScope ctx (Value(NewOption(opt, _, _),_)) ->
1065+
match opt with
1066+
| Some value -> Some value
1067+
| None -> Some defValue
1068+
| _ -> ifNullOp r t nullable defValue |> Some
10641069
| "DefaultAsyncBuilder", _ ->
10651070
makeImportLib com t "singleton" "AsyncBuilder" |> Some
10661071
| "KeyValuePattern", [arg] ->

src/Fable.Transforms/OverloadSuffix.fs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ let private getConstraintHash genParams = function
4343
let rec private getTypeFastFullName (genParams: IDictionary<_,_>) (t: Fable.Type) =
4444
match t with
4545
| Fable.Measure fullname -> fullname
46-
| Fable.GenericParam(name, _, constraints) ->
47-
match genParams.TryGetValue(name) with
48-
| true, i -> i
49-
| false, _ -> constraints |> List.map (getConstraintHash genParams) |> String.concat ","
46+
| Fable.GenericParam(name, isMeasure, constraints) ->
47+
if isMeasure then "measure"
48+
else
49+
match genParams.TryGetValue(name) with
50+
| true, i -> i
51+
| false, _ -> constraints |> List.map (getConstraintHash genParams) |> String.concat ","
5052
| Fable.Tuple(genArgs, isStruct) ->
5153
let genArgs = genArgs |> Seq.map (getTypeFastFullName genParams) |> String.concat " * "
5254
if isStruct then "struct " + genArgs

src/Fable.Transforms/Python/Replacements.fs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,11 +1279,13 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o
12791279
Helper.GlobalCall("math", t, args, argTypes, memb=meth, ?loc = r)
12801280

12811281
match i.CompiledName, args with
1282-
| ("DefaultArg"
1283-
| "DefaultValueArg"),
1284-
_ ->
1285-
Helper.LibCall(com, "option", "defaultArg", t, args, i.SignatureArgTypes, ?loc = r)
1286-
|> Some
1282+
| ("DefaultArg" | "DefaultValueArg"), [opt; defValue] ->
1283+
match opt with
1284+
| MaybeInScope ctx (Value(NewOption(opt, _, _),_)) ->
1285+
match opt with
1286+
| Some value -> Some value
1287+
| None -> Some defValue
1288+
| _ -> Helper.LibCall(com, "option", "defaultArg", t, args, i.SignatureArgTypes, ?loc = r) |> Some
12871289
| "DefaultAsyncBuilder", _ ->
12881290
makeImportLib com t "singleton" "async_builder"
12891291
|> Some

src/Fable.Transforms/Replacements.fs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,11 @@ let makePojo (com: Compiler) caseRule keyValueList =
660660
let name = defaultArg uci.CompiledName uci.Name
661661
makeObjMember caseRule name values::acc |> Some
662662
| Some acc, MaybeCasted(Value(NewTuple((StringConst name)::values,_),_)) ->
663-
// Don't change the case for tuples in disguise
664-
makeObjMember Core.CaseRules.None name values::acc |> Some
663+
match values with
664+
| [MaybeCasted(Value(NewOption(None, _, _), _))] -> Some acc
665+
| values ->
666+
// Don't change the case for tuples in disguise
667+
makeObjMember Core.CaseRules.None name values::acc |> Some
665668
| _ -> None))
666669
|> Option.map (fun members -> ObjectExpr(members, Any, None))
667670

@@ -1056,8 +1059,13 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o
10561059
Helper.GlobalCall("Math", t, args, argTypes, memb=meth, ?loc=r)
10571060

10581061
match i.CompiledName, args with
1059-
| ("DefaultArg" | "DefaultValueArg"), _ ->
1060-
Helper.LibCall(com, "Option", "defaultArg", t, args, i.SignatureArgTypes, ?loc=r) |> Some
1062+
| ("DefaultArg" | "DefaultValueArg"), [opt; defValue] ->
1063+
match opt with
1064+
| MaybeInScope ctx (Value(NewOption(opt, _, _),_)) ->
1065+
match opt with
1066+
| Some value -> Some value
1067+
| None -> Some defValue
1068+
| _ -> Helper.LibCall(com, "Option", "defaultArg", t, args, i.SignatureArgTypes, ?loc=r) |> Some
10611069
| "DefaultAsyncBuilder", _ ->
10621070
makeImportLib com t "singleton" "AsyncBuilder" |> Some
10631071
// Erased operators.

src/Fable.Transforms/Rust/Replacements.fs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,13 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o
922922
| _ -> "Missing argument." |> addErrorAndReturnNull com ctx.InlinePath r
923923

924924
match i.CompiledName, args with
925-
| ("DefaultArg" | "DefaultValueArg"), _ ->
926-
Helper.LibCall(com, "Option", "defaultArg", t, args, i.SignatureArgTypes, ?loc=r) |> Some
925+
| ("DefaultArg" | "DefaultValueArg"), [opt; defValue] ->
926+
match opt with
927+
| MaybeInScope ctx (Value(NewOption(opt, _, _),_)) ->
928+
match opt with
929+
| Some value -> Some value
930+
| None -> Some defValue
931+
| _ -> Helper.LibCall(com, "Option", "defaultArg", t, args, i.SignatureArgTypes, ?loc=r) |> Some
927932
| "DefaultAsyncBuilder", _ ->
928933
makeImportLib com t "singleton" "AsyncBuilder" |> Some
929934
// Erased operators.

src/fable-library/Types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export function toString(x: any, callStack = 0): string {
2828
} else if (Symbol.iterator in x) {
2929
return seqToString(x);
3030
} else { // TODO: Date?
31-
const cons = Object.getPrototypeOf(x).constructor;
31+
const cons = Object.getPrototypeOf(x)?.constructor;
3232
return cons === Object && callStack < 10
3333
// Same format as recordToString
3434
? "{ " + Object.entries(x).map(([k, v]) => k + " = " + toString(v, callStack + 1)).join("\n ") + " }"
35-
: cons.name;
35+
: cons?.name ?? "";
3636
}
3737
}
3838
return String(x);

src/fable-library/Util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function disposeSafe(x: any) {
8282
}
8383

8484
export function sameConstructor<T>(x: T, y: T) {
85-
return Object.getPrototypeOf(x).constructor === Object.getPrototypeOf(y).constructor;
85+
return Object.getPrototypeOf(x)?.constructor === Object.getPrototypeOf(y)?.constructor;
8686
}
8787

8888
export interface IEnumerator<T> extends IDisposable {
@@ -334,7 +334,7 @@ export function structuralHash<T>(x: T): number {
334334
return arrayHash(x);
335335
} else if (x instanceof Date) {
336336
return dateHash(x);
337-
} else if (Object.getPrototypeOf(x).constructor === Object) {
337+
} else if (Object.getPrototypeOf(x)?.constructor === Object) {
338338
// TODO: check call-stack to prevent cyclic objects?
339339
const hashes = Object.values(x).map((v) => structuralHash(v));
340340
return combineHashCodes(hashes);
@@ -403,7 +403,7 @@ export function equals<T>(x: T, y: T): boolean {
403403
} else if (x instanceof Date) {
404404
return (y instanceof Date) && compareDates(x, y) === 0;
405405
} else {
406-
return Object.getPrototypeOf(x).constructor === Object && equalObjects(x, y);
406+
return Object.getPrototypeOf(x)?.constructor === Object && equalObjects(x, y);
407407
}
408408
}
409409

@@ -480,7 +480,7 @@ export function compare<T>(x: T, y: T): number {
480480
} else if (x instanceof Date) {
481481
return y instanceof Date ? compareDates(x, y) : -1;
482482
} else {
483-
return Object.getPrototypeOf(x).constructor === Object ? compareObjects(x, y) : -1;
483+
return Object.getPrototypeOf(x)?.constructor === Object ? compareObjects(x, y) : -1;
484484
}
485485
}
486486

tests/Js/Main/JsInteropTests.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,13 @@ let tests =
380380
|> handleClass
381381
|> equal "Hello Narumi!!!!!!"
382382

383+
testCase "Can useq equals with Object.create(null)" <| fun () -> // See #2900
384+
let o: obj = emitJsExpr () "Object.create(null)"
385+
o = obj() |> equal false
386+
o = null |> equal false
387+
isNull o |> equal false
388+
jsTypeof o |> equal "object"
389+
383390
testCase "Dynamic application works" <| fun () ->
384391
let dynObj =
385392
createObj [

0 commit comments

Comments
 (0)