Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions jscomp/lam_compile_group.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.meta)
*)
| Single(_, ({name="print_endline";_} as id),_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id
~exp:(E.js_global "console.log")
~exp:(let param = Ext_ident.create "param" in
E.fun_ [param] [S.return
(E.seq (E.call ~info:{arity=Full}
(E.js_global "console.log") [E.var param])
E.zero_int_literal )] )
| Single(_, ({name="prerr_endline";_} as id),_ ), "pervasives.ml" ->
Js_output.of_stmt @@ S.alias_variable id
~exp:(E.js_global "console.error")
~exp:(let param = Ext_ident.create "param" in
E.fun_ [param] [S.return
(E.seq (E.call ~info:{arity=Full}
(E.js_global "console.error") [E.var param])
E.zero_int_literal )] )


| Single(_, ({name="string_of_int";_} as id),_ ), "pervasives.ml" ->
Expand Down
10 changes: 8 additions & 2 deletions jscomp/stdlib/pervasives.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ function print_float(f) {
return output_string(stdout, valid_float_lexem(Caml_format.caml_format_float("%.12g", f)));
}

var print_endline = console.log;
function print_endline(param) {
console.log(param);
return 0;
}

function print_newline() {
Caml_io.caml_ml_output_char(stdout, /* "\n" */10);
Expand All @@ -471,7 +474,10 @@ function prerr_float(f) {
return output_string(stderr, valid_float_lexem(Caml_format.caml_format_float("%.12g", f)));
}

var prerr_endline = console.error;
function prerr_endline(param) {
console.error(param);
return 0;
}

function prerr_newline() {
Caml_io.caml_ml_output_char(stderr, /* "\n" */10);
Expand Down
4 changes: 4 additions & 0 deletions jscomp/test/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ int_overflow_test.cmo : ../stdlib/string.cmi mt.cmi ../stdlib/int32.cmi \
../stdlib/char.cmi
int_overflow_test.cmx : ../stdlib/string.cmx mt.cmx ../stdlib/int32.cmx \
../stdlib/char.cmx
io_test.cmo : ../lib/js.cmi
io_test.cmx : ../lib/js.cmx
js_bool_test.cmo : mt.cmi ../lib/js.cmi
js_bool_test.cmx : mt.cmx ../lib/js.cmx
js_date_test.cmo : mt.cmi ../lib/js_date.cmo
Expand Down Expand Up @@ -618,6 +620,8 @@ int_overflow_test.cmo : ../stdlib/string.cmi mt.cmi ../stdlib/int32.cmi \
../stdlib/char.cmi
int_overflow_test.cmj : ../stdlib/string.cmj mt.cmj ../stdlib/int32.cmj \
../stdlib/char.cmj
io_test.cmo : ../lib/js.cmi
io_test.cmj : ../lib/js.cmj
js_bool_test.cmo : mt.cmi ../lib/js.cmi
js_bool_test.cmj : mt.cmj ../lib/js.cmj
js_date_test.cmo : mt.cmi ../lib/js_date.cmo
Expand Down
2 changes: 2 additions & 0 deletions jscomp/test/io_test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export var f: (param : any) => any ;

13 changes: 13 additions & 0 deletions jscomp/test/io_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Generated CODE, PLEASE EDIT WITH CARE
'use strict';


function f() {
var v = (console.error("x"), /* () */0);
console.log(v);
console.log((console.log("hi"), /* () */0));
return /* () */0;
}

exports.f = f;
/* No side effect */
7 changes: 7 additions & 0 deletions jscomp/test/io_test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


let f () =
let v = prerr_endline "x" in
Js.log v ;
let u = print_endline "hi" in
Js.log u
3 changes: 2 additions & 1 deletion jscomp/test/test.mllib
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,5 @@ debugger_test
caml_format_test

js_val
epsilon_test
epsilon_test
io_test