Skip to content

Improve code generated for template literals. #6090

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
Mar 21, 2023
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ These are only breaking changes for unformatted code.
- PPX V3: allow uncurried `make` function and treat it like a curried one https://github.com/rescript-lang/rescript-compiler/pull/6081
- Add support for `|>` in uncurried mode by desugaring it https://github.com/rescript-lang/rescript-compiler/pull/6083
- Change the compilation of pattern matching for variants so it does not depends on variats being integers https://github.com/rescript-lang/rescript-compiler/pull/6085
- Improve code generated for string templates https://github.com/rescript-lang/rescript-compiler/pull/6090

# 10.1.4

Expand Down
2 changes: 2 additions & 0 deletions jscomp/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ let rec string_append ?comment (e : t) (el : t) : t =
{ e with expression_desc = Str { txt = a ^ b; delim } }
in
match (e.expression_desc, el.expression_desc) with
| Str { txt = ""}, _ -> el
| _, Str { txt = ""} -> e
| ( Str { txt = a; delim },
String_append ({ expression_desc = Str { txt = b; delim = delim_ } }, c) )
when delim = delim_ ->
Expand Down
8 changes: 4 additions & 4 deletions jscomp/test/caml_format_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function from_of_string(xs) {
var b = param[1];
var a = param[0];
return [
"of_string " + String(i) + "",
"of_string " + String(i),
(function (param) {
return {
TAG: /* Eq */0,
Expand Down Expand Up @@ -156,7 +156,7 @@ var suites = Pervasives.$at(from_of_string(of_string), Pervasives.$at({
var b = param[1];
var a = param[0];
return [
"infinity_of_string " + String(i) + "",
"infinity_of_string " + String(i),
(function (param) {
return {
TAG: /* Eq */0,
Expand Down Expand Up @@ -194,7 +194,7 @@ var suites = Pervasives.$at(from_of_string(of_string), Pervasives.$at({
var b = param[1];
var a = param[0];
return [
"normal_float_of_string " + String(i) + "",
"normal_float_of_string " + String(i),
(function (param) {
return {
TAG: /* Eq */0,
Expand Down Expand Up @@ -427,7 +427,7 @@ Mt.from_pair_suites("Caml_format_test", Pervasives.$at(suites, Pervasives.$at($$
var f = param[1];
var fmt = param[0];
return [
"loat_format " + String(i) + "",
"loat_format " + String(i),
(function (param) {
return {
TAG: /* Eq */0,
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/ext_filename_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function find_root_filename(_cwd, filename) {
_cwd = cwd$p;
continue ;
}
var s = "" + filename + " not found from " + cwd;
var s = filename + " not found from " + cwd;
throw {
RE_EXN_ID: "Failure",
_1: s,
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/int64_mul_div_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function from_pairs(prefix, pairs) {
var a = param[1];
var result = param[0];
return [
"" + prefix + "_" + i,
prefix + "_" + i,
(function (param) {
return commutative_mul(result, a, b);
})
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/mario_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -3331,7 +3331,7 @@ function load(param) {
if (el !== null) {
canvas = el;
} else {
console.log("cant find canvas " + canvas_id + "");
console.log("cant find canvas " + canvas_id);
throw {
RE_EXN_ID: "Failure",
_1: "fail",
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var bla2 = "";

function concat(param) {
return "\n display:\r flex;\n " + bla2 + "";
return "\n display:\r flex;\n " + bla2;
}

exports.bla2 = bla2;
Expand Down
12 changes: 6 additions & 6 deletions lib/es6/arg.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function add_help(speclist) {
}

function usage_b(buf, speclist, errmsg) {
$$Buffer.add_string(buf, "" + errmsg + "\n");
$$Buffer.add_string(buf, errmsg + "\n");
List.iter((function (param) {
var doc = param[2];
if (doc.length === 0) {
Expand All @@ -132,7 +132,7 @@ function usage_b(buf, speclist, errmsg) {
return $$Buffer.add_string(buf, " " + key + " " + doc + "\n");
}
var sym = make_symlist("{", "|", "}", spec._0);
return $$Buffer.add_string(buf, " " + key + " " + sym + "" + doc + "\n");
return $$Buffer.add_string(buf, " " + key + " " + sym + doc + "\n");
}), add_help(speclist));
}

Expand Down Expand Up @@ -202,17 +202,17 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist
case "-help" :
break;
default:
$$Buffer.add_string(b, "" + progname + ": unknown option '" + s + "'.\n");
$$Buffer.add_string(b, progname + ": unknown option '" + s + "'.\n");
}
break;
case /* Wrong */1 :
$$Buffer.add_string(b, "" + progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n");
$$Buffer.add_string(b, progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n");
break;
case /* Missing */2 :
$$Buffer.add_string(b, "" + progname + ": option '" + error._0 + "' needs an argument.\n");
$$Buffer.add_string(b, progname + ": option '" + error._0 + "' needs an argument.\n");
break;
case /* Message */3 :
$$Buffer.add_string(b, "" + progname + ": " + error._0 + ".\n");
$$Buffer.add_string(b, progname + ": " + error._0 + ".\n");
break;

}
Expand Down
12 changes: 6 additions & 6 deletions lib/js/arg.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function add_help(speclist) {
}

function usage_b(buf, speclist, errmsg) {
$$Buffer.add_string(buf, "" + errmsg + "\n");
$$Buffer.add_string(buf, errmsg + "\n");
List.iter((function (param) {
var doc = param[2];
if (doc.length === 0) {
Expand All @@ -132,7 +132,7 @@ function usage_b(buf, speclist, errmsg) {
return $$Buffer.add_string(buf, " " + key + " " + doc + "\n");
}
var sym = make_symlist("{", "|", "}", spec._0);
return $$Buffer.add_string(buf, " " + key + " " + sym + "" + doc + "\n");
return $$Buffer.add_string(buf, " " + key + " " + sym + doc + "\n");
}), add_help(speclist));
}

Expand Down Expand Up @@ -202,17 +202,17 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist
case "-help" :
break;
default:
$$Buffer.add_string(b, "" + progname + ": unknown option '" + s + "'.\n");
$$Buffer.add_string(b, progname + ": unknown option '" + s + "'.\n");
}
break;
case /* Wrong */1 :
$$Buffer.add_string(b, "" + progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n");
$$Buffer.add_string(b, progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n");
break;
case /* Missing */2 :
$$Buffer.add_string(b, "" + progname + ": option '" + error._0 + "' needs an argument.\n");
$$Buffer.add_string(b, progname + ": option '" + error._0 + "' needs an argument.\n");
break;
case /* Message */3 :
$$Buffer.add_string(b, "" + progname + ": " + error._0 + ".\n");
$$Buffer.add_string(b, progname + ": " + error._0 + ".\n");
break;

}
Expand Down