我有以下 OCaml 程序打开 Js
let lex s = Compiler.Parse_js.lexer_from_file s
let parse s = lex s |> Compiler.Parse_js.parse
let buffer_pp program =
let buf = Buffer.create 10 in
let pp = Compiler.Pretty_print.to_buffer buf in
Compiler.Js_output.program pp program;
Buffer.contents buf |> print_endline
let () =
parse "test.js" |> buffer_pp
和下面的 JavaScript 程序
function person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
person.prototype.name = function() {
return this.firstName + " " + this.lastName;
};
运行编译的 ocaml 代码时,它会打印出来
function person(first,last,age,eyecolor)
{this.firstName=first;this.lastName=last;this.age=age;this.eyeColor=eyecolor}
person.prototype.name=function(){return this.firstName+" "+this.lastName};
有没有办法进行漂亮的打印以更好地显示格式?