Skip to content

Fix Obj.magic, String.length etc. appearing in JS output #7087

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

Merged
merged 1 commit into from
Oct 7, 2024
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
5 changes: 2 additions & 3 deletions lib/es6/js_exn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down
52 changes: 1 addition & 51 deletions lib/es6/obj.js
Original file line number Diff line number Diff line change
@@ -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. */
15 changes: 0 additions & 15 deletions lib/es6/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -306,8 +294,6 @@ function split_on_char(sep, s) {
}

export {
length,
get,
make,
init,
sub,
Expand All @@ -333,6 +319,5 @@ export {
capitalize_ascii,
uncapitalize_ascii,
split_on_char,
unsafe_get,
}
/* No side effect */
5 changes: 2 additions & 3 deletions lib/js/js_exn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down
50 changes: 1 addition & 49 deletions lib/js/obj.js
Original file line number Diff line number Diff line change
@@ -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. */
15 changes: 0 additions & 15 deletions lib/js/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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;
Expand All @@ -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 */
2 changes: 1 addition & 1 deletion runtime/char.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let chr = unsafe_chr

external bytes_create: int => array<char> = "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<char> => string = "fromCodePoint"
Expand Down
20 changes: 10 additions & 10 deletions runtime/obj.res
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 2 additions & 0 deletions runtime/primitive_object.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions runtime/string.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ module B = {

let concat = (sep: string, xs: list<string>) => 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<string> = "from"
let bos = str => B.map(str => str->unsafe_get(0), str->bos)
Expand Down
9 changes: 5 additions & 4 deletions runtime/string.resi
Original file line number Diff line number Diff line change
Expand Up @@ -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]. */
Expand Down Expand Up @@ -245,5 +246,5 @@ external equal: (t, t) => bool = "%equal"
let split_on_char: (char, string) => list<string>

/* 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"

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions tests/tests/src/module_missing_conversion.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/tests/src/module_parameter_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tests/tests/src/obj_magic_test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading