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

classify js bigint type correctly #5351

Merged
merged 4 commits into from
Jun 30, 2022
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
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Add support for `@new @variadic` (see https://github.com/rescript-lang/rescript-compiler/pull/5364)
- New records with `@optional` fields [#5423](https://github.com/rescript-lang/rescript-compiler/pull/5423) [#5452](https://github.com/rescript-lang/rescript-compiler/issues/5452)
- Classify bigint correctly [#5351](https://github.com/rescript-lang/rescript-compiler/pull/5351)

**Syntax**

Expand Down
8 changes: 4 additions & 4 deletions jscomp/main/builtin_cmi_datasets.ml

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions jscomp/others/js_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
type symbol
(** Js symbol type only available in ES6 *)

type bigint_val
(** Js bigint type only available in ES2020 *)

type obj_val
type undefined_val
(** This type has only one value `undefined` *)
Expand All @@ -45,6 +48,7 @@ type _ t =
| Function : function_val t
| Object : obj_val t
| Symbol : symbol t
| BigInt : bigint_val t



Expand All @@ -58,6 +62,7 @@ type tagged_t =
| JSFunction of function_val
| JSObject of obj_val
| JSSymbol of symbol
| JSBigInt of bigint_val

let classify (x : 'a) : tagged_t =
let ty = Js.typeof x in
Expand All @@ -66,18 +71,20 @@ let classify (x : 'a) : tagged_t =
if x == (Obj.magic Js_null.empty) then
JSNull else
if ty = "number" then
JSNumber (Obj.magic x ) else
JSNumber (Obj.magic x) else
if ty = "bigint" then
JSBigInt (Obj.magic x) else
if ty = "string" then
JSString (Obj.magic x) else
if ty = "boolean" then
if (Obj.magic x) = true then JSTrue
if (Obj.magic x) = true then JSTrue
else JSFalse else
if ty = "symbol" then
JSSymbol (Obj.magic x) else
if ty = "function" then
JSFunction (Obj.magic x) else
if ty = "object" then
JSObject (Obj.magic x)
JSFunction (Obj.magic x)
else
JSSymbol (Obj.magic x)
JSObject (Obj.magic x)


let test (type a) (x : 'a) (v : a t) : bool =
Expand Down Expand Up @@ -105,5 +112,7 @@ let test (type a) (x : 'a) (v : a t) : bool =
Js.typeof x = "object"
| Symbol
->
Js.typeof x = "symbol"

Js.typeof x = "symbol"
| BigInt
->
Js.typeof x = "bigint"
5 changes: 5 additions & 0 deletions jscomp/others/js_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
type symbol
(** Js symbol type (only available in ES6) *)

type bigint_val
(** Js bigint type only available in ES2020 *)

type obj_val

type undefined_val
Expand All @@ -46,6 +49,7 @@ type _ t =
| Function : function_val t
| Object : obj_val t
| Symbol : symbol t
| BigInt : bigint_val t

val test : 'a -> 'b t -> bool
(**
Expand All @@ -69,5 +73,6 @@ type tagged_t =
| JSFunction of function_val
| JSObject of obj_val
| JSSymbol of symbol
| JSBigInt of bigint_val

val classify : 'a -> tagged_t
3 changes: 2 additions & 1 deletion jscomp/test/typeof_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ let string_or_number (type t) x =
| JSFalse | JSTrue -> false
| JSFunction _ -> Js.log ("Function"); false
| JSObject _ -> false
| JSSymbol _ -> false
| JSSymbol _ -> false
| JSBigInt _ -> false

let suites = Mt.[
"int_type", (fun _ -> Eq(Js.typeof 3, "number") );
Expand Down
4 changes: 1 addition & 3 deletions lib/4.06.1/rescript.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5492,10 +5492,8 @@ end = struct
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
let version = "10.0.0"

let version = "10.0.0-beta.1"
let header = "// Generated by ReScript, PLEASE EDIT WITH CARE"

let package_name = ref "rescript"

end
Expand Down
12 changes: 5 additions & 7 deletions lib/4.06.1/unstable/js_compiler.ml

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions lib/4.06.1/unstable/js_playground_compiler.ml

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions lib/4.06.1/whole_compiler.ml

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions lib/es6/js_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ function classify(x) {
TAG: /* JSNumber */0,
_0: x
};
} else if (ty === "bigint") {
return {
TAG: /* JSBigInt */5,
_0: x
};
} else if (ty === "string") {
return {
TAG: /* JSString */1,
Expand All @@ -23,19 +28,19 @@ function classify(x) {
} else {
return /* JSFalse */0;
}
} else if (ty === "function") {
} else if (ty === "symbol") {
return {
TAG: /* JSFunction */2,
TAG: /* JSSymbol */4,
_0: x
};
} else if (ty === "object") {
} else if (ty === "function") {
return {
TAG: /* JSObject */3,
TAG: /* JSFunction */2,
_0: x
};
} else {
return {
TAG: /* JSSymbol */4,
TAG: /* JSObject */3,
_0: x
};
}
Expand All @@ -59,6 +64,8 @@ function test(x, v) {
return typeof x === "object";
case /* Symbol */7 :
return typeof x === "symbol";
case /* BigInt */8 :
return typeof x === "bigint";

}
}
Expand Down
17 changes: 12 additions & 5 deletions lib/js/js_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ function classify(x) {
TAG: /* JSNumber */0,
_0: x
};
} else if (ty === "bigint") {
return {
TAG: /* JSBigInt */5,
_0: x
};
} else if (ty === "string") {
return {
TAG: /* JSString */1,
Expand All @@ -23,19 +28,19 @@ function classify(x) {
} else {
return /* JSFalse */0;
}
} else if (ty === "function") {
} else if (ty === "symbol") {
return {
TAG: /* JSFunction */2,
TAG: /* JSSymbol */4,
_0: x
};
} else if (ty === "object") {
} else if (ty === "function") {
return {
TAG: /* JSObject */3,
TAG: /* JSFunction */2,
_0: x
};
} else {
return {
TAG: /* JSSymbol */4,
TAG: /* JSObject */3,
_0: x
};
}
Expand All @@ -59,6 +64,8 @@ function test(x, v) {
return typeof x === "object";
case /* Symbol */7 :
return typeof x === "symbol";
case /* BigInt */8 :
return typeof x === "bigint";

}
}
Expand Down