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

feat: emit let instead of var #1019

Merged
merged 5 commits into from
Feb 6, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Unreleased
([#1036](https://github.com/melange-re/melange/pull/1036))
- stdlib: fix runtime primitive for `Float.{min,max}` and related functions
([#1050](https://github.com/melange-re/melange/pull/1050))
- core: emit `let` instead of `var` in compiled JS
([#1019](https://github.com/melange-re/melange/pull/1019))

3.0.0 2024-01-28
---------------
Expand Down
4 changes: 2 additions & 2 deletions jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ let pp_paren_params (cxt : cxt) (lexical : Ident.t list) : unit =
id) *)

let pp_var_assign cxt id =
string cxt L.var;
string cxt L.let_;
space cxt;
let acxt = ident cxt id in
space cxt;
Expand All @@ -241,7 +241,7 @@ let pp_var_assign_this cxt id =
cxt

let pp_var_declare cxt id =
string cxt L.var;
string cxt L.let_;
space cxt;
let acxt = ident cxt id in
semi cxt;
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_dump_import_export.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let requires require_lit cxt f (modules : (Ident.t * string * bool) list) =
in
P.at_least_two_lines f;
List.rev_iter reversed_list (fun (s, file, default) ->
P.string f L.var;
P.string f L.let_;
P.space f;
P.string f s;
P.space f;
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_dump_lit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

let function_ = "function"
let var = "var" (* should be able to switch to [let] easily*)
let let_ = "let"
let return = "return"
let require = "require"
let import = "import"
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/dist-es6/jscomp/test/es6_tests/es6_export.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Generated by Melange


var $$default = 3;
let $$default = 3;

export {
$$default as default,
Expand Down
34 changes: 17 additions & 17 deletions jscomp/test/dist-es6/jscomp/test/mt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ function assert_fail(msg) {
}

function is_mocha(param) {
var match = Stdlib__Array.to_list(Process.argv);
let match = Stdlib__Array.to_list(Process.argv);
if (!match) {
return false;
}
var match$1 = match.tl;
let match$1 = match.tl;
if (!match$1) {
return false;
}
var exec = Path.basename(match$1.hd);
let exec = Path.basename(match$1.hd);
if (exec === "mocha") {
return true;
} else {
Expand All @@ -29,11 +29,11 @@ function is_mocha(param) {
}

function from_suites(name, suite) {
var match = Stdlib__Array.to_list(Process.argv);
let match = Stdlib__Array.to_list(Process.argv);
if (match && is_mocha(undefined)) {
describe(name, (function () {
return Stdlib__List.iter((function (param) {
var partial_arg = param[1];
let partial_arg = param[1];
it(param[0], (function () {
return Curry._1(partial_arg, undefined);
}));
Expand All @@ -45,7 +45,7 @@ function from_suites(name, suite) {
}

function close_enough(thresholdOpt, a, b) {
var threshold = thresholdOpt !== undefined ? thresholdOpt : 0.0000001;
let threshold = thresholdOpt !== undefined ? thresholdOpt : 0.0000001;
return Math.abs(a - b) < threshold;
}

Expand All @@ -67,17 +67,17 @@ function handleCode(spec) {
Assert.ok(spec._0);
return ;
case /* Approx */5 :
var b = spec._1;
var a = spec._0;
let b = spec._1;
let a = spec._0;
if (!close_enough(undefined, a, b)) {
Assert.deepEqual(a, b);
return ;
} else {
return ;
}
case /* ApproxThreshold */6 :
var b$1 = spec._2;
var a$1 = spec._1;
let b$1 = spec._2;
let a$1 = spec._1;
if (!close_enough(spec._0, a$1, b$1)) {
Assert.deepEqual(a$1, b$1);
return ;
Expand All @@ -96,12 +96,12 @@ function handleCode(spec) {
}

function from_pair_suites(name, suites) {
var match = Stdlib__Array.to_list(Process.argv);
let match = Stdlib__Array.to_list(Process.argv);
if (match) {
if (is_mocha(undefined)) {
describe(name, (function () {
return Stdlib__List.iter((function (param) {
var code = param[1];
let code = param[1];
it(param[0], (function () {
return handleCode(Curry._1(code, undefined));
}));
Expand All @@ -114,8 +114,8 @@ function from_pair_suites(name, suites) {
"testing"
]);
return Stdlib__List.iter((function (param) {
var name = param[0];
var _fn = Curry._1(param[1], undefined);
let name = param[0];
let _fn = Curry._1(param[1], undefined);
switch (_fn.TAG | 0) {
case /* Eq */0 :
console.log([
Expand Down Expand Up @@ -191,15 +191,15 @@ function from_pair_suites(name, suites) {

}

var val_unit = Promise.resolve(undefined);
let val_unit = Promise.resolve(undefined);

function from_promise_suites(name, suites) {
var match = Stdlib__Array.to_list(Process.argv);
let match = Stdlib__Array.to_list(Process.argv);
if (match) {
if (is_mocha(undefined)) {
describe(name, (function () {
return Stdlib__List.iter((function (param) {
var code = param[1];
let code = param[1];
it(param[0], (function () {
return code.then(function (x) {
handleCode(x);
Expand Down
22 changes: 11 additions & 11 deletions jscomp/test/dist/jscomp/test/406_primitive_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 jscomp/test/dist/jscomp/test/a_filename_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 jscomp/test/dist/jscomp/test/a_list_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 jscomp/test/dist/jscomp/test/a_recursive_type.js

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

8 changes: 4 additions & 4 deletions jscomp/test/dist/jscomp/test/a_scope_bug.js

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

16 changes: 8 additions & 8 deletions jscomp/test/dist/jscomp/test/a_string_test.js

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

2 changes: 1 addition & 1 deletion jscomp/test/dist/jscomp/test/acyc/a0_a1.js

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

4 changes: 2 additions & 2 deletions jscomp/test/dist/jscomp/test/acyc/a1_a2.js

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

Loading