diff --git a/lib/es6/js_exn.js b/lib/es6/js_exn.js index b377a7d4ec..3e55225bfe 100644 --- a/lib/es6/js_exn.js +++ b/lib/es6/js_exn.js @@ -5,9 +5,8 @@ import * as Primitive_option from "./primitive_option.js"; let $$Error = "JsError"; function asJsExn(exn) { - let t = exn; - if (t.RE_EXN_ID === $$Error) { - return Primitive_option.some(t._1); + if (exn.RE_EXN_ID === $$Error) { + return Primitive_option.some(exn._1); } } diff --git a/lib/es6/obj.js b/lib/es6/obj.js index c436633a10..ae1b9f17e6 100644 --- a/lib/es6/obj.js +++ b/lib/es6/obj.js @@ -1,51 +1 @@ - - - -function magic(prim) { - return prim; -} - -function repr(prim) { - return prim; -} - -function obj(prim) { - return prim; -} - -function tag(prim) { - return prim.TAG; -} - -function size(prim) { - return prim.length | 0; -} - -function field(prim0, prim1) { - return prim0[prim1]; -} - -function set_field(prim0, prim1, prim2) { - prim0[prim1] = prim2; -} - -function dup(prim) { - return {...prim}; -} - -function update_dummy(prim0, prim1) { - Object.assign(prim0, prim1); -} - -export { - magic, - repr, - obj, - tag, - size, - field, - set_field, - dup, - update_dummy, -} -/* No side effect */ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/lib/es6/string.js b/lib/es6/string.js index 9f8621b6ae..66c0818ad4 100644 --- a/lib/es6/string.js +++ b/lib/es6/string.js @@ -17,18 +17,6 @@ function concat(sep, xs) { return $$Array.of_list(xs).join(sep); } -function length(prim) { - return prim.length; -} - -function get(prim0, prim1) { - return prim0.codePointAt(prim1); -} - -function unsafe_get(prim0, prim1) { - return prim0.codePointAt(prim1); -} - function bos(str) { return $$Array.map(str => str.codePointAt(0), Array.from(str)); } @@ -306,8 +294,6 @@ function split_on_char(sep, s) { } export { - length, - get, make, init, sub, @@ -333,6 +319,5 @@ export { capitalize_ascii, uncapitalize_ascii, split_on_char, - unsafe_get, } /* No side effect */ diff --git a/lib/js/js_exn.js b/lib/js/js_exn.js index 07a77f6631..119fd1a8ea 100644 --- a/lib/js/js_exn.js +++ b/lib/js/js_exn.js @@ -5,9 +5,8 @@ let Primitive_option = require("./primitive_option.js"); let $$Error = "JsError"; function asJsExn(exn) { - let t = exn; - if (t.RE_EXN_ID === $$Error) { - return Primitive_option.some(t._1); + if (exn.RE_EXN_ID === $$Error) { + return Primitive_option.some(exn._1); } } diff --git a/lib/js/obj.js b/lib/js/obj.js index fffba72d0c..ae1b9f17e6 100644 --- a/lib/js/obj.js +++ b/lib/js/obj.js @@ -1,49 +1 @@ -'use strict'; - - -function magic(prim) { - return prim; -} - -function repr(prim) { - return prim; -} - -function obj(prim) { - return prim; -} - -function tag(prim) { - return prim.TAG; -} - -function size(prim) { - return prim.length | 0; -} - -function field(prim0, prim1) { - return prim0[prim1]; -} - -function set_field(prim0, prim1, prim2) { - prim0[prim1] = prim2; -} - -function dup(prim) { - return {...prim}; -} - -function update_dummy(prim0, prim1) { - Object.assign(prim0, prim1); -} - -exports.magic = magic; -exports.repr = repr; -exports.obj = obj; -exports.tag = tag; -exports.size = size; -exports.field = field; -exports.set_field = set_field; -exports.dup = dup; -exports.update_dummy = update_dummy; -/* No side effect */ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/lib/js/string.js b/lib/js/string.js index b9e2c62b0e..1ac454fdd7 100644 --- a/lib/js/string.js +++ b/lib/js/string.js @@ -17,18 +17,6 @@ function concat(sep, xs) { return $$Array.of_list(xs).join(sep); } -function length(prim) { - return prim.length; -} - -function get(prim0, prim1) { - return prim0.codePointAt(prim1); -} - -function unsafe_get(prim0, prim1) { - return prim0.codePointAt(prim1); -} - function bos(str) { return $$Array.map(str => str.codePointAt(0), Array.from(str)); } @@ -305,8 +293,6 @@ function split_on_char(sep, s) { }; } -exports.length = length; -exports.get = get; exports.make = make; exports.init = init; exports.sub = sub; @@ -332,5 +318,4 @@ exports.lowercase_ascii = lowercase_ascii; exports.capitalize_ascii = capitalize_ascii; exports.uncapitalize_ascii = uncapitalize_ascii; exports.split_on_char = split_on_char; -exports.unsafe_get = unsafe_get; /* No side effect */ diff --git a/runtime/char.res b/runtime/char.res index a80fc11663..a3f1b05ecc 100644 --- a/runtime/char.res +++ b/runtime/char.res @@ -14,7 +14,7 @@ let chr = unsafe_chr external bytes_create: int => array = "Array" -let bytes_unsafe_set = Primitive_array_extern.setUnsafe +external bytes_unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" @scope("String") @variadic external unsafe_to_string: array => string = "fromCodePoint" diff --git a/runtime/obj.res b/runtime/obj.res index d794096fad..eacdb95a6e 100644 --- a/runtime/obj.res +++ b/runtime/obj.res @@ -4,28 +4,28 @@ type t = Primitive_object_extern.t -let magic = Primitive_object_extern.magic +external magic: 'a => 'b = "%identity" @deprecated("Do not use directly. This will be removed in v13") -let repr = Primitive_object_extern.repr +external repr: 'a => t = "%identity" @deprecated("Do not use directly. This will be removed in v13") -let obj = Primitive_object_extern.obj +external obj: t => 'a = "%identity" @deprecated("Do not use directly. This will be removed in v13") -let tag = Primitive_object_extern.tag +external tag: t => int = "%obj_tag" @deprecated("Do not use directly. This will be removed in v13") -let size = Primitive_object_extern.size +external size: t => int = "%obj_size" @deprecated("Do not use directly. This will be removed in v13") -let field = Primitive_object_extern.getField +external getField: (t, 'a) => t = "%obj_get_field" @deprecated("Do not use directly. This will be removed in v13") -let set_field = Primitive_object_extern.setField +external setField: (t, 'a, t) => unit = "%obj_set_field" @deprecated("Do not use directly. This will be removed in v13") -let dup = Primitive_object_extern.dup +external dup: t => t = "%obj_dup" -@deprecated("Do not use directly. This will be removed in v13") -let update_dummy = Primitive_object_extern.updateDummy +@deprecated("Do not use directly. This will be removed in v13") @scope("Object") +external updateDummy: (t, t) => unit = "assign" diff --git a/runtime/primitive_object.res b/runtime/primitive_object.res index 3324543da4..ae655a20d5 100644 --- a/runtime/primitive_object.res +++ b/runtime/primitive_object.res @@ -27,6 +27,8 @@ module Js = Primitive_js_extern type t = Primitive_object_extern.t +// Note: this only works as intended as long as the runtime is compiled +// with -bs-cross-module-opt. let repr = Primitive_object_extern.repr let magic = Primitive_object_extern.magic let tag = Primitive_object_extern.tag diff --git a/runtime/string.res b/runtime/string.res index 11fa4877f1..3613f1dde4 100644 --- a/runtime/string.res +++ b/runtime/string.res @@ -30,11 +30,11 @@ module B = { let concat = (sep: string, xs: list) => xs->Array.of_list->join(sep) -let length = Primitive_string_extern.length +external length: string => int = "%string_length" -let get = Primitive_string_extern.getCharUnsafe +@send external get: (string, int) => char = "codePointAt" -let unsafe_get = Primitive_string_extern.getCharUnsafe +@send external unsafe_get: (string, int) => char = "codePointAt" @scope("Array") external bos: string => array = "from" let bos = str => B.map(str => str->unsafe_get(0), str->bos) diff --git a/runtime/string.resi b/runtime/string.resi index 8ef4fbbc7d..a5bc660235 100644 --- a/runtime/string.resi +++ b/runtime/string.resi @@ -6,14 +6,15 @@ /** Return the length (number of characters) of the given string. */ @deprecated("Use Core instead. This will be removed in v13") -let length: string => int +external length: string => int = "%string_length" /** [String.get s n] returns the character at index [n] in string [s]. You can also write [s.[n]] instead of [String.get s n]. Raise [Invalid_argument] if [n] not a valid index in [s]. */ @deprecated("Use Core instead. This will be removed in v13") -let get: (string, int) => char +@send +external get: (string, int) => char = "codePointAt" /** [String.make n c] returns a fresh string of length [n], filled with the character [c]. */ @@ -245,5 +246,5 @@ external equal: (t, t) => bool = "%equal" let split_on_char: (char, string) => list /* The following is for system use only. Do not call directly. */ -@deprecated("Use Core instead. This will be removed in v13") -let unsafe_get: (string, int) => char +@deprecated("Use Core instead. This will be removed in v13") @send +external unsafe_get: (string, int) => char = "codePointAt" diff --git a/tests/gentype_tests/typescript-react-example/src/Hooks.res.js b/tests/gentype_tests/typescript-react-example/src/Hooks.res.js index d4e7549a27..669725e3fa 100644 --- a/tests/gentype_tests/typescript-react-example/src/Hooks.res.js +++ b/tests/gentype_tests/typescript-react-example/src/Hooks.res.js @@ -1,6 +1,5 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Obj from "rescript/lib/es6/obj.js"; import * as React from "react"; import * as ImportHooks from "./ImportHooks.res.js"; import * as Primitive_option from "rescript/lib/es6/primitive_option.js"; @@ -149,7 +148,7 @@ let testForwardRef = React.forwardRef((x, y) => makeWithRef(x)(y)); let input = React.forwardRef((r, ref) => JsxRuntime.jsx("div", { children: r.x, - ref: Primitive_option.some(Obj.magic(ref)) + ref: Primitive_option.some(ref) })); let ForwardRef = { diff --git a/tests/tests/src/module_missing_conversion.js b/tests/tests/src/module_missing_conversion.js index bc223525cb..6ccd36f3f2 100644 --- a/tests/tests/src/module_missing_conversion.js +++ b/tests/tests/src/module_missing_conversion.js @@ -3,7 +3,6 @@ let $$String = require("rescript/lib/js/string.js"); let Belt_Array = require("rescript/lib/js/belt_Array.js"); -let Primitive_array = require("rescript/lib/js/primitive_array.js"); function f(x) { return x; @@ -87,11 +86,9 @@ let XX = { let u = [$$String]; -let $$String$1 = Primitive_array.get(u, 0); - -let hh = $$String$1.length("x"); +let hh = "x".length; exports.XX = XX; exports.u = u; exports.hh = hh; -/* hh Not a pure module */ +/* No side effect */ diff --git a/tests/tests/src/module_parameter_test.js b/tests/tests/src/module_parameter_test.js index 0d923d5e38..ecfda775fd 100644 --- a/tests/tests/src/module_parameter_test.js +++ b/tests/tests/src/module_parameter_test.js @@ -14,10 +14,10 @@ let N = { s: s }; -let v0 = s.length("x"); +let v0 = "x".length; function v(x) { - return s.length(x); + return x.length; } let suites_0 = [ @@ -53,4 +53,4 @@ exports.N = N; exports.v0 = v0; exports.v = v; exports.suites = suites; -/* v0 Not a pure module */ +/* Not a pure module */ diff --git a/tests/tests/src/obj_magic_test.js b/tests/tests/src/obj_magic_test.js index 3485e5f0f1..7e6071f1f2 100644 --- a/tests/tests/src/obj_magic_test.js +++ b/tests/tests/src/obj_magic_test.js @@ -12,7 +12,7 @@ let suites_0 = [ param => ({ TAG: "Eq", _0: false, - _1: is_block(3) + _1: "number" !== "number" }) ]; @@ -22,10 +22,10 @@ let suites_1 = { param => ({ TAG: "Eq", _0: true, - _1: is_block({ + _1: typeof ({ hd: 3, tl: /* [] */0 - }) + }) !== "number" }) ], tl: { @@ -34,7 +34,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: true, - _1: is_block("x") + _1: "string" !== "number" }) ], tl: { @@ -43,7 +43,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: false, - _1: is_block(3.0) + _1: "number" !== "number" }) ], tl: /* [] */0 diff --git a/tests/tests/src/reasonReact.js b/tests/tests/src/reasonReact.js index daf33e32c8..afbce1d035 100644 --- a/tests/tests/src/reasonReact.js +++ b/tests/tests/src/reasonReact.js @@ -84,8 +84,7 @@ function element(keyOpt, refOpt, component) { } function wrapReasonForJs(component, jsPropsToReason) { - let jsPropsToReason$1 = jsPropsToReason; - let uncurriedJsPropsToReason = jsProps => jsPropsToReason$1(jsProps); + let uncurriedJsPropsToReason = jsProps => jsPropsToReason(jsProps); component.reactClassInternal.prototype.jsPropsToReason = uncurriedJsPropsToReason; return component.reactClassInternal; } diff --git a/tests/tests/src/rec_module_opt.js b/tests/tests/src/rec_module_opt.js index b5c4a5bfd7..51401e97a4 100644 --- a/tests/tests/src/rec_module_opt.js +++ b/tests/tests/src/rec_module_opt.js @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Obj = require("rescript/lib/js/obj.js"); let Belt_Id = require("rescript/lib/js/belt_Id.js"); let Primitive_module = require("rescript/lib/js/primitive_module.js"); let Primitive_string = require("rescript/lib/js/primitive_string.js"); @@ -30,7 +29,7 @@ function cmp(t1, t2) { } else if (t2.TAG === "Leaf") { return -1; } else { - return Obj.magic(AComparable.cmp)(t1._0, t2._0); + return AComparable.cmp(t1._0, t2._0); } }