Skip to content
Snippets Groups Projects
Commit b0d5f066 authored by Cesar Roux Dit Buisson's avatar Cesar Roux Dit Buisson
Browse files

Fix powered up function error by rewrite

Slightly hacky, force the = function syntax into a match.
Also rewrite variables using "'" as javascript doesn't support that.
parent df790ffe
No related branches found
No related tags found
No related merge requests found
......@@ -131,6 +131,9 @@ let is_infix f args = match args with
* to ECMAScript, therefore all of them are in a single place.
*)
(** Remove ' from variables and replace with "prime" **)
let sanitize_var = Str.global_replace (Str.regexp "'") "prime"
let ppf_lambda_wrap s =
Printf.sprintf "(function () {@;<1 2>@[<v 0>%s@]@,}())@," s
......@@ -224,7 +227,7 @@ let ppf_record llde =
let ppf_decl ?(mod_gen=[]) id expr =
let assign_op, decl_kw, end_mark = if mod_gen = [] then " = ", "var ", ";" else ": ", "", "," in
Printf.sprintf "@[<v 0>%s%s%s%s%s@,@]"
decl_kw id assign_op expr end_mark
decl_kw (sanitize_var id) assign_op expr end_mark
let ppf_pat_array id_list array_expr =
Printf.sprintf "var __%s = %s;@," "array" array_expr ^
......@@ -444,10 +447,10 @@ and js_of_constant = function
| Const_int32 n -> Int32.to_string n
| Const_int64 n -> Int64.to_string n
| Const_nativeint n -> Nativeint.to_string n
and js_of_longident loc =
let res = String.concat "." @@ Longident.flatten loc.txt in
if res = "()" then "undefined" else res
if res = "()" then "undefined" else sanitize_var res
and ident_of_pat pat = match pat.pat_desc with
| Tpat_var (id, _) -> Ident.name id
......@@ -481,7 +484,7 @@ and js_of_pattern ?(mod_gen=[]) pat obj =
let binders =
if List.length el = 0 then ""
else Printf.sprintf "@[<v 0>%s@]"
("var " ^ show_list ", " (List.map2 (fun x y -> x ^ " = " ^ obj ^ "." ^ y) (List.map (fun x -> fst (js_of_pattern ~mod_gen x obj)) el) params) ^ ";") in
("var " ^ show_list ", " (List.map2 (fun x y -> (sanitize_var x) ^ " = " ^ obj ^ "." ^ y) (List.map (fun x -> fst (js_of_pattern ~mod_gen x obj)) el) params) ^ ";") in
spat, binders
| Tpat_tuple el -> unsupported "tuple matching"
| Tpat_array el -> unsupported "array-match"
......
......@@ -7,6 +7,8 @@ foreach $fname (@ARGV) {
open(FILE, "< $fname") or die("Could not open $fname\n");
open(NEW, "> $fname.temp");
while($line = <FILE>) {
# Convert partial function to match syntax
$line =~ s/= function/autogeneratedtempvar = match autogeneratedtempvar with/g;
if ($line =~ m/^(?!.*\[.*?\])(?!.*->)(\s*\|.*?)(of (.*))?$/) {
$no = split(/\*/, $3);
$annot = " [\@f";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment