From a154b01f25be5baad1db52b089830a1d33d2b926 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 16 Nov 2023 13:44:32 -0800 Subject: [PATCH] feat: remove `Js.Array2`, use labeled arguments for `Js.Array` (#895) * feat: remove `Js.Array2`, use labeled arguments for `Js.Array` * fix: tests * code review * revert lastIndexOf --- jscomp/runtime/js.ml | 3 - jscomp/runtime/js_array.ml | 232 +- jscomp/runtime/js_array2.ml | 213 -- jscomp/runtime/js_dict.ml | 18 +- jscomp/runtime/js_json.ml | 10 +- jscomp/runtime/js_string.ml | 2 +- jscomp/runtime/js_string2.ml | 2 +- jscomp/test/array_subtle_test.ml | 14 +- jscomp/test/bs_array_test.ml | 8 +- jscomp/test/bs_auto_uncurry_test.ml | 10 +- jscomp/test/bs_string_test.ml | 4 +- jscomp/test/chn_test.ml | 10 +- jscomp/test/dist/jscomp/test/chn_test.js | 2 +- jscomp/test/dist/jscomp/test/ffi_js_test.js | 4 +- .../dist/jscomp/test/flow_parser_reg_test.js | 2562 ++++++++--------- jscomp/test/dist/jscomp/test/js_array_test.js | 14 +- .../dist/jscomp/test/ocaml_parsetree_test.js | 28 +- .../dist/jscomp/test/ocaml_typedtree_test.js | 2224 +++++++------- jscomp/test/ffi_array_test.ml | 2 +- jscomp/test/ffi_js_test.ml | 4 +- jscomp/test/js_array_test.ml | 128 +- jscomp/test/js_json_test.ml | 2 +- jscomp/test/key_word_property_plus_test.ml | 2 +- jscomp/test/ppx_this_obj_field.ml | 2 +- jscomp/test/re_or_res/reactDOMRe.re | 20 +- jscomp/test/re_or_res/reasonReact.re | 24 +- 26 files changed, 2646 insertions(+), 2898 deletions(-) delete mode 100644 jscomp/runtime/js_array2.ml diff --git a/jscomp/runtime/js.ml b/jscomp/runtime/js.ml index 662ca6cbe3..9cc028735c 100644 --- a/jscomp/runtime/js.ml +++ b/jscomp/runtime/js.ml @@ -64,9 +64,6 @@ type +'a nullable = 'a Js_null_undefined.t type +'a null_undefined = 'a nullable -module Array2 = Js_array2 -(** Provide bindings to Js array*) - module Exn = Js_exn (** Provide utilities for dealing with Js exceptions *) diff --git a/jscomp/runtime/js_array.ml b/jscomp/runtime/js_array.ml index 80a1e9f8ee..fca801fe08 100644 --- a/jscomp/runtime/js_array.ml +++ b/jscomp/runtime/js_array.ml @@ -25,216 +25,180 @@ (** JavaScript Array API *) type 'a t = 'a array -type 'a array_like = 'a Js_array2.array_like +type 'a array_like -(* commented out until bs has a plan for iterators +(* commented out until Melange has a plan for iterators type 'a array_iter = 'a array_like *) external from : 'a array_like -> 'a array = "Array.from" (* ES2015 *) -external fromMap : 'a array_like -> (('a -> 'b)[@mel.uncurry]) -> 'b array +external fromMap : 'a array_like -> f:(('a -> 'b)[@mel.uncurry]) -> 'b array = "Array.from" - (* ES2015 *) external isArray : 'a -> bool = "Array.isArray" - -(* ES2015 *) (* ES2015 *) (* Array.of: seems pointless unless you can bind *) external length : 'a array -> int = "length" [@@mel.get] -(* Mutator functions -*) -external copyWithin : to_:int -> 'this = "copyWithin" -[@@mel.send.pipe: 'a t as 'this] -(* ES2015 *) - -external copyWithinFrom : to_:int -> from:int -> 'this = "copyWithin" -[@@mel.send.pipe: 'a t as 'this] -(* ES2015 *) +(** Mutating functions *) -external copyWithinFromRange : to_:int -> start:int -> end_:int -> 'this +external copyWithin : 'a t -> to_:int -> ?start:int -> ?end_:int -> unit -> 'a t = "copyWithin" -[@@mel.send.pipe: 'a t as 'this] -(* ES2015 *) - -external fillInPlace : 'a -> 'this = "fill" [@@mel.send.pipe: 'a t as 'this] +[@@mel.send] (* ES2015 *) -external fillFromInPlace : 'a -> from:int -> 'this = "fill" -[@@mel.send.pipe: 'a t as 'this] +external fill : 'a t -> value:'a -> ?start:int -> ?end_:int -> unit -> 'a t + = "fill" +[@@mel.send] (* ES2015 *) -external fillRangeInPlace : 'a -> start:int -> end_:int -> 'this = "fill" -[@@mel.send.pipe: 'a t as 'this] -(* ES2015 *) - -external pop : 'a option = "pop" -[@@mel.send.pipe: 'a t as 'this] [@@mel.return undefined_to_opt] +external pop : 'a t -> 'a option = "pop" +[@@mel.send] [@@mel.return undefined_to_opt] (** https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push *) -external push : 'a -> int = "push" [@@mel.send.pipe: 'a t as 'this] +external push : 'a t -> value:'a -> int = "push" [@@mel.send] -external pushMany : 'a array -> int = "push" -[@@mel.send.pipe: 'a t as 'this] [@@mel.splice] +external pushMany : 'a t -> values:'a array -> int = "push" +[@@mel.send] [@@mel.splice] -external reverseInPlace : 'this = "reverse" [@@mel.send.pipe: 'a t as 'this] +external reverseInPlace : 'a t -> 'a t = "reverse" [@@mel.send] -external shift : 'a option = "shift" -[@@mel.send.pipe: 'a t as 'this] [@@mel.return { undefined_to_opt }] +external shift : 'a t -> 'a option = "shift" +[@@mel.send] [@@mel.return undefined_to_opt] -external sortInPlace : 'this = "sort" [@@mel.send.pipe: 'a t as 'this] +external sortInPlace : 'a t -> 'a t = "sort" [@@mel.send] -external sortInPlaceWith : (('a -> 'a -> int)[@mel.uncurry]) -> 'this = "sort" -[@@mel.send.pipe: 'a t as 'this] +external sortInPlaceWith : 'a t -> f:(('a -> 'a -> int)[@mel.uncurry]) -> 'a t + = "sort" +[@@mel.send] -external spliceInPlace : pos:int -> remove:int -> add:'a array -> 'this +external spliceInPlace : 'a t -> pos:int -> remove:int -> add:'a array -> 'a t = "splice" -[@@mel.send.pipe: 'a t as 'this] [@@mel.splice] +[@@mel.send] [@@mel.splice] -external removeFromInPlace : pos:int -> 'this = "splice" -[@@mel.send.pipe: 'a t as 'this] +external removeFromInPlace : 'a t -> pos:int -> 'a t = "splice" [@@mel.send] -external removeCountInPlace : pos:int -> count:int -> 'this = "splice" -[@@mel.send.pipe: 'a t as 'this] +external removeCountInPlace : 'a t -> pos:int -> count:int -> 'a t = "splice" +[@@mel.send] (* screwy naming, but screwy function *) -external unshift : 'a -> int = "unshift" [@@mel.send.pipe: 'a t as 'this] - -external unshiftMany : 'a array -> int = "unshift" -[@@mel.send.pipe: 'a t as 'this] [@@mel.splice] +external unshift : 'a t -> value:'a -> int = "unshift" [@@mel.send] -(* Accessor functions -*) -external append : 'a -> 'this = "concat" -[@@mel.send.pipe: 'a t as 'this] -[@@deprecated "append is not type-safe. Use `concat` instead, and see #1884"] - -external concat : 'this -> 'this = "concat" [@@mel.send.pipe: 'a t as 'this] - -external concatMany : 'this array -> 'this = "concat" -[@@mel.send.pipe: 'a t as 'this] [@@mel.splice] - -(* TODO: Not available in Node V4 *) -external includes : 'a -> bool = "includes" -[@@mel.send.pipe: 'a t as 'this] -(** ES2016 *) - -external indexOf : 'a -> int = "indexOf" [@@mel.send.pipe: 'a t as 'this] - -external indexOfFrom : 'a -> from:int -> int = "indexOf" -[@@mel.send.pipe: 'a t as 'this] +external unshiftMany : 'a t -> values:'a array -> int = "unshift" +[@@mel.send] [@@mel.splice] -external join : 'a t -> string = "join" -[@@mel.send] [@@deprecated "please use joinWith instead"] +external concat : 'a t -> other:'a t -> 'a t = "concat" [@@mel.send] -external joinWith : string -> string = "join" [@@mel.send.pipe: 'a t as 'this] +external concatMany : 'a t -> arrays:'a t array -> 'a t = "concat" +[@@mel.send] [@@mel.splice] -external lastIndexOf : 'a -> int = "lastIndexOf" -[@@mel.send.pipe: 'a t as 'this] +external includes : 'a t -> value:'a -> bool = "includes" +[@@mel.send] +(** ES2015 *) -external lastIndexOfFrom : 'a -> from:int -> int = "lastIndexOf" -[@@mel.send.pipe: 'a t as 'this] +external join : 'a t -> ?sep:string -> string = "join" [@@mel.send] -external lastIndexOf_start : 'a -> int = "lastIndexOf" -[@@mel.send.pipe: 'a t as 'this] [@@deprecated "Please use `lastIndexOf"] +(** Accessor functions *) -external slice : start:int -> end_:int -> 'this = "slice" -[@@mel.send.pipe: 'a t as 'this] +external indexOf : 'a t -> value:'a -> ?start:int -> unit -> int = "indexOf" +[@@mel.send] -external copy : 'this = "slice" [@@mel.send.pipe: 'a t as 'this] +external lastIndexOf : 'a t -> value:'a -> int = "lastIndexOf" [@@mel.send] -external slice_copy : unit -> 'this = "slice" -[@@mel.send.pipe: 'a t as 'this] [@@deprecated "Please use `copy`"] +external lastIndexOfFrom : 'a t -> value:'a -> start:int -> int = "lastIndexOf" +[@@mel.send] -external sliceFrom : int -> 'this = "slice" [@@mel.send.pipe: 'a t as 'this] +external copy : 'a t -> 'a t = "slice" [@@mel.send] -external slice_start : int -> 'this = "slice" -[@@mel.send.pipe: 'a t as 'this] [@@deprecated "Please use `sliceFrom`"] +external slice : 'a t -> ?start:int -> ?end_:int -> unit -> 'a t = "slice" +[@@mel.send] -external toString : string = "toString" [@@mel.send.pipe: 'a t as 'this] - -external toLocaleString : string = "toLocaleString" -[@@mel.send.pipe: 'a t as 'this] +external toString : 'a t -> string = "toString" [@@mel.send] +external toLocaleString : 'a t -> string = "toLocaleString" [@@mel.send] (* Iteration functions *) -(* commented out until bs has a plan for iterators - external entries : (int * 'a) array_iter = "" [@@mel.send.pipe: 'a t as 'this] (* ES2015 *) +(* commented out until Melange has a plan for iterators + external entries : 'a t -> (int * 'a) array_iter = "" [@@mel.send] (* ES2015 *) *) -external every : (('a -> bool)[@mel.uncurry]) -> bool = "every" -[@@mel.send.pipe: 'a t as 'this] +external every : 'a t -> f:(('a -> bool)[@mel.uncurry]) -> bool = "every" +[@@mel.send] -external everyi : (('a -> int -> bool)[@mel.uncurry]) -> bool = "every" -[@@mel.send.pipe: 'a t as 'this] +external everyi : 'a t -> f:(('a -> int -> bool)[@mel.uncurry]) -> bool + = "every" +[@@mel.send] -external filter : (('a -> bool)[@mel.uncurry]) -> 'this = "filter" -[@@mel.send.pipe: 'a t as 'this] -(** should we use [bool] or [boolean] seems they are intechangeable here *) +external filter : 'a t -> f:(('a -> bool)[@mel.uncurry]) -> 'a t = "filter" +[@@mel.send] -external filteri : (('a -> int -> bool)[@mel.uncurry]) -> 'this = "filter" -[@@mel.send.pipe: 'a t as 'this] +external filteri : 'a t -> f:(('a -> int -> bool)[@mel.uncurry]) -> 'a t + = "filter" +[@@mel.send] -external find : (('a -> bool)[@mel.uncurry]) -> 'a option = "find" -[@@mel.send.pipe: 'a t as 'this] [@@mel.return { undefined_to_opt }] +external find : 'a t -> f:(('a -> bool)[@mel.uncurry]) -> 'a option = "find" +[@@mel.send] [@@mel.return { undefined_to_opt }] (* ES2015 *) -external findi : (('a -> int -> bool)[@mel.uncurry]) -> 'a option = "find" -[@@mel.send.pipe: 'a t as 'this] [@@mel.return { undefined_to_opt }] +external findi : 'a t -> f:(('a -> int -> bool)[@mel.uncurry]) -> 'a option + = "find" +[@@mel.send] [@@mel.return { undefined_to_opt }] (* ES2015 *) -external findIndex : (('a -> bool)[@mel.uncurry]) -> int = "findIndex" -[@@mel.send.pipe: 'a t as 'this] +external findIndex : 'a t -> f:(('a -> bool)[@mel.uncurry]) -> int = "findIndex" +[@@mel.send] (* ES2015 *) -external findIndexi : (('a -> int -> bool)[@mel.uncurry]) -> int = "findIndex" -[@@mel.send.pipe: 'a t as 'this] +external findIndexi : 'a t -> f:(('a -> int -> bool)[@mel.uncurry]) -> int + = "findIndex" +[@@mel.send] (* ES2015 *) -external forEach : (('a -> unit)[@mel.uncurry]) -> unit = "forEach" -[@@mel.send.pipe: 'a t as 'this] +external forEach : 'a t -> f:(('a -> unit)[@mel.uncurry]) -> unit = "forEach" +[@@mel.send] -external forEachi : (('a -> int -> unit)[@mel.uncurry]) -> unit = "forEach" -[@@mel.send.pipe: 'a t as 'this] +external forEachi : 'a t -> f:(('a -> int -> unit)[@mel.uncurry]) -> unit + = "forEach" +[@@mel.send] -(* commented out until bs has a plan for iterators - external keys : int array_iter = "" [@@mel.send.pipe: 'a t as 'this] (* ES2015 *) +(* commented out until Melange has a plan for iterators + external keys : 'a t -> int array_iter = "" [@@mel.send] (* ES2015 *) *) -external map : (('a -> 'b)[@mel.uncurry]) -> 'b t = "map" -[@@mel.send.pipe: 'a t as 'this] - -external mapi : (('a -> int -> 'b)[@mel.uncurry]) -> 'b t = "map" -[@@mel.send.pipe: 'a t as 'this] +external map : 'a t -> f:(('a -> 'b)[@mel.uncurry]) -> 'b t = "map" [@@mel.send] -external reduce : (('b -> 'a -> 'b)[@mel.uncurry]) -> 'b -> 'b = "reduce" -[@@mel.send.pipe: 'a t as 'this] +external mapi : 'a t -> f:(('a -> int -> 'b)[@mel.uncurry]) -> 'b t = "map" +[@@mel.send] -external reducei : (('b -> 'a -> int -> 'b)[@mel.uncurry]) -> 'b -> 'b +external reduce : 'a t -> f:(('b -> 'a -> 'b)[@mel.uncurry]) -> init:'b -> 'b = "reduce" -[@@mel.send.pipe: 'a t as 'this] +[@@mel.send] -external reduceRight : (('b -> 'a -> 'b)[@mel.uncurry]) -> 'b -> 'b - = "reduceRight" -[@@mel.send.pipe: 'a t as 'this] +external reducei : + 'a t -> f:(('b -> 'a -> int -> 'b)[@mel.uncurry]) -> init:'b -> 'b = "reduce" +[@@mel.send] -external reduceRighti : (('b -> 'a -> int -> 'b)[@mel.uncurry]) -> 'b -> 'b +external reduceRight : + 'a t -> f:(('b -> 'a -> 'b)[@mel.uncurry]) -> init:'b -> 'b = "reduceRight" +[@@mel.send] + +external reduceRighti : + 'a t -> f:(('b -> 'a -> int -> 'b)[@mel.uncurry]) -> init:'b -> 'b = "reduceRight" -[@@mel.send.pipe: 'a t as 'this] +[@@mel.send] -external some : (('a -> bool)[@mel.uncurry]) -> bool = "some" -[@@mel.send.pipe: 'a t as 'this] +external some : 'a t -> f:(('a -> bool)[@mel.uncurry]) -> bool = "some" +[@@mel.send] -external somei : (('a -> int -> bool)[@mel.uncurry]) -> bool = "some" -[@@mel.send.pipe: 'a t as 'this] +external somei : 'a t -> f:(('a -> int -> bool)[@mel.uncurry]) -> bool = "some" +[@@mel.send] + +(* commented out until Melange has a plan for iterators + external values : 'a t -> 'a array_iter = "" [@@mel.send] (* ES2015 *) *) -(* commented out until bs has a plan for iterators - external values : 'a array_iter = "" [@@mel.send.pipe: 'a t as 'this] (* ES2015 *) -*) external unsafe_get : 'a array -> int -> 'a = "%array_unsafe_get" external unsafe_set : 'a array -> int -> 'a -> unit = "%array_unsafe_set" diff --git a/jscomp/runtime/js_array2.ml b/jscomp/runtime/js_array2.ml deleted file mode 100644 index 76c45e51c5..0000000000 --- a/jscomp/runtime/js_array2.ml +++ /dev/null @@ -1,213 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -(** JavaScript Array API *) - -type 'a t = 'a array -type 'a array_like - -(* commented out until bs has a plan for iterators - type 'a array_iter = 'a array_like -*) - -external from : 'a array_like -> 'a array = "Array.from" -(* ES2015 *) - -external fromMap : 'a array_like -> (('a -> 'b)[@mel.uncurry]) -> 'b array - = "Array.from" - -(* ES2015 *) - -external isArray : 'a -> bool = "Array.isArray" - -(* ES2015 *) -(* ES2015 *) - -(* Array.of: seems pointless unless you can bind *) -external length : 'a array -> int = "length" [@@mel.get] - -(* Mutator functions -*) -external copyWithin : 'a t -> to_:int -> 'a t = "copyWithin" [@@mel.send] -(* ES2015 *) - -external copyWithinFrom : 'a t -> to_:int -> from:int -> 'a t = "copyWithin" -[@@mel.send] -(* ES2015 *) - -external copyWithinFromRange : 'a t -> to_:int -> start:int -> end_:int -> 'a t - = "copyWithin" -[@@mel.send] -(* ES2015 *) - -external fillInPlace : 'a t -> 'a -> 'a t = "fill" [@@mel.send] (* ES2015 *) -external fillFromInPlace : 'a t -> 'a -> from:int -> 'a t = "fill" [@@mel.send] -(* ES2015 *) - -external fillRangeInPlace : 'a t -> 'a -> start:int -> end_:int -> 'a t = "fill" -[@@mel.send] -(* ES2015 *) - -external pop : 'a t -> 'a option = "pop" -[@@mel.send] [@@mel.return undefined_to_opt] -(** https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push *) - -external push : 'a t -> 'a -> int = "push" [@@mel.send] -external pushMany : 'a t -> 'a array -> int = "push" [@@mel.send] [@@mel.splice] -external reverseInPlace : 'a t -> 'a t = "reverse" [@@mel.send] - -external shift : 'a t -> 'a option = "shift" -[@@mel.send] [@@mel.return undefined_to_opt] - -external sortInPlace : 'a t -> 'a t = "sort" [@@mel.send] - -external sortInPlaceWith : 'a t -> (('a -> 'a -> int)[@mel.uncurry]) -> 'a t - = "sort" -[@@mel.send] - -external spliceInPlace : 'a t -> pos:int -> remove:int -> add:'a array -> 'a t - = "splice" -[@@mel.send] [@@mel.splice] - -external removeFromInPlace : 'a t -> pos:int -> 'a t = "splice" [@@mel.send] - -external removeCountInPlace : 'a t -> pos:int -> count:int -> 'a t = "splice" -[@@mel.send] -(* screwy naming, but screwy function *) - -external unshift : 'a t -> 'a -> int = "unshift" [@@mel.send] - -external unshiftMany : 'a t -> 'a array -> int = "unshift" -[@@mel.send] [@@mel.splice] - -(* Accessor functions -*) -external append : 'a t -> 'a -> 'a t = "concat" -[@@mel.send] -[@@deprecated "append is not type-safe. Use `concat` instead, and see #1884"] - -external concat : 'a t -> 'a t -> 'a t = "concat" [@@mel.send] - -external concatMany : 'a t -> 'a t array -> 'a t = "concat" -[@@mel.send] [@@mel.splice] - -(* TODO: Not available in Node V4 *) -external includes : 'a t -> 'a -> bool = "includes" [@@mel.send] -(** ES2016 *) - -external indexOf : 'a t -> 'a -> int = "indexOf" [@@mel.send] -external indexOfFrom : 'a t -> 'a -> from:int -> int = "indexOf" [@@mel.send] -external joinWith : 'a t -> string -> string = "join" [@@mel.send] -external lastIndexOf : 'a t -> 'a -> int = "lastIndexOf" [@@mel.send] - -external lastIndexOfFrom : 'a t -> 'a -> from:int -> int = "lastIndexOf" -[@@mel.send] - -external slice : 'a t -> start:int -> end_:int -> 'a t = "slice" [@@mel.send] -external copy : 'a t -> 'a t = "slice" [@@mel.send] -external sliceFrom : 'a t -> int -> 'a t = "slice" [@@mel.send] -external toString : 'a t -> string = "toString" [@@mel.send] -external toLocaleString : 'a t -> string = "toLocaleString" [@@mel.send] - -(* Iteration functions -*) -(* commented out until bs has a plan for iterators - external entries : 'a t -> (int * 'a) array_iter = "" [@@mel.send] (* ES2015 *) -*) - -external every : 'a t -> (('a -> bool)[@mel.uncurry]) -> bool = "every" -[@@mel.send] - -external everyi : 'a t -> (('a -> int -> bool)[@mel.uncurry]) -> bool = "every" -[@@mel.send] - -external filter : 'a t -> (('a -> bool)[@mel.uncurry]) -> 'a t = "filter" -[@@mel.send] -(** should we use [bool] or [boolean] seems they are intechangeable here *) - -external filteri : 'a t -> (('a -> int -> bool)[@mel.uncurry]) -> 'a t - = "filter" -[@@mel.send] - -external find : 'a t -> (('a -> bool)[@mel.uncurry]) -> 'a option = "find" -[@@mel.send] [@@mel.return { undefined_to_opt }] -(* ES2015 *) - -external findi : 'a t -> (('a -> int -> bool)[@mel.uncurry]) -> 'a option - = "find" -[@@mel.send] [@@mel.return { undefined_to_opt }] -(* ES2015 *) - -external findIndex : 'a t -> (('a -> bool)[@mel.uncurry]) -> int = "findIndex" -[@@mel.send] -(* ES2015 *) - -external findIndexi : 'a t -> (('a -> int -> bool)[@mel.uncurry]) -> int - = "findIndex" -[@@mel.send] -(* ES2015 *) - -external forEach : 'a t -> (('a -> unit)[@mel.uncurry]) -> unit = "forEach" -[@@mel.send] - -external forEachi : 'a t -> (('a -> int -> unit)[@mel.uncurry]) -> unit - = "forEach" -[@@mel.send] - -(* commented out until bs has a plan for iterators - external keys : 'a t -> int array_iter = "" [@@mel.send] (* ES2015 *) -*) - -external map : 'a t -> (('a -> 'b)[@mel.uncurry]) -> 'b t = "map" [@@mel.send] - -external mapi : 'a t -> (('a -> int -> 'b)[@mel.uncurry]) -> 'b t = "map" -[@@mel.send] - -external reduce : 'a t -> (('b -> 'a -> 'b)[@mel.uncurry]) -> 'b -> 'b - = "reduce" -[@@mel.send] - -external reducei : 'a t -> (('b -> 'a -> int -> 'b)[@mel.uncurry]) -> 'b -> 'b - = "reduce" -[@@mel.send] - -external reduceRight : 'a t -> (('b -> 'a -> 'b)[@mel.uncurry]) -> 'b -> 'b - = "reduceRight" -[@@mel.send] - -external reduceRighti : - 'a t -> (('b -> 'a -> int -> 'b)[@mel.uncurry]) -> 'b -> 'b = "reduceRight" -[@@mel.send] - -external some : 'a t -> (('a -> bool)[@mel.uncurry]) -> bool = "some" -[@@mel.send] - -external somei : 'a t -> (('a -> int -> bool)[@mel.uncurry]) -> bool = "some" -[@@mel.send] - -(* commented out until bs has a plan for iterators - external values : 'a t -> 'a array_iter = "" [@@mel.send] (* ES2015 *) -*) -external unsafe_get : 'a array -> int -> 'a = "%array_unsafe_get" -external unsafe_set : 'a array -> int -> 'a -> unit = "%array_unsafe_set" diff --git a/jscomp/runtime/js_dict.ml b/jscomp/runtime/js_dict.ml index 613b50a8a4..d998e9f801 100644 --- a/jscomp/runtime/js_dict.ml +++ b/jscomp/runtime/js_dict.ml @@ -72,21 +72,21 @@ external unsafeCreate : int -> 'a array = "Array" [@@mel.new] (* external entries : 'a t -> (key * 'a) array = "Object.entries" (* ES2017 *) *) let entries dict = let keys = keys dict in - let l = Js_array2.length keys in + let l = Js_array.length keys in let values = unsafeCreate l in for i = 0 to l - 1 do - let key = Js_array2.unsafe_get keys i in - Js_array2.unsafe_set values i (key, dict.!(key)) + let key = Js_array.unsafe_get keys i in + Js_array.unsafe_set values i (key, dict.!(key)) done; values (* external values : 'a t -> 'a array = "Object.values" (* ES2017 *) *) let values dict = let keys = keys dict in - let l = Js_array2.length keys in + let l = Js_array.length keys in let values = unsafeCreate l in for i = 0 to l - 1 do - Js_array2.unsafe_set values i dict.!(Js_array2.unsafe_get keys i) + Js_array.unsafe_set values i dict.!(Js_array.unsafe_get keys i) done; values @@ -102,9 +102,9 @@ let fromList entries = let fromArray entries = let dict = empty () in - let l = Js_array2.length entries in + let l = Js_array.length entries in for i = 0 to l - 1 do - let key, value = Js_array2.unsafe_get entries i in + let key, value = Js_array.unsafe_get entries i in set dict key value done; dict @@ -112,9 +112,9 @@ let fromArray entries = let map f source = let target = empty () in let keys = keys source in - let l = Js_array2.length keys in + let l = Js_array.length keys in for i = 0 to l - 1 do - let key = Js_array2.unsafe_get keys i in + let key = Js_array.unsafe_get keys i in set target key (f (unsafeGet source key) [@u]) done; target diff --git a/jscomp/runtime/js_json.ml b/jscomp/runtime/js_json.ml index 5aa2b340b1..50c5632c15 100644 --- a/jscomp/runtime/js_json.ml +++ b/jscomp/runtime/js_json.ml @@ -50,7 +50,7 @@ let classify (x : t) : tagged_t = else if ty = "number" then JSONNumber (Obj.magic x) else if ty = "boolean" then if Obj.magic x = true then JSONTrue else JSONFalse else if Obj.magic x == Js_internal.null then JSONNull - else if Js_array2.isArray x then JSONArray (Obj.magic x) + else if Js_array.isArray x then JSONArray (Obj.magic x) else JSONObject (Obj.magic x) let test (type a) (x : 'a) (v : a kind) : bool = @@ -59,11 +59,11 @@ let test (type a) (x : 'a) (v : a kind) : bool = | Boolean -> Js_internal.typeof x = "boolean" | String -> Js_internal.typeof x = "string" | Null -> Obj.magic x == Js_internal.null - | Array -> Js_array2.isArray x + | Array -> Js_array.isArray x | Object -> Obj.magic x != Js_internal.null && Js_internal.typeof x = "object" - && not (Js_array2.isArray x) + && not (Js_array.isArray x) let decodeString json = if Js_internal.typeof json = "string" then @@ -77,13 +77,13 @@ let decodeNumber json = let decodeObject json = if Js_internal.typeof json = "object" - && (not (Js_array2.isArray json)) + && (not (Js_array.isArray json)) && not ((Obj.magic json : 'a Js_internal.null) == Js_internal.null) then Some (Obj.magic (json : t) : t Js_dict.t) else None let decodeArray json = - if Js_array2.isArray json then Some (Obj.magic (json : t) : t array) else None + if Js_array.isArray json then Some (Obj.magic (json : t) : t array) else None let decodeBoolean (json : t) = if Js_internal.typeof json = "boolean" then Some (Obj.magic (json : t) : bool) diff --git a/jscomp/runtime/js_string.ml b/jscomp/runtime/js_string.ml index 4809831c7b..ee928fc88d 100644 --- a/jscomp/runtime/js_string.ml +++ b/jscomp/runtime/js_string.ml @@ -716,7 +716,7 @@ external link : t -> t = "link" [@@mel.send.pipe: t] (** ES2015 *) -external castToArrayLike : t -> t Js_array2.array_like = "%identity" +external castToArrayLike : t -> t Js_array.array_like = "%identity" (* FIXME: we should not encourage people to use [%identity], better to provide something using so that we can track such casting diff --git a/jscomp/runtime/js_string2.ml b/jscomp/runtime/js_string2.ml index e3b843b5ea..b2f96818c9 100644 --- a/jscomp/runtime/js_string2.ml +++ b/jscomp/runtime/js_string2.ml @@ -702,7 +702,7 @@ external link : t -> t -> t = "link" [@@mel.send] (** ES2015 *) -external castToArrayLike : t -> t Js_array2.array_like = "%identity" +external castToArrayLike : t -> t Js_array.array_like = "%identity" (* FIXME: we should not encourage people to use [%identity], better to provide something using so that we can track such casting diff --git a/jscomp/test/array_subtle_test.ml b/jscomp/test/array_subtle_test.ml index 5dd1681799..624661e10f 100644 --- a/jscomp/test/array_subtle_test.ml +++ b/jscomp/test/array_subtle_test.ml @@ -12,9 +12,9 @@ let () = eq __LOC__ (4,Array.length v) let () = - eq __LOC__ (5,Js.Array2.push v 3 ); (* in Js array length can be changing .. *) + eq __LOC__ (5,Js.Array.push v ~value:3 ); (* in Js array length can be changing .. *) eq __LOC__ (5, Array.length v ); - eq __LOC__ (5,Js.Array2.length v ) + eq __LOC__ (5,Js.Array.length v ) let () = @@ -23,17 +23,17 @@ let () = eq __LOC__ (4,v.(2)) (* should not inline *) let () = - while Js.Array2.length v > 0 do - ignore @@ Js.Array2.pop v + while Js.Array.length v > 0 do + ignore @@ Js.Array.pop v done; - eq __LOC__ (0, Js.Array2.length v ) + eq __LOC__ (0, Js.Array.length v ) let f v = - (match Js.Array2.pop v with + (match Js.Array.pop v with | Some x -> Js.log "hi" | None -> Js.log "hi2"); - Js.log (ignore @@ Js.Array2.pop v) + Js.log (ignore @@ Js.Array.pop v) let fff x = diff --git a/jscomp/test/bs_array_test.ml b/jscomp/test/bs_array_test.ml index ba865df4b0..b8b10bdf02 100644 --- a/jscomp/test/bs_array_test.ml +++ b/jscomp/test/bs_array_test.ml @@ -15,12 +15,12 @@ module L = Belt.List let {push } = (module A) -type 'a t = 'a Js.Array2.t +type 'a t = 'a Js.Array.t let () = [| 1; 2; 3; 4 |] - |. Js.Array2.filter (fun x -> x > 2) - |. Js.Array2.mapi (fun x i -> x + i) - |. Js.Array2.reduce (fun x y -> x + y) 0 + |. Js.Array.filter ~f:(fun x -> x > 2) + |. Js.Array.mapi ~f:(fun x i -> x + i) + |. Js.Array.reduce ~f:(fun x y -> x + y) ~init:0 |. Js.log diff --git a/jscomp/test/bs_auto_uncurry_test.ml b/jscomp/test/bs_auto_uncurry_test.ml index 5080d800fa..7944d3e6b2 100644 --- a/jscomp/test/bs_auto_uncurry_test.ml +++ b/jscomp/test/bs_auto_uncurry_test.ml @@ -34,23 +34,23 @@ let () = ([|1;2;3|] |> map (fun x -> x + 1)) ([|2;3;4|]); eq __LOC__ - ([|1;2;3|] |. Js.Array2.map (fun x -> x + 1)) + ([|1;2;3|] |. Js.Array.map ~f:(fun x -> x + 1)) ([|2;3;4|]); eq __LOC__ - ([|1;2;3|] |. Js.Array2.reduce (+) 0) + ([|1;2;3|] |. Js.Array.reduce ~f:(+) ~init:0) 6 ; eq __LOC__ - ([|1;2;3|] |. Js.Array2.reducei (fun x y i -> x + y + i) 0) + ([|1;2;3|] |. Js.Array.reducei ~f:(fun x y i -> x + y + i) ~init:0) 9; eq __LOC__ - ([| 1;2;3|] |. Js.Array2.some (fun x -> x <1)) + ([| 1;2;3|] |. Js.Array.some ~f:(fun x -> x <1)) false ; eq __LOC__ - ([|1;2;3|] |. Js.Array2.every (fun x -> x > 0)) + ([|1;2;3|] |. Js.Array.every ~f:(fun x -> x > 0)) true end diff --git a/jscomp/test/bs_string_test.ml b/jscomp/test/bs_string_test.ml index a31910d936..8837a86e39 100644 --- a/jscomp/test/bs_string_test.ml +++ b/jscomp/test/bs_string_test.ml @@ -11,9 +11,9 @@ let () = eq __LOC__ ("ghso ghso g" |. Js.String2.split " " - |. Js.Array2.reduce (fun x y -> x ^ "-" ^ y) "" + |. Js.Array.reduce ~f:(fun x y -> x ^ "-" ^ y) ~init:"" ) "-ghso-ghso-g" -let () = Mt.from_pair_suites __MODULE__ !suites \ No newline at end of file +let () = Mt.from_pair_suites __MODULE__ !suites diff --git a/jscomp/test/chn_test.ml b/jscomp/test/chn_test.ml index 90728b25e9..d2e83a78d2 100644 --- a/jscomp/test/chn_test.ml +++ b/jscomp/test/chn_test.ml @@ -13,12 +13,12 @@ Js.log {js|你好, Js.log {js|\x3f\u003f\b\t\n\v\f\r\0"'|js} ;; let convert (s : string) : int list = - Js.Array2.fromMap + Js.Array.fromMap (Js.String.castToArrayLike s) - (fun x -> - match Js.String.codePointAt 0 x with - | None -> assert false - | Some x -> x ) |> Array.to_list + ~f:(fun x -> + match Js.String.codePointAt 0 x with + | None -> assert false + | Some x -> x ) |> Array.to_list let () = begin diff --git a/jscomp/test/dist/jscomp/test/chn_test.js b/jscomp/test/dist/jscomp/test/chn_test.js index 9fea2c8621..d6e689a3c8 100644 --- a/jscomp/test/dist/jscomp/test/chn_test.js +++ b/jscomp/test/dist/jscomp/test/chn_test.js @@ -45,7 +45,7 @@ function convert(s) { _1: [ "jscomp/test/chn_test.ml", 20, - 18 + 22 ], Error: new Error() }; diff --git a/jscomp/test/dist/jscomp/test/ffi_js_test.js b/jscomp/test/dist/jscomp/test/ffi_js_test.js index cabf3bd9fe..5f1c121405 100644 --- a/jscomp/test/dist/jscomp/test/ffi_js_test.js +++ b/jscomp/test/dist/jscomp/test/ffi_js_test.js @@ -98,12 +98,12 @@ eq("File \"jscomp/test/ffi_js_test.ml\", line 45, characters 5-12", [ ]); eq("File \"jscomp/test/ffi_js_test.ml\", line 46, characters 5-12", [ - Object.keys(v_obj).indexOf("hi_x"), + Object.keys(v_obj).indexOf("hi_x", undefined), -1 ]); eq("File \"jscomp/test/ffi_js_test.ml\", line 47, characters 5-12", [ - Object.keys(v_obj).indexOf("hi"), + Object.keys(v_obj).indexOf("hi", undefined), 0 ]); diff --git a/jscomp/test/dist/jscomp/test/flow_parser_reg_test.js b/jscomp/test/dist/jscomp/test/flow_parser_reg_test.js index da7e03dbcf..2caf2e3596 100644 --- a/jscomp/test/dist/jscomp/test/flow_parser_reg_test.js +++ b/jscomp/test/dist/jscomp/test/flow_parser_reg_test.js @@ -15547,16 +15547,96 @@ function parse(content, options) { string(param[1].name) ]]); }; - var variable_declarator = function (param) { - var declarator = param[1]; - return node("VariableDeclarator", param[0], [ + var identifier = function (param) { + var id = param[1]; + return node("Identifier", param[0], [ + [ + "name", + string(id.name) + ], + [ + "typeAnnotation", + option(type_annotation, id.typeAnnotation) + ], + [ + "optional", + bool(id.optional) + ] + ]); + }; + var type_parameter_declaration = function (param) { + return node("TypeParameterDeclaration", param[0], [[ + "params", + array_of_list(type_param, param[1].params) + ]]); + }; + var object_type = function (param) { + var o = param[1]; + return node("ObjectTypeAnnotation", param[0], [ + [ + "properties", + array_of_list(object_type_property, o.properties) + ], + [ + "indexers", + array_of_list(object_type_indexer, o.indexers) + ], + [ + "callProperties", + array_of_list(object_type_call_property, o.callProperties) + ] + ]); + }; + var interface_extends = function (param) { + var g = param[1]; + var id = g.id; + var id$1; + id$1 = id.TAG === /* Unqualified */0 ? identifier(id._0) : generic_type_qualified_identifier(id._0); + return node("InterfaceExtends", param[0], [ [ "id", - pattern(declarator.id) + id$1 ], [ - "init", - option(expression, declarator.init) + "typeParameters", + option(type_parameter_instantiation, g.typeParameters) + ] + ]); + }; + var jsx_member_expression = function (param) { + var member_expression = param[1]; + var id = member_expression._object; + var _object; + _object = id.TAG === /* Identifier */0 ? jsx_identifier(id._0) : jsx_member_expression(id._0); + return node("JSXMemberExpression", param[0], [ + [ + "object", + _object + ], + [ + "property", + jsx_identifier(member_expression.property) + ] + ]); + }; + var function_type = function (param) { + var fn = param[1]; + return node("FunctionTypeAnnotation", param[0], [ + [ + "params", + array_of_list(function_type_param, fn.params) + ], + [ + "returnType", + _type(fn.returnType) + ], + [ + "rest", + option(function_type_param, fn.rest) + ], + [ + "typeParameters", + option(type_parameter_declaration, fn.typeParameters) ] ]); }; @@ -15712,85 +15792,24 @@ function parse(content, options) { } } }; - var identifier = function (param) { - var id = param[1]; - return node("Identifier", param[0], [ - [ - "name", - string(id.name) - ], - [ + var type_annotation = function (param) { + return node("TypeAnnotation", param[0], [[ "typeAnnotation", - option(type_annotation, id.typeAnnotation) - ], - [ - "optional", - bool(id.optional) - ] - ]); - }; - var jsx_child = function (param) { - var element = param[1]; - var loc = param[0]; - switch (element.TAG | 0) { - case /* Element */0 : - return jsx_element([ - loc, - element._0 - ]); - case /* ExpressionContainer */1 : - return jsx_expression_container([ - loc, - element._0 - ]); - case /* Text */2 : - var param$1 = [ - loc, - element._0 - ]; - var text = param$1[1]; - return node("JSXText", param$1[0], [ - [ - "value", - string(text.value) - ], - [ - "raw", - string(text.raw) - ] - ]); - - } - }; - var jsx_closing = function (param) { - return node("JSXClosingElement", param[0], [[ - "name", - jsx_name(param[1].name) + _type(param[1]) ]]); }; - var jsx_opening = function (param) { - var opening = param[1]; - return node("JSXOpeningElement", param[0], [ - [ - "name", - jsx_name(opening.name) - ], - [ - "attributes", - array_of_list(jsx_opening_attribute, opening.attributes) - ], - [ - "selfClosing", - bool(opening.selfClosing) - ] - ]); - }; var class_body = function (param) { return node("ClassBody", param[0], [[ "body", array_of_list(class_element, param[1].body) ]]); }; + var type_parameter_instantiation = function (param) { + return node("TypeParameterInstantiation", param[0], [[ + "params", + array_of_list(_type, param[1].params) + ]]); + }; var expression = function (param) { var arr = param[1]; var loc = param[0]; @@ -16298,12 +16317,6 @@ function parse(content, options) { } }; - var type_parameter_declaration = function (param) { - return node("TypeParameterDeclaration", param[0], [[ - "params", - array_of_list(type_param, param[1].params) - ]]); - }; var class_implements = function (param) { var $$implements = param[1]; return node("ClassImplements", param[0], [ @@ -16317,64 +16330,136 @@ function parse(content, options) { ] ]); }; - var type_parameter_instantiation = function (param) { - return node("TypeParameterInstantiation", param[0], [[ - "params", - array_of_list(_type, param[1].params) - ]]); + var template_element = function (param) { + var element = param[1]; + var value = obj([ + [ + "raw", + string(element.value.raw) + ], + [ + "cooked", + string(element.value.cooked) + ] + ]); + return node("TemplateElement", param[0], [ + [ + "value", + value + ], + [ + "tail", + bool(element.tail) + ] + ]); }; - var literal = function (param) { - var lit = param[1]; - var raw = lit.raw; - var value = lit.value; - var loc = param[0]; - var value_; - if (typeof value === "number") { - value_ = $$null; - } else { - switch (value.TAG | 0) { - case /* String */0 : - value_ = string(value._0); - break; - case /* Boolean */1 : - value_ = bool(value._0); - break; - case /* Number */2 : - value_ = number$1(value._0); - break; - case /* RegExp */3 : - var match = value._0; - value_ = regexp$1(loc, match.pattern, match.flags); - break; - - } - } - var props; - var exit = 0; - if (typeof value === "number" || value.TAG !== /* RegExp */3) { - exit = 1; - } else { - var match$1 = value._0; - var regex = obj([ - [ - "pattern", - string(match$1.pattern) - ], - [ - "flags", - string(match$1.flags) - ] - ]); - props = [ - [ - "value", - value_ - ], - [ - "raw", - string(raw) - ], - [ + var generic_type_qualified_identifier = function (param) { + var q = param[1]; + var id = q.qualification; + var qualification; + qualification = id.TAG === /* Unqualified */0 ? identifier(id._0) : generic_type_qualified_identifier(id._0); + return node("QualifiedTypeIdentifier", param[0], [ + [ + "qualification", + qualification + ], + [ + "id", + identifier(q.id) + ] + ]); + }; + var export_specifier = function (param) { + var specifier = param[1]; + return node("ExportSpecifier", param[0], [ + [ + "id", + identifier(specifier.id) + ], + [ + "name", + option(identifier, specifier.name) + ] + ]); + }; + var jsx_namespaced_name = function (param) { + var namespaced_name = param[1]; + return node("JSXNamespacedName", param[0], [ + [ + "namespace", + jsx_identifier(namespaced_name.namespace) + ], + [ + "name", + jsx_identifier(namespaced_name.name) + ] + ]); + }; + var jsx_attribute_value = function (param) { + if (param.TAG === /* Literal */0) { + return literal([ + param._0, + param._1 + ]); + } else { + return jsx_expression_container([ + param._0, + param._1 + ]); + } + }; + var literal = function (param) { + var lit = param[1]; + var raw = lit.raw; + var value = lit.value; + var loc = param[0]; + var value_; + if (typeof value === "number") { + value_ = $$null; + } else { + switch (value.TAG | 0) { + case /* String */0 : + value_ = string(value._0); + break; + case /* Boolean */1 : + value_ = bool(value._0); + break; + case /* Number */2 : + value_ = number$1(value._0); + break; + case /* RegExp */3 : + var match = value._0; + value_ = regexp$1(loc, match.pattern, match.flags); + break; + + } + } + var props; + var exit = 0; + if (typeof value === "number" || value.TAG !== /* RegExp */3) { + exit = 1; + } else { + var match$1 = value._0; + var regex = obj([ + [ + "pattern", + string(match$1.pattern) + ], + [ + "flags", + string(match$1.flags) + ] + ]); + props = [ + [ + "value", + value_ + ], + [ + "raw", + string(raw) + ], + [ "regex", regex ] @@ -16394,91 +16479,6 @@ function parse(content, options) { } return node("Literal", loc, props); }; - var type_annotation = function (param) { - return node("TypeAnnotation", param[0], [[ - "typeAnnotation", - _type(param[1]) - ]]); - }; - var jsx_namespaced_name = function (param) { - var namespaced_name = param[1]; - return node("JSXNamespacedName", param[0], [ - [ - "namespace", - jsx_identifier(namespaced_name.namespace) - ], - [ - "name", - jsx_identifier(namespaced_name.name) - ] - ]); - }; - var jsx_member_expression = function (param) { - var member_expression = param[1]; - var id = member_expression._object; - var _object; - _object = id.TAG === /* Identifier */0 ? jsx_identifier(id._0) : jsx_member_expression(id._0); - return node("JSXMemberExpression", param[0], [ - [ - "object", - _object - ], - [ - "property", - jsx_identifier(member_expression.property) - ] - ]); - }; - var function_expression = function (param) { - var _function = param[1]; - var b = _function.body; - var body; - body = b.TAG === /* BodyBlock */0 ? block(b._0) : expression(b._0); - return node("FunctionExpression", param[0], [ - [ - "id", - option(identifier, _function.id) - ], - [ - "params", - array_of_list(pattern, _function.params) - ], - [ - "defaults", - array_of_list((function (param) { - return option(expression, param); - }), _function.defaults) - ], - [ - "rest", - option(identifier, _function.rest) - ], - [ - "body", - body - ], - [ - "async", - bool(_function.async) - ], - [ - "generator", - bool(_function.generator) - ], - [ - "expression", - bool(_function.expression) - ], - [ - "returnType", - option(type_annotation, _function.returnType) - ], - [ - "typeParameters", - option(type_parameter_declaration, _function.typeParameters) - ] - ]); - }; var pattern = function (param) { var obj = param[1]; var loc = param[0]; @@ -16528,568 +16528,315 @@ function parse(content, options) { } }; - var interface_extends = function (param) { - var g = param[1]; - var id = g.id; - var id$1; - id$1 = id.TAG === /* Unqualified */0 ? identifier(id._0) : generic_type_qualified_identifier(id._0); - return node("InterfaceExtends", param[0], [ + var variable_declarator = function (param) { + var declarator = param[1]; + return node("VariableDeclarator", param[0], [ [ "id", - id$1 - ], - [ - "typeParameters", - option(type_parameter_instantiation, g.typeParameters) - ] - ]); - }; - var object_type = function (param) { - var o = param[1]; - return node("ObjectTypeAnnotation", param[0], [ - [ - "properties", - array_of_list(object_type_property, o.properties) - ], - [ - "indexers", - array_of_list(object_type_indexer, o.indexers) + pattern(declarator.id) ], [ - "callProperties", - array_of_list(object_type_call_property, o.callProperties) + "init", + option(expression, declarator.init) ] ]); }; - var jsx_expression_container = function (param) { - var expr = param[1].expression; - var expression$1; - expression$1 = expr.TAG === /* Expression */0 ? expression(expr._0) : node("JSXEmptyExpression", expr._0, []); - return node("JSXExpressionContainer", param[0], [[ - "expression", - expression$1 + var block = function (param) { + return node("BlockStatement", param[0], [[ + "body", + array_of_list(statement, param[1].body) ]]); }; - var statement = function (param) { - var b = param[1]; - var loc = param[0]; - if (typeof b === "number") { - if (b === /* Empty */0) { - return node("EmptyStatement", loc, []); - } else { - return node("DebuggerStatement", loc, []); - } - } - switch (b.TAG | 0) { - case /* Block */0 : - return block([ - loc, - b._0 - ]); - case /* Expression */1 : - return node("ExpressionStatement", loc, [[ - "expression", - expression(b._0.expression) - ]]); - case /* If */2 : - var _if = b._0; - return node("IfStatement", loc, [ - [ - "test", - expression(_if.test) - ], - [ - "consequent", - statement(_if.consequent) - ], - [ - "alternate", - option(statement, _if.alternate) - ] + var object_property = function (param) { + if (param.TAG === /* Property */0) { + var match = param._0; + var prop = match[1]; + var lit = prop.key; + var match$1; + switch (lit.TAG | 0) { + case /* Literal */0 : + match$1 = [ + literal(lit._0), + false + ]; + break; + case /* Identifier */1 : + match$1 = [ + identifier(lit._0), + false + ]; + break; + case /* Computed */2 : + match$1 = [ + expression(lit._0), + true + ]; + break; + + } + var match$2 = prop.kind; + var kind; + switch (match$2) { + case /* Init */0 : + kind = "init"; + break; + case /* Get */1 : + kind = "get"; + break; + case /* Set */2 : + kind = "set"; + break; + + } + return node("Property", match[0], [ + [ + "key", + match$1[0] + ], + [ + "value", + expression(prop.value) + ], + [ + "kind", + string(kind) + ], + [ + "method", + bool(prop._method) + ], + [ + "shorthand", + bool(prop.shorthand) + ], + [ + "computed", + bool(match$1[1]) + ] + ]); + } + var match$3 = param._0; + return node("SpreadProperty", match$3[0], [[ + "argument", + expression(match$3[1].argument) + ]]); + }; + var jsx_element = function (param) { + var element = param[1]; + return node("JSXElement", param[0], [ + [ + "openingElement", + jsx_opening(element.openingElement) + ], + [ + "closingElement", + option(jsx_closing, element.closingElement) + ], + [ + "children", + array_of_list(jsx_child, element.children) + ] + ]); + }; + var function_expression = function (param) { + var _function = param[1]; + var b = _function.body; + var body; + body = b.TAG === /* BodyBlock */0 ? block(b._0) : expression(b._0); + return node("FunctionExpression", param[0], [ + [ + "id", + option(identifier, _function.id) + ], + [ + "params", + array_of_list(pattern, _function.params) + ], + [ + "defaults", + array_of_list((function (param) { + return option(expression, param); + }), _function.defaults) + ], + [ + "rest", + option(identifier, _function.rest) + ], + [ + "body", + body + ], + [ + "async", + bool(_function.async) + ], + [ + "generator", + bool(_function.generator) + ], + [ + "expression", + bool(_function.expression) + ], + [ + "returnType", + option(type_annotation, _function.returnType) + ], + [ + "typeParameters", + option(type_parameter_declaration, _function.typeParameters) + ] + ]); + }; + var comprehension_block = function (param) { + var b = param[1]; + return node("ComprehensionBlock", param[0], [ + [ + "left", + pattern(b.left) + ], + [ + "right", + expression(b.right) + ], + [ + "each", + bool(b.each) + ] + ]); + }; + var template_literal = function (param) { + var value = param[1]; + return node("TemplateLiteral", param[0], [ + [ + "quasis", + array_of_list(template_element, value.quasis) + ], + [ + "expressions", + array_of_list(expression, value.expressions) + ] + ]); + }; + var let_assignment = function (assignment) { + return obj([ + [ + "id", + pattern(assignment.id) + ], + [ + "init", + option(expression, assignment.init) + ] + ]); + }; + var expression_or_spread = function (param) { + if (param.TAG === /* Expression */0) { + return expression(param._0); + } + var match = param._0; + return node("SpreadElement", match[0], [[ + "argument", + expression(match[1].argument) + ]]); + }; + var jsx_opening = function (param) { + var opening = param[1]; + return node("JSXOpeningElement", param[0], [ + [ + "name", + jsx_name(opening.name) + ], + [ + "attributes", + array_of_list(jsx_opening_attribute, opening.attributes) + ], + [ + "selfClosing", + bool(opening.selfClosing) + ] + ]); + }; + var jsx_child = function (param) { + var element = param[1]; + var loc = param[0]; + switch (element.TAG | 0) { + case /* Element */0 : + return jsx_element([ + loc, + element._0 ]); - case /* Labeled */3 : - var labeled = b._0; - return node("LabeledStatement", loc, [ + case /* ExpressionContainer */1 : + return jsx_expression_container([ + loc, + element._0 + ]); + case /* Text */2 : + var param$1 = [ + loc, + element._0 + ]; + var text = param$1[1]; + return node("JSXText", param$1[0], [ [ - "label", - identifier(labeled.label) + "value", + string(text.value) ], [ - "body", - statement(labeled.body) - ] - ]); - case /* Break */4 : - return node("BreakStatement", loc, [[ - "label", - option(identifier, b._0.label) - ]]); - case /* Continue */5 : - return node("ContinueStatement", loc, [[ - "label", - option(identifier, b._0.label) - ]]); - case /* With */6 : - var _with = b._0; - return node("WithStatement", loc, [ - [ - "object", - expression(_with._object) - ], - [ - "body", - statement(_with.body) - ] - ]); - case /* TypeAlias */7 : - return type_alias([ - loc, - b._0 - ]); - case /* Switch */8 : - var $$switch = b._0; - return node("SwitchStatement", loc, [ - [ - "discriminant", - expression($$switch.discriminant) - ], - [ - "cases", - array_of_list($$case, $$switch.cases) - ], - [ - "lexical", - bool($$switch.lexical) - ] - ]); - case /* Return */9 : - return node("ReturnStatement", loc, [[ - "argument", - option(expression, b._0.argument) - ]]); - case /* Throw */10 : - return node("ThrowStatement", loc, [[ - "argument", - expression(b._0.argument) - ]]); - case /* Try */11 : - var _try = b._0; - return node("TryStatement", loc, [ - [ - "block", - block(_try.block) - ], - [ - "handler", - option($$catch, _try.handler) - ], - [ - "guardedHandlers", - array_of_list($$catch, _try.guardedHandlers) - ], - [ - "finalizer", - option(block, _try.finalizer) - ] - ]); - case /* While */12 : - var _while = b._0; - return node("WhileStatement", loc, [ - [ - "test", - expression(_while.test) - ], - [ - "body", - statement(_while.body) - ] - ]); - case /* DoWhile */13 : - var dowhile = b._0; - return node("DoWhileStatement", loc, [ - [ - "body", - statement(dowhile.body) - ], - [ - "test", - expression(dowhile.test) - ] - ]); - case /* For */14 : - var _for = b._0; - var init = function (param) { - if (param.TAG === /* InitDeclaration */0) { - return variable_declaration(param._0); - } else { - return expression(param._0); - } - }; - return node("ForStatement", loc, [ - [ - "init", - option(init, _for.init) - ], - [ - "test", - option(expression, _for.test) - ], - [ - "update", - option(expression, _for.update) - ], - [ - "body", - statement(_for.body) - ] - ]); - case /* ForIn */15 : - var forin = b._0; - var left = forin.left; - var left$1; - left$1 = left.TAG === /* LeftDeclaration */0 ? variable_declaration(left._0) : expression(left._0); - return node("ForInStatement", loc, [ - [ - "left", - left$1 - ], - [ - "right", - expression(forin.right) - ], - [ - "body", - statement(forin.body) - ], - [ - "each", - bool(forin.each) - ] - ]); - case /* ForOf */16 : - var forof = b._0; - var left$2 = forof.left; - var left$3; - left$3 = left$2.TAG === /* LeftDeclaration */0 ? variable_declaration(left$2._0) : expression(left$2._0); - return node("ForOfStatement", loc, [ - [ - "left", - left$3 - ], - [ - "right", - expression(forof.right) - ], - [ - "body", - statement(forof.body) - ] - ]); - case /* Let */17 : - var _let = b._0; - return node("LetStatement", loc, [ - [ - "head", - array_of_list(let_assignment, _let.head) - ], - [ - "body", - statement(_let.body) - ] - ]); - case /* FunctionDeclaration */18 : - var fn = b._0; - var id = fn.id; - var match = id !== undefined ? [ - "FunctionDeclaration", - identifier(id) - ] : [ - "FunctionExpression", - $$null - ]; - var b$1 = fn.body; - var body; - body = b$1.TAG === /* BodyBlock */0 ? block(b$1._0) : expression(b$1._0); - return node(match[0], loc, [ - [ - "id", - match[1] - ], - [ - "params", - array_of_list(pattern, fn.params) - ], - [ - "defaults", - array_of_list((function (param) { - return option(expression, param); - }), fn.defaults) - ], - [ - "rest", - option(identifier, fn.rest) - ], - [ - "body", - body - ], - [ - "async", - bool(fn.async) - ], - [ - "generator", - bool(fn.generator) - ], - [ - "expression", - bool(fn.expression) - ], - [ - "returnType", - option(type_annotation, fn.returnType) - ], - [ - "typeParameters", - option(type_parameter_declaration, fn.typeParameters) - ] - ]); - case /* VariableDeclaration */19 : - return variable_declaration([ - loc, - b._0 - ]); - case /* ClassDeclaration */20 : - var param$1 = [ - loc, - b._0 - ]; - var c = param$1[1]; - var id$1 = c.id; - var match$1 = id$1 !== undefined ? [ - "ClassDeclaration", - identifier(id$1) - ] : [ - "ClassExpression", - $$null - ]; - return node(match$1[0], param$1[0], [ - [ - "id", - match$1[1] - ], - [ - "body", - class_body(c.body) - ], - [ - "superClass", - option(expression, c.superClass) - ], - [ - "typeParameters", - option(type_parameter_declaration, c.typeParameters) - ], - [ - "superTypeParameters", - option(type_parameter_instantiation, c.superTypeParameters) - ], - [ - "implements", - array_of_list(class_implements, c.implements) - ], - [ - "decorators", - array_of_list(expression, c.classDecorators) - ] - ]); - case /* InterfaceDeclaration */21 : - return interface_declaration([ - loc, - b._0 - ]); - case /* DeclareVariable */22 : - return declare_variable([ - loc, - b._0 - ]); - case /* DeclareFunction */23 : - return declare_function([ - loc, - b._0 - ]); - case /* DeclareClass */24 : - return declare_class([ - loc, - b._0 - ]); - case /* DeclareModule */25 : - var m = b._0; - var lit = m.id; - var id$2; - id$2 = lit.TAG === /* Identifier */0 ? identifier(lit._0) : literal(lit._0); - var match$2 = m.kind; - var tmp; - tmp = match$2.TAG === /* CommonJS */0 ? string("CommonJS") : string("ES"); - return node("DeclareModule", loc, [ - [ - "id", - id$2 - ], - [ - "body", - block(m.body) - ], - [ - "kind", - tmp - ] - ]); - case /* DeclareModuleExports */26 : - return node("DeclareModuleExports", loc, [[ - "typeAnnotation", - type_annotation(b._0) - ]]); - case /* DeclareExportDeclaration */27 : - var $$export = b._0; - var match$3 = $$export.declaration; - var declaration; - if (match$3 !== undefined) { - switch (match$3.TAG | 0) { - case /* Variable */0 : - declaration = declare_variable(match$3._0); - break; - case /* Function */1 : - declaration = declare_function(match$3._0); - break; - case /* Class */2 : - declaration = declare_class(match$3._0); - break; - case /* DefaultType */3 : - declaration = _type(match$3._0); - break; - case /* NamedType */4 : - declaration = type_alias(match$3._0); - break; - case /* Interface */5 : - declaration = interface_declaration(match$3._0); - break; - - } - } else { - declaration = $$null; - } - return node("DeclareExportDeclaration", loc, [ - [ - "default", - bool($$export.default) - ], - [ - "declaration", - declaration - ], - [ - "specifiers", - export_specifiers($$export.specifiers) - ], - [ - "source", - option(literal, $$export.source) - ] - ]); - case /* ExportDeclaration */28 : - var $$export$1 = b._0; - var match$4 = $$export$1.declaration; - var declaration$1 = match$4 !== undefined ? ( - match$4.TAG === /* Declaration */0 ? statement(match$4._0) : expression(match$4._0) - ) : $$null; - return node("ExportDeclaration", loc, [ - [ - "default", - bool($$export$1.default) - ], - [ - "declaration", - declaration$1 - ], - [ - "specifiers", - export_specifiers($$export$1.specifiers) - ], - [ - "source", - option(literal, $$export$1.source) - ], - [ - "exportKind", - string($$export$1.exportKind ? "value" : "type") - ] - ]); - case /* ImportDeclaration */29 : - var $$import = b._0; - var specifiers = Stdlib__List.map((function (param) { - switch (param.TAG | 0) { - case /* ImportNamedSpecifier */0 : - var match = param._0; - var local_id = match.local; - var remote_id = match.remote; - var span_loc = local_id !== undefined ? btwn(remote_id[0], local_id[0]) : remote_id[0]; - return node("ImportSpecifier", span_loc, [ - [ - "id", - identifier(remote_id) - ], - [ - "name", - option(identifier, local_id) - ] - ]); - case /* ImportDefaultSpecifier */1 : - var id = param._0; - return node("ImportDefaultSpecifier", id[0], [[ - "id", - identifier(id) - ]]); - case /* ImportNamespaceSpecifier */2 : - var param$1 = param._0; - return node("ImportNamespaceSpecifier", param$1[0], [[ - "id", - identifier(param$1[1]) - ]]); - - } - }), $$import.specifiers); - var match$5 = $$import.importKind; - var import_kind; - switch (match$5) { - case /* ImportType */0 : - import_kind = "type"; - break; - case /* ImportTypeof */1 : - import_kind = "typeof"; - break; - case /* ImportValue */2 : - import_kind = "value"; - break; - - } - return node("ImportDeclaration", loc, [ - [ - "specifiers", - array(Stdlib__Array.of_list(specifiers)) - ], - [ - "source", - literal($$import.source) - ], - [ - "importKind", - string(import_kind) + "raw", + string(text.raw) ] ]); } }; + var jsx_closing = function (param) { + return node("JSXClosingElement", param[0], [[ + "name", + jsx_name(param[1].name) + ]]); + }; + var comment = function (param) { + var c = param[1]; + var match; + match = c.TAG === /* Block */0 ? [ + "Block", + c._0 + ] : [ + "Line", + c._0 + ]; + return node(match[0], param[0], [[ + "value", + string(match[1]) + ]]); + }; + var function_type_param = function (param) { + var param$1 = param[1]; + return node("FunctionTypeParam", param[0], [ + [ + "name", + identifier(param$1.name) + ], + [ + "typeAnnotation", + _type(param$1.typeAnnotation) + ], + [ + "optional", + bool(param$1.optional) + ] + ]); + }; + var jsx_expression_container = function (param) { + var expr = param[1].expression; + var expression$1; + expression$1 = expr.TAG === /* Expression */0 ? expression(expr._0) : node("JSXEmptyExpression", expr._0, []); + return node("JSXExpressionContainer", param[0], [[ + "expression", + expression$1 + ]]); + }; var class_element = function (param) { if (param.TAG === /* Method */0) { var param$1 = param._0; @@ -17209,221 +16956,723 @@ function parse(content, options) { ]); } }; - var template_literal = function (param) { - var value = param[1]; - return node("TemplateLiteral", param[0], [ - [ - "quasis", - array_of_list(template_element, value.quasis) - ], - [ - "expressions", - array_of_list(expression, value.expressions) - ] - ]); + var array_pattern_element = function (param) { + if (param.TAG === /* Element */0) { + return pattern(param._0); + } + var match = param._0; + return node("SpreadElementPattern", match[0], [[ + "argument", + pattern(match[1].argument) + ]]); }; - var generic_type_qualified_identifier = function (param) { - var q = param[1]; - var id = q.qualification; - var qualification; - qualification = id.TAG === /* Unqualified */0 ? identifier(id._0) : generic_type_qualified_identifier(id._0); - return node("QualifiedTypeIdentifier", param[0], [ + var object_pattern_property = function (param) { + if (param.TAG === /* Property */0) { + var match = param._0; + var prop = match[1]; + var lit = prop.key; + var match$1; + switch (lit.TAG | 0) { + case /* Literal */0 : + match$1 = [ + literal(lit._0), + false + ]; + break; + case /* Identifier */1 : + match$1 = [ + identifier(lit._0), + false + ]; + break; + case /* Computed */2 : + match$1 = [ + expression(lit._0), + true + ]; + break; + + } + return node("PropertyPattern", match[0], [ + [ + "key", + match$1[0] + ], + [ + "pattern", + pattern(prop.pattern) + ], + [ + "computed", + bool(match$1[1]) + ], + [ + "shorthand", + bool(prop.shorthand) + ] + ]); + } + var match$2 = param._0; + return node("SpreadPropertyPattern", match$2[0], [[ + "argument", + pattern(match$2[1].argument) + ]]); + }; + var type_param = function (param) { + var tp = param[1]; + var variance = function (param) { + if (param) { + return string("minus"); + } else { + return string("plus"); + } + }; + return node("TypeParameter", param[0], [ [ - "qualification", - qualification + "name", + string(tp.name) ], [ - "id", - identifier(q.id) - ] - ]); - }; - var export_specifier = function (param) { - var specifier = param[1]; - return node("ExportSpecifier", param[0], [ + "bound", + option(type_annotation, tp.bound) + ], [ - "id", - identifier(specifier.id) + "variance", + option(variance, tp.variance) ], [ - "name", - option(identifier, specifier.name) + "default", + option(_type, tp.default) ] ]); }; - var expression_or_spread = function (param) { - if (param.TAG === /* Expression */0) { - return expression(param._0); + var jsx_opening_attribute = function (param) { + if (param.TAG === /* Attribute */0) { + var param$1 = param._0; + var attribute = param$1[1]; + var id = attribute.name; + var name; + name = id.TAG === /* Identifier */0 ? jsx_identifier(id._0) : jsx_namespaced_name(id._0); + return node("JSXAttribute", param$1[0], [ + [ + "name", + name + ], + [ + "value", + option(jsx_attribute_value, attribute.value) + ] + ]); + } else { + var param$2 = param._0; + return node("JSXSpreadAttribute", param$2[0], [[ + "argument", + expression(param$2[1].argument) + ]]); } - var match = param._0; - return node("SpreadElement", match[0], [[ - "argument", - expression(match[1].argument) - ]]); }; - var let_assignment = function (assignment) { - return obj([ + var jsx_name = function (param) { + switch (param.TAG | 0) { + case /* Identifier */0 : + return jsx_identifier(param._0); + case /* NamespacedName */1 : + return jsx_namespaced_name(param._0); + case /* MemberExpression */2 : + return jsx_member_expression(param._0); + + } + }; + var object_type_indexer = function (param) { + var indexer = param[1]; + return node("ObjectTypeIndexer", param[0], [ [ "id", - pattern(assignment.id) + identifier(indexer.id) ], [ - "init", - option(expression, assignment.init) + "key", + _type(indexer.key) + ], + [ + "value", + _type(indexer.value) + ], + [ + "static", + bool(indexer.static) ] ]); }; - var jsx_element = function (param) { - var element = param[1]; - return node("JSXElement", param[0], [ - [ - "openingElement", - jsx_opening(element.openingElement) - ], + var object_type_call_property = function (param) { + var callProperty = param[1]; + return node("ObjectTypeCallProperty", param[0], [ [ - "closingElement", - option(jsx_closing, element.closingElement) + "value", + function_type(callProperty.value) ], [ - "children", - array_of_list(jsx_child, element.children) + "static", + bool(callProperty.static) ] ]); }; - var block = function (param) { - return node("BlockStatement", param[0], [[ - "body", - array_of_list(statement, param[1].body) - ]]); - }; - var comprehension_block = function (param) { - var b = param[1]; - return node("ComprehensionBlock", param[0], [ + var object_type_property = function (param) { + var prop = param[1]; + var lit = prop.key; + var key; + switch (lit.TAG | 0) { + case /* Literal */0 : + key = literal(lit._0); + break; + case /* Identifier */1 : + key = identifier(lit._0); + break; + case /* Computed */2 : + throw { + MEL_EXN_ID: "Failure", + _1: "There should not be computed object type property keys", + Error: new Error() + }; + + } + return node("ObjectTypeProperty", param[0], [ [ - "left", - pattern(b.left) + "key", + key ], [ - "right", - expression(b.right) + "value", + _type(prop.value) ], [ - "each", - bool(b.each) + "optional", + bool(prop.optional) + ], + [ + "static", + bool(prop.static) ] ]); }; - var object_property = function (param) { - if (param.TAG === /* Property */0) { - var match = param._0; - var prop = match[1]; - var lit = prop.key; - var match$1; - switch (lit.TAG | 0) { - case /* Literal */0 : - match$1 = [ - literal(lit._0), - false - ]; - break; - case /* Identifier */1 : - match$1 = [ - identifier(lit._0), - false + var statement = function (param) { + var b = param[1]; + var loc = param[0]; + if (typeof b === "number") { + if (b === /* Empty */0) { + return node("EmptyStatement", loc, []); + } else { + return node("DebuggerStatement", loc, []); + } + } + switch (b.TAG | 0) { + case /* Block */0 : + return block([ + loc, + b._0 + ]); + case /* Expression */1 : + return node("ExpressionStatement", loc, [[ + "expression", + expression(b._0.expression) + ]]); + case /* If */2 : + var _if = b._0; + return node("IfStatement", loc, [ + [ + "test", + expression(_if.test) + ], + [ + "consequent", + statement(_if.consequent) + ], + [ + "alternate", + option(statement, _if.alternate) + ] + ]); + case /* Labeled */3 : + var labeled = b._0; + return node("LabeledStatement", loc, [ + [ + "label", + identifier(labeled.label) + ], + [ + "body", + statement(labeled.body) + ] + ]); + case /* Break */4 : + return node("BreakStatement", loc, [[ + "label", + option(identifier, b._0.label) + ]]); + case /* Continue */5 : + return node("ContinueStatement", loc, [[ + "label", + option(identifier, b._0.label) + ]]); + case /* With */6 : + var _with = b._0; + return node("WithStatement", loc, [ + [ + "object", + expression(_with._object) + ], + [ + "body", + statement(_with.body) + ] + ]); + case /* TypeAlias */7 : + return type_alias([ + loc, + b._0 + ]); + case /* Switch */8 : + var $$switch = b._0; + return node("SwitchStatement", loc, [ + [ + "discriminant", + expression($$switch.discriminant) + ], + [ + "cases", + array_of_list($$case, $$switch.cases) + ], + [ + "lexical", + bool($$switch.lexical) + ] + ]); + case /* Return */9 : + return node("ReturnStatement", loc, [[ + "argument", + option(expression, b._0.argument) + ]]); + case /* Throw */10 : + return node("ThrowStatement", loc, [[ + "argument", + expression(b._0.argument) + ]]); + case /* Try */11 : + var _try = b._0; + return node("TryStatement", loc, [ + [ + "block", + block(_try.block) + ], + [ + "handler", + option($$catch, _try.handler) + ], + [ + "guardedHandlers", + array_of_list($$catch, _try.guardedHandlers) + ], + [ + "finalizer", + option(block, _try.finalizer) + ] + ]); + case /* While */12 : + var _while = b._0; + return node("WhileStatement", loc, [ + [ + "test", + expression(_while.test) + ], + [ + "body", + statement(_while.body) + ] + ]); + case /* DoWhile */13 : + var dowhile = b._0; + return node("DoWhileStatement", loc, [ + [ + "body", + statement(dowhile.body) + ], + [ + "test", + expression(dowhile.test) + ] + ]); + case /* For */14 : + var _for = b._0; + var init = function (param) { + if (param.TAG === /* InitDeclaration */0) { + return variable_declaration(param._0); + } else { + return expression(param._0); + } + }; + return node("ForStatement", loc, [ + [ + "init", + option(init, _for.init) + ], + [ + "test", + option(expression, _for.test) + ], + [ + "update", + option(expression, _for.update) + ], + [ + "body", + statement(_for.body) + ] + ]); + case /* ForIn */15 : + var forin = b._0; + var left = forin.left; + var left$1; + left$1 = left.TAG === /* LeftDeclaration */0 ? variable_declaration(left._0) : expression(left._0); + return node("ForInStatement", loc, [ + [ + "left", + left$1 + ], + [ + "right", + expression(forin.right) + ], + [ + "body", + statement(forin.body) + ], + [ + "each", + bool(forin.each) + ] + ]); + case /* ForOf */16 : + var forof = b._0; + var left$2 = forof.left; + var left$3; + left$3 = left$2.TAG === /* LeftDeclaration */0 ? variable_declaration(left$2._0) : expression(left$2._0); + return node("ForOfStatement", loc, [ + [ + "left", + left$3 + ], + [ + "right", + expression(forof.right) + ], + [ + "body", + statement(forof.body) + ] + ]); + case /* Let */17 : + var _let = b._0; + return node("LetStatement", loc, [ + [ + "head", + array_of_list(let_assignment, _let.head) + ], + [ + "body", + statement(_let.body) + ] + ]); + case /* FunctionDeclaration */18 : + var fn = b._0; + var id = fn.id; + var match = id !== undefined ? [ + "FunctionDeclaration", + identifier(id) + ] : [ + "FunctionExpression", + $$null ]; - break; - case /* Computed */2 : - match$1 = [ - expression(lit._0), - true + var b$1 = fn.body; + var body; + body = b$1.TAG === /* BodyBlock */0 ? block(b$1._0) : expression(b$1._0); + return node(match[0], loc, [ + [ + "id", + match[1] + ], + [ + "params", + array_of_list(pattern, fn.params) + ], + [ + "defaults", + array_of_list((function (param) { + return option(expression, param); + }), fn.defaults) + ], + [ + "rest", + option(identifier, fn.rest) + ], + [ + "body", + body + ], + [ + "async", + bool(fn.async) + ], + [ + "generator", + bool(fn.generator) + ], + [ + "expression", + bool(fn.expression) + ], + [ + "returnType", + option(type_annotation, fn.returnType) + ], + [ + "typeParameters", + option(type_parameter_declaration, fn.typeParameters) + ] + ]); + case /* VariableDeclaration */19 : + return variable_declaration([ + loc, + b._0 + ]); + case /* ClassDeclaration */20 : + var param$1 = [ + loc, + b._0 + ]; + var c = param$1[1]; + var id$1 = c.id; + var match$1 = id$1 !== undefined ? [ + "ClassDeclaration", + identifier(id$1) + ] : [ + "ClassExpression", + $$null ]; - break; - - } - var match$2 = prop.kind; - var kind; - switch (match$2) { - case /* Init */0 : - kind = "init"; - break; - case /* Get */1 : - kind = "get"; - break; - case /* Set */2 : - kind = "set"; - break; - - } - return node("Property", match[0], [ - [ - "key", - match$1[0] - ], - [ - "value", - expression(prop.value) - ], - [ - "kind", - string(kind) - ], - [ - "method", - bool(prop._method) - ], - [ - "shorthand", - bool(prop.shorthand) - ], - [ - "computed", - bool(match$1[1]) - ] - ]); + return node(match$1[0], param$1[0], [ + [ + "id", + match$1[1] + ], + [ + "body", + class_body(c.body) + ], + [ + "superClass", + option(expression, c.superClass) + ], + [ + "typeParameters", + option(type_parameter_declaration, c.typeParameters) + ], + [ + "superTypeParameters", + option(type_parameter_instantiation, c.superTypeParameters) + ], + [ + "implements", + array_of_list(class_implements, c.implements) + ], + [ + "decorators", + array_of_list(expression, c.classDecorators) + ] + ]); + case /* InterfaceDeclaration */21 : + return interface_declaration([ + loc, + b._0 + ]); + case /* DeclareVariable */22 : + return declare_variable([ + loc, + b._0 + ]); + case /* DeclareFunction */23 : + return declare_function([ + loc, + b._0 + ]); + case /* DeclareClass */24 : + return declare_class([ + loc, + b._0 + ]); + case /* DeclareModule */25 : + var m = b._0; + var lit = m.id; + var id$2; + id$2 = lit.TAG === /* Identifier */0 ? identifier(lit._0) : literal(lit._0); + var match$2 = m.kind; + var tmp; + tmp = match$2.TAG === /* CommonJS */0 ? string("CommonJS") : string("ES"); + return node("DeclareModule", loc, [ + [ + "id", + id$2 + ], + [ + "body", + block(m.body) + ], + [ + "kind", + tmp + ] + ]); + case /* DeclareModuleExports */26 : + return node("DeclareModuleExports", loc, [[ + "typeAnnotation", + type_annotation(b._0) + ]]); + case /* DeclareExportDeclaration */27 : + var $$export = b._0; + var match$3 = $$export.declaration; + var declaration; + if (match$3 !== undefined) { + switch (match$3.TAG | 0) { + case /* Variable */0 : + declaration = declare_variable(match$3._0); + break; + case /* Function */1 : + declaration = declare_function(match$3._0); + break; + case /* Class */2 : + declaration = declare_class(match$3._0); + break; + case /* DefaultType */3 : + declaration = _type(match$3._0); + break; + case /* NamedType */4 : + declaration = type_alias(match$3._0); + break; + case /* Interface */5 : + declaration = interface_declaration(match$3._0); + break; + + } + } else { + declaration = $$null; + } + return node("DeclareExportDeclaration", loc, [ + [ + "default", + bool($$export.default) + ], + [ + "declaration", + declaration + ], + [ + "specifiers", + export_specifiers($$export.specifiers) + ], + [ + "source", + option(literal, $$export.source) + ] + ]); + case /* ExportDeclaration */28 : + var $$export$1 = b._0; + var match$4 = $$export$1.declaration; + var declaration$1 = match$4 !== undefined ? ( + match$4.TAG === /* Declaration */0 ? statement(match$4._0) : expression(match$4._0) + ) : $$null; + return node("ExportDeclaration", loc, [ + [ + "default", + bool($$export$1.default) + ], + [ + "declaration", + declaration$1 + ], + [ + "specifiers", + export_specifiers($$export$1.specifiers) + ], + [ + "source", + option(literal, $$export$1.source) + ], + [ + "exportKind", + string($$export$1.exportKind ? "value" : "type") + ] + ]); + case /* ImportDeclaration */29 : + var $$import = b._0; + var specifiers = Stdlib__List.map((function (param) { + switch (param.TAG | 0) { + case /* ImportNamedSpecifier */0 : + var match = param._0; + var local_id = match.local; + var remote_id = match.remote; + var span_loc = local_id !== undefined ? btwn(remote_id[0], local_id[0]) : remote_id[0]; + return node("ImportSpecifier", span_loc, [ + [ + "id", + identifier(remote_id) + ], + [ + "name", + option(identifier, local_id) + ] + ]); + case /* ImportDefaultSpecifier */1 : + var id = param._0; + return node("ImportDefaultSpecifier", id[0], [[ + "id", + identifier(id) + ]]); + case /* ImportNamespaceSpecifier */2 : + var param$1 = param._0; + return node("ImportNamespaceSpecifier", param$1[0], [[ + "id", + identifier(param$1[1]) + ]]); + + } + }), $$import.specifiers); + var match$5 = $$import.importKind; + var import_kind; + switch (match$5) { + case /* ImportType */0 : + import_kind = "type"; + break; + case /* ImportTypeof */1 : + import_kind = "typeof"; + break; + case /* ImportValue */2 : + import_kind = "value"; + break; + + } + return node("ImportDeclaration", loc, [ + [ + "specifiers", + array(Stdlib__Array.of_list(specifiers)) + ], + [ + "source", + literal($$import.source) + ], + [ + "importKind", + string(import_kind) + ] + ]); + } - var match$3 = param._0; - return node("SpreadProperty", match$3[0], [[ - "argument", - expression(match$3[1].argument) - ]]); - }; - var function_type_param = function (param) { - var param$1 = param[1]; - return node("FunctionTypeParam", param[0], [ - [ - "name", - identifier(param$1.name) - ], - [ - "typeAnnotation", - _type(param$1.typeAnnotation) - ], - [ - "optional", - bool(param$1.optional) - ] - ]); - }; - var function_type = function (param) { - var fn = param[1]; - return node("FunctionTypeAnnotation", param[0], [ - [ - "params", - array_of_list(function_type_param, fn.params) - ], - [ - "returnType", - _type(fn.returnType) - ], - [ - "rest", - option(function_type_param, fn.rest) - ], - [ - "typeParameters", - option(type_parameter_declaration, fn.typeParameters) - ] - ]); }; var declare_function = function (param) { return node("DeclareFunction", param[0], [[ @@ -17431,390 +17680,141 @@ function parse(content, options) { identifier(param[1].id) ]]); }; - var $$catch = function (param) { - var c = param[1]; - return node("CatchClause", param[0], [ - [ - "param", - pattern(c.param) - ], - [ - "guard", - option(expression, c.guard) - ], - [ - "body", - block(c.body) - ] - ]); - }; - var variable_declaration = function (param) { - var $$var = param[1]; - var match = $$var.kind; - var kind; - switch (match) { - case /* Var */0 : - kind = "var"; - break; - case /* Let */1 : - kind = "let"; - break; - case /* Const */2 : - kind = "const"; - break; - - } - return node("VariableDeclaration", param[0], [ - [ - "declarations", - array_of_list(variable_declarator, $$var.declarations) - ], - [ - "kind", - string(kind) - ] - ]); - }; - var declare_variable = function (param) { - return node("DeclareVariable", param[0], [[ - "id", - identifier(param[1].id) - ]]); - }; - var type_alias = function (param) { - var alias = param[1]; - return node("TypeAlias", param[0], [ - [ - "id", - identifier(alias.id) - ], - [ - "typeParameters", - option(type_parameter_declaration, alias.typeParameters) - ], - [ - "right", - _type(alias.right) - ] - ]); - }; - var declare_class = function (param) { - var d = param[1]; - return node("DeclareClass", param[0], [ - [ - "id", - identifier(d.id) - ], - [ - "typeParameters", - option(type_parameter_declaration, d.typeParameters) - ], - [ - "body", - object_type(d.body) - ], - [ - "extends", - array_of_list(interface_extends, d.extends) - ] - ]); - }; - var $$case = function (param) { - var c = param[1]; - return node("SwitchCase", param[0], [ - [ - "test", - option(expression, c.test) - ], - [ - "consequent", - array_of_list(statement, c.consequent) - ] - ]); - }; - var interface_declaration = function (param) { - var i = param[1]; - return node("InterfaceDeclaration", param[0], [ - [ - "id", - identifier(i.id) - ], - [ - "typeParameters", - option(type_parameter_declaration, i.typeParameters) - ], - [ - "body", - object_type(i.body) - ], - [ - "extends", - array_of_list(interface_extends, i.extends) - ] - ]); - }; var export_specifiers = function (param) { if (param !== undefined) { if (param.TAG === /* ExportSpecifiers */0) { return array_of_list(export_specifier, param._0); } else { return array([node("ExportBatchSpecifier", param._0, [[ - "name", - option(identifier, param._1) - ]])]); - } - } else { - return array([]); - } - }; - var comment = function (param) { - var c = param[1]; - var match; - match = c.TAG === /* Block */0 ? [ - "Block", - c._0 - ] : [ - "Line", - c._0 - ]; - return node(match[0], param[0], [[ - "value", - string(match[1]) - ]]); - }; - var object_type_property = function (param) { - var prop = param[1]; - var lit = prop.key; - var key; - switch (lit.TAG | 0) { - case /* Literal */0 : - key = literal(lit._0); - break; - case /* Identifier */1 : - key = identifier(lit._0); - break; - case /* Computed */2 : - throw { - MEL_EXN_ID: "Failure", - _1: "There should not be computed object type property keys", - Error: new Error() - }; - + "name", + option(identifier, param._1) + ]])]); + } + } else { + return array([]); } - return node("ObjectTypeProperty", param[0], [ - [ - "key", - key - ], + }; + var $$catch = function (param) { + var c = param[1]; + return node("CatchClause", param[0], [ [ - "value", - _type(prop.value) + "param", + pattern(c.param) ], [ - "optional", - bool(prop.optional) + "guard", + option(expression, c.guard) ], [ - "static", - bool(prop.static) + "body", + block(c.body) ] ]); }; - var object_type_indexer = function (param) { - var indexer = param[1]; - return node("ObjectTypeIndexer", param[0], [ + var declare_class = function (param) { + var d = param[1]; + return node("DeclareClass", param[0], [ [ "id", - identifier(indexer.id) + identifier(d.id) ], [ - "key", - _type(indexer.key) + "typeParameters", + option(type_parameter_declaration, d.typeParameters) ], [ - "value", - _type(indexer.value) + "body", + object_type(d.body) ], [ - "static", - bool(indexer.static) + "extends", + array_of_list(interface_extends, d.extends) ] ]); }; - var object_type_call_property = function (param) { - var callProperty = param[1]; - return node("ObjectTypeCallProperty", param[0], [ + var variable_declaration = function (param) { + var $$var = param[1]; + var match = $$var.kind; + var kind; + switch (match) { + case /* Var */0 : + kind = "var"; + break; + case /* Let */1 : + kind = "let"; + break; + case /* Const */2 : + kind = "const"; + break; + + } + return node("VariableDeclaration", param[0], [ [ - "value", - function_type(callProperty.value) + "declarations", + array_of_list(variable_declarator, $$var.declarations) ], [ - "static", - bool(callProperty.static) + "kind", + string(kind) ] ]); }; - var type_param = function (param) { - var tp = param[1]; - var variance = function (param) { - if (param) { - return string("minus"); - } else { - return string("plus"); - } - }; - return node("TypeParameter", param[0], [ + var interface_declaration = function (param) { + var i = param[1]; + return node("InterfaceDeclaration", param[0], [ [ - "name", - string(tp.name) + "id", + identifier(i.id) ], [ - "bound", - option(type_annotation, tp.bound) + "typeParameters", + option(type_parameter_declaration, i.typeParameters) ], [ - "variance", - option(variance, tp.variance) + "body", + object_type(i.body) ], [ - "default", - option(_type, tp.default) + "extends", + array_of_list(interface_extends, i.extends) ] ]); }; - var template_element = function (param) { - var element = param[1]; - var value = obj([ - [ - "raw", - string(element.value.raw) - ], - [ - "cooked", - string(element.value.cooked) - ] - ]); - return node("TemplateElement", param[0], [ + var $$case = function (param) { + var c = param[1]; + return node("SwitchCase", param[0], [ [ - "value", - value + "test", + option(expression, c.test) ], [ - "tail", - bool(element.tail) + "consequent", + array_of_list(statement, c.consequent) ] ]); }; - var jsx_name = function (param) { - switch (param.TAG | 0) { - case /* Identifier */0 : - return jsx_identifier(param._0); - case /* NamespacedName */1 : - return jsx_namespaced_name(param._0); - case /* MemberExpression */2 : - return jsx_member_expression(param._0); - - } - }; - var object_pattern_property = function (param) { - if (param.TAG === /* Property */0) { - var match = param._0; - var prop = match[1]; - var lit = prop.key; - var match$1; - switch (lit.TAG | 0) { - case /* Literal */0 : - match$1 = [ - literal(lit._0), - false - ]; - break; - case /* Identifier */1 : - match$1 = [ - identifier(lit._0), - false - ]; - break; - case /* Computed */2 : - match$1 = [ - expression(lit._0), - true - ]; - break; - - } - return node("PropertyPattern", match[0], [ - [ - "key", - match$1[0] - ], - [ - "pattern", - pattern(prop.pattern) - ], - [ - "computed", - bool(match$1[1]) - ], - [ - "shorthand", - bool(prop.shorthand) - ] - ]); - } - var match$2 = param._0; - return node("SpreadPropertyPattern", match$2[0], [[ - "argument", - pattern(match$2[1].argument) - ]]); - }; - var array_pattern_element = function (param) { - if (param.TAG === /* Element */0) { - return pattern(param._0); - } - var match = param._0; - return node("SpreadElementPattern", match[0], [[ - "argument", - pattern(match[1].argument) + var declare_variable = function (param) { + return node("DeclareVariable", param[0], [[ + "id", + identifier(param[1].id) ]]); }; - var jsx_attribute_value = function (param) { - if (param.TAG === /* Literal */0) { - return literal([ - param._0, - param._1 - ]); - } else { - return jsx_expression_container([ - param._0, - param._1 - ]); - } - }; - var jsx_opening_attribute = function (param) { - if (param.TAG === /* Attribute */0) { - var param$1 = param._0; - var attribute = param$1[1]; - var id = attribute.name; - var name; - name = id.TAG === /* Identifier */0 ? jsx_identifier(id._0) : jsx_namespaced_name(id._0); - return node("JSXAttribute", param$1[0], [ - [ - "name", - name - ], - [ - "value", - option(jsx_attribute_value, attribute.value) - ] - ]); - } else { - var param$2 = param._0; - return node("JSXSpreadAttribute", param$2[0], [[ - "argument", - expression(param$2[1].argument) - ]]); - } + var type_alias = function (param) { + var alias = param[1]; + return node("TypeAlias", param[0], [ + [ + "id", + identifier(alias.id) + ], + [ + "typeParameters", + option(type_parameter_declaration, alias.typeParameters) + ], + [ + "right", + _type(alias.right) + ] + ]); }; var program$2 = function (param) { return node("Program", param[0], [ diff --git a/jscomp/test/dist/jscomp/test/js_array_test.js b/jscomp/test/dist/jscomp/test/js_array_test.js index a609f71218..f49e6fa342 100644 --- a/jscomp/test/dist/jscomp/test/js_array_test.js +++ b/jscomp/test/dist/jscomp/test/js_array_test.js @@ -60,7 +60,7 @@ var suites_1 = { 3, 4, 5 - ].copyWithin(-2) + ].copyWithin(-2, undefined, undefined) }; }) ], @@ -83,7 +83,7 @@ var suites_1 = { 3, 4, 5 - ].copyWithin(0, 3) + ].copyWithin(0, 3, undefined) }; }) ], @@ -125,7 +125,7 @@ var suites_1 = { 1, 2, 3 - ].fill(4) + ].fill(4, undefined, undefined) }; }) ], @@ -144,7 +144,7 @@ var suites_1 = { 1, 2, 3 - ].fill(4, 1) + ].fill(4, 1, undefined) }; }) ], @@ -525,7 +525,7 @@ var suites_1 = { 1, 2, 3 - ].indexOf(2) + ].indexOf(2, undefined) }; }) ], @@ -556,7 +556,7 @@ var suites_1 = { 1, 2, 3 - ].join() + ].join(",") }; }) ], @@ -666,7 +666,7 @@ var suites_1 = { 3, 4, 5 - ].slice(2) + ].slice(2, undefined) }; }) ], diff --git a/jscomp/test/dist/jscomp/test/ocaml_parsetree_test.js b/jscomp/test/dist/jscomp/test/ocaml_parsetree_test.js index 124085f23e..6a9d17d7b1 100644 --- a/jscomp/test/dist/jscomp/test/ocaml_parsetree_test.js +++ b/jscomp/test/dist/jscomp/test/ocaml_parsetree_test.js @@ -11409,6 +11409,20 @@ function directive_parse(token_with_comments, lexbuf) { } } }; + var parse_or_aux = function (calc, v) { + var e = token(undefined); + if (e === 8) { + var calc$1 = calc && !v; + var b = parse_or_aux(calc$1, parse_and_aux(calc$1, parse_relation(calc$1))); + if (v) { + return true; + } else { + return b; + } + } + push(e); + return v; + }; var parse_and_aux = function (calc, v) { var e = token(undefined); if (typeof e === "number") { @@ -11427,20 +11441,6 @@ function directive_parse(token_with_comments, lexbuf) { push(e); return v; }; - var parse_or_aux = function (calc, v) { - var e = token(undefined); - if (e === 8) { - var calc$1 = calc && !v; - var b = parse_or_aux(calc$1, parse_and_aux(calc$1, parse_relation(calc$1))); - if (v) { - return true; - } else { - return b; - } - } - push(e); - return v; - }; var v = parse_or_aux(true, parse_and_aux(true, parse_relation(true))); var match = token(undefined); if (match === 88) { diff --git a/jscomp/test/dist/jscomp/test/ocaml_typedtree_test.js b/jscomp/test/dist/jscomp/test/ocaml_typedtree_test.js index ec0e05cd4d..bedf8c3707 100644 --- a/jscomp/test/dist/jscomp/test/ocaml_typedtree_test.js +++ b/jscomp/test/dist/jscomp/test/ocaml_typedtree_test.js @@ -24966,6 +24966,49 @@ function token(lexbuf) { }; } +function __ocaml_lex_quoted_string_rec(delim, lexbuf, ___ocaml_lex_state) { + while(true) { + var __ocaml_lex_state = ___ocaml_lex_state; + var __ocaml_lex_state$1 = Stdlib__Lexing.engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf); + switch (__ocaml_lex_state$1) { + case 0 : + update_loc(lexbuf, undefined, 1, false, 0); + store_string(Stdlib__Lexing.lexeme(lexbuf)); + ___ocaml_lex_state = 183; + continue ; + case 1 : + is_in_string.contents = false; + throw { + MEL_EXN_ID: $$Error$4, + _1: /* Unterminated_string */0, + _2: string_start_loc.contents, + Error: new Error() + }; + case 2 : + var edelim = Stdlib__Lexing.lexeme(lexbuf); + var edelim$1 = Stdlib__String.sub(edelim, 1, edelim.length - 2 | 0); + if (delim === edelim$1) { + return ; + } + store_string(Stdlib__Lexing.lexeme(lexbuf)); + ___ocaml_lex_state = 183; + continue ; + case 3 : + store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); + ___ocaml_lex_state = 183; + continue ; + default: + Curry._1(lexbuf.refill_buff, lexbuf); + ___ocaml_lex_state = __ocaml_lex_state$1; + continue ; + } + }; +} + +function comment(lexbuf) { + return __ocaml_lex_comment_rec(lexbuf, 132); +} + function string(lexbuf) { lexbuf.lex_mem = Caml_array.make(2, -1); var ___ocaml_lex_state = 164; @@ -25023,10 +25066,6 @@ function string(lexbuf) { }; } -function comment(lexbuf) { - return __ocaml_lex_comment_rec(lexbuf, 132); -} - function __ocaml_lex_comment_rec(lexbuf, ___ocaml_lex_state) { while(true) { var __ocaml_lex_state = ___ocaml_lex_state; @@ -25212,45 +25251,6 @@ function __ocaml_lex_comment_rec(lexbuf, ___ocaml_lex_state) { }; } -function __ocaml_lex_quoted_string_rec(delim, lexbuf, ___ocaml_lex_state) { - while(true) { - var __ocaml_lex_state = ___ocaml_lex_state; - var __ocaml_lex_state$1 = Stdlib__Lexing.engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf); - switch (__ocaml_lex_state$1) { - case 0 : - update_loc(lexbuf, undefined, 1, false, 0); - store_string(Stdlib__Lexing.lexeme(lexbuf)); - ___ocaml_lex_state = 183; - continue ; - case 1 : - is_in_string.contents = false; - throw { - MEL_EXN_ID: $$Error$4, - _1: /* Unterminated_string */0, - _2: string_start_loc.contents, - Error: new Error() - }; - case 2 : - var edelim = Stdlib__Lexing.lexeme(lexbuf); - var edelim$1 = Stdlib__String.sub(edelim, 1, edelim.length - 2 | 0); - if (delim === edelim$1) { - return ; - } - store_string(Stdlib__Lexing.lexeme(lexbuf)); - ___ocaml_lex_state = 183; - continue ; - case 3 : - store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); - ___ocaml_lex_state = 183; - continue ; - default: - Curry._1(lexbuf.refill_buff, lexbuf); - ___ocaml_lex_state = __ocaml_lex_state$1; - continue ; - } - }; -} - function at_bol(lexbuf) { var pos = lexbuf.lex_start_p; return pos.pos_cnum === pos.pos_bol; @@ -26077,121 +26077,201 @@ function TypedtreeMap_MakeMap(funarg) { str_final_env: str$1.str_final_env }); }; - var map_pattern = function (pat) { - var pat$1 = Curry._1(funarg.enter_pattern, pat); - var list = pat$1.pat_desc; - var pat_desc; - if (typeof list === "number") { - pat_desc = pat$1.pat_desc; + var map_binding = function (vb) { + return { + vb_pat: map_pattern(vb.vb_pat), + vb_expr: map_expression(vb.vb_expr), + vb_attributes: vb.vb_attributes, + vb_loc: vb.vb_loc + }; + }; + var map_extension_constructor = function (ext) { + var ext$1 = Curry._1(funarg.enter_extension_constructor, ext); + var match = ext$1.ext_kind; + var ext_kind; + if (match.TAG === /* Text_decl */0) { + var args = Stdlib__List.map(map_core_type, match._0); + var ret = may_map(map_core_type, match._1); + ext_kind = { + TAG: /* Text_decl */0, + _0: args, + _1: ret + }; } else { - switch (list.TAG | 0) { - case /* Tpat_alias */1 : - var pat1 = map_pattern(list._0); - pat_desc = { - TAG: /* Tpat_alias */1, - _0: pat1, - _1: list._1, - _2: list._2 - }; - break; - case /* Tpat_tuple */3 : - pat_desc = { - TAG: /* Tpat_tuple */3, - _0: Stdlib__List.map(map_pattern, list._0) - }; - break; - case /* Tpat_construct */4 : - pat_desc = { - TAG: /* Tpat_construct */4, - _0: list._0, - _1: list._1, - _2: Stdlib__List.map(map_pattern, list._2) - }; - break; - case /* Tpat_variant */5 : - var pato = list._1; - var pato$1 = pato !== undefined ? map_pattern(pato) : pato; - pat_desc = { - TAG: /* Tpat_variant */5, - _0: list._0, - _1: pato$1, - _2: list._2 - }; - break; - case /* Tpat_record */6 : - pat_desc = { - TAG: /* Tpat_record */6, - _0: Stdlib__List.map((function (param) { - return [ - param[0], - param[1], - map_pattern(param[2]) - ]; - }), list._0), - _1: list._1 - }; - break; - case /* Tpat_array */7 : - pat_desc = { - TAG: /* Tpat_array */7, - _0: Stdlib__List.map(map_pattern, list._0) - }; - break; - case /* Tpat_or */8 : - pat_desc = { - TAG: /* Tpat_or */8, - _0: map_pattern(list._0), - _1: map_pattern(list._1), - _2: list._2 - }; - break; - case /* Tpat_lazy */9 : - pat_desc = { - TAG: /* Tpat_lazy */9, - _0: map_pattern(list._0) - }; - break; - default: - pat_desc = pat$1.pat_desc; - } + ext_kind = { + TAG: /* Text_rebind */1, + _0: match._0, + _1: match._1 + }; } - var pat_extra = Stdlib__List.map(map_pat_extra, pat$1.pat_extra); - return Curry._1(funarg.leave_pattern, { - pat_desc: pat_desc, - pat_loc: pat$1.pat_loc, - pat_extra: pat_extra, - pat_type: pat$1.pat_type, - pat_env: pat$1.pat_env, - pat_attributes: pat$1.pat_attributes + return Curry._1(funarg.leave_extension_constructor, { + ext_id: ext$1.ext_id, + ext_name: ext$1.ext_name, + ext_type: ext$1.ext_type, + ext_kind: ext_kind, + ext_loc: ext$1.ext_loc, + ext_attributes: ext$1.ext_attributes }); }; - var map_expression = function (exp) { - var exp$1 = Curry._1(funarg.enter_expression, exp); - var list = exp$1.exp_desc; - var exp_desc; - switch (list.TAG | 0) { - case /* Texp_let */2 : - var rec_flag = list._0; - exp_desc = { - TAG: /* Texp_let */2, - _0: rec_flag, - _1: Stdlib__List.map(map_binding, list._1), - _2: map_expression(list._2) - }; + var map_class_declaration = function (cd) { + var cd$1 = Curry._1(funarg.enter_class_declaration, cd); + var ci_params = Stdlib__List.map(map_type_parameter, cd$1.ci_params); + var ci_expr = map_class_expr(cd$1.ci_expr); + return Curry._1(funarg.leave_class_declaration, { + ci_virt: cd$1.ci_virt, + ci_params: ci_params, + ci_id_name: cd$1.ci_id_name, + ci_id_class: cd$1.ci_id_class, + ci_id_class_type: cd$1.ci_id_class_type, + ci_id_object: cd$1.ci_id_object, + ci_id_typesharp: cd$1.ci_id_typesharp, + ci_expr: ci_expr, + ci_decl: cd$1.ci_decl, + ci_type_decl: cd$1.ci_type_decl, + ci_loc: cd$1.ci_loc, + ci_attributes: cd$1.ci_attributes + }); + }; + var map_module_expr = function (mexpr) { + var mexpr$1 = Curry._1(funarg.enter_module_expr, mexpr); + var st = mexpr$1.mod_desc; + var mod_desc; + switch (st.TAG | 0) { + case /* Tmod_ident */0 : + mod_desc = mexpr$1.mod_desc; break; - case /* Texp_function */3 : - exp_desc = { - TAG: /* Texp_function */3, - _0: list._0, - _1: Stdlib__List.map(map_case, list._1), - _2: list._2 + case /* Tmod_structure */1 : + mod_desc = { + TAG: /* Tmod_structure */1, + _0: map_structure(st._0) }; break; - case /* Texp_apply */4 : - exp_desc = { - TAG: /* Texp_apply */4, - _0: map_expression(list._0), - _1: Stdlib__List.map((function (param) { + case /* Tmod_functor */2 : + mod_desc = { + TAG: /* Tmod_functor */2, + _0: st._0, + _1: st._1, + _2: may_map(map_module_type, st._2), + _3: map_module_expr(st._3) + }; + break; + case /* Tmod_apply */3 : + mod_desc = { + TAG: /* Tmod_apply */3, + _0: map_module_expr(st._0), + _1: map_module_expr(st._1), + _2: st._2 + }; + break; + case /* Tmod_constraint */4 : + var mtype = st._2; + var mod_type = st._1; + var mexpr$2 = st._0; + mod_desc = mtype ? ({ + TAG: /* Tmod_constraint */4, + _0: map_module_expr(mexpr$2), + _1: mod_type, + _2: /* Tmodtype_explicit */{ + _0: map_module_type(mtype._0) + }, + _3: st._3 + }) : ({ + TAG: /* Tmod_constraint */4, + _0: map_module_expr(mexpr$2), + _1: mod_type, + _2: /* Tmodtype_implicit */0, + _3: st._3 + }); + break; + case /* Tmod_unpack */5 : + mod_desc = { + TAG: /* Tmod_unpack */5, + _0: map_expression(st._0), + _1: st._1 + }; + break; + + } + return Curry._1(funarg.leave_module_expr, { + mod_desc: mod_desc, + mod_loc: mexpr$1.mod_loc, + mod_type: mexpr$1.mod_type, + mod_env: mexpr$1.mod_env, + mod_attributes: mexpr$1.mod_attributes + }); + }; + var map_type_extension = function (tyext) { + var tyext$1 = Curry._1(funarg.enter_type_extension, tyext); + var tyext_params = Stdlib__List.map(map_type_parameter, tyext$1.tyext_params); + var tyext_constructors = Stdlib__List.map(map_extension_constructor, tyext$1.tyext_constructors); + return Curry._1(funarg.leave_type_extension, { + tyext_path: tyext$1.tyext_path, + tyext_txt: tyext$1.tyext_txt, + tyext_params: tyext_params, + tyext_constructors: tyext_constructors, + tyext_private: tyext$1.tyext_private, + tyext_attributes: tyext$1.tyext_attributes + }); + }; + var map_value_description = function (v) { + var v$1 = Curry._1(funarg.enter_value_description, v); + var val_desc = map_core_type(v$1.val_desc); + return Curry._1(funarg.leave_value_description, { + val_id: v$1.val_id, + val_name: v$1.val_name, + val_desc: val_desc, + val_val: v$1.val_val, + val_prim: v$1.val_prim, + val_loc: v$1.val_loc, + val_attributes: v$1.val_attributes + }); + }; + var map_class_type_declaration = function (cd) { + var cd$1 = Curry._1(funarg.enter_class_type_declaration, cd); + var ci_params = Stdlib__List.map(map_type_parameter, cd$1.ci_params); + var ci_expr = map_class_type(cd$1.ci_expr); + return Curry._1(funarg.leave_class_type_declaration, { + ci_virt: cd$1.ci_virt, + ci_params: ci_params, + ci_id_name: cd$1.ci_id_name, + ci_id_class: cd$1.ci_id_class, + ci_id_class_type: cd$1.ci_id_class_type, + ci_id_object: cd$1.ci_id_object, + ci_id_typesharp: cd$1.ci_id_typesharp, + ci_expr: ci_expr, + ci_decl: cd$1.ci_decl, + ci_type_decl: cd$1.ci_type_decl, + ci_loc: cd$1.ci_loc, + ci_attributes: cd$1.ci_attributes + }); + }; + var map_expression = function (exp) { + var exp$1 = Curry._1(funarg.enter_expression, exp); + var list = exp$1.exp_desc; + var exp_desc; + switch (list.TAG | 0) { + case /* Texp_let */2 : + var rec_flag = list._0; + exp_desc = { + TAG: /* Texp_let */2, + _0: rec_flag, + _1: Stdlib__List.map(map_binding, list._1), + _2: map_expression(list._2) + }; + break; + case /* Texp_function */3 : + exp_desc = { + TAG: /* Texp_function */3, + _0: list._0, + _1: Stdlib__List.map(map_case, list._1), + _2: list._2 + }; + break; + case /* Texp_apply */4 : + exp_desc = { + TAG: /* Texp_apply */4, + _0: map_expression(list._0), + _1: Stdlib__List.map((function (param) { var expo = param[1]; var expo$1 = expo !== undefined ? map_expression(expo) : expo; return [ @@ -26396,243 +26476,75 @@ function TypedtreeMap_MakeMap(funarg) { exp_attributes: exp$1.exp_attributes }); }; - var map_extension_constructor = function (ext) { - var ext$1 = Curry._1(funarg.enter_extension_constructor, ext); - var match = ext$1.ext_kind; - var ext_kind; - if (match.TAG === /* Text_decl */0) { - var args = Stdlib__List.map(map_core_type, match._0); - var ret = may_map(map_core_type, match._1); - ext_kind = { - TAG: /* Text_decl */0, - _0: args, - _1: ret + var map_module_type_declaration = function (mtd) { + var mtd$1 = Curry._1(funarg.enter_module_type_declaration, mtd); + return Curry._1(funarg.leave_module_type_declaration, { + mtd_id: mtd$1.mtd_id, + mtd_name: mtd$1.mtd_name, + mtd_type: may_map(map_module_type, mtd$1.mtd_type), + mtd_attributes: mtd$1.mtd_attributes, + mtd_loc: mtd$1.mtd_loc + }); + }; + var map_type_declaration = function (decl) { + var decl$1 = Curry._1(funarg.enter_type_declaration, decl); + var typ_params = Stdlib__List.map(map_type_parameter, decl$1.typ_params); + var typ_cstrs = Stdlib__List.map((function (param) { + return [ + map_core_type(param[0]), + map_core_type(param[1]), + param[2] + ]; + }), decl$1.typ_cstrs); + var list = decl$1.typ_kind; + var typ_kind; + if (typeof list === "number") { + typ_kind = list === /* Ttype_abstract */0 ? /* Ttype_abstract */0 : /* Ttype_open */1; + } else if (list.TAG === /* Ttype_variant */0) { + var list$1 = Stdlib__List.map(map_constructor_declaration, list._0); + typ_kind = { + TAG: /* Ttype_variant */0, + _0: list$1 }; } else { - ext_kind = { - TAG: /* Text_rebind */1, - _0: match._0, - _1: match._1 + var list$2 = Stdlib__List.map((function (ld) { + return { + ld_id: ld.ld_id, + ld_name: ld.ld_name, + ld_mutable: ld.ld_mutable, + ld_type: map_core_type(ld.ld_type), + ld_loc: ld.ld_loc, + ld_attributes: ld.ld_attributes + }; + }), list._0); + typ_kind = { + TAG: /* Ttype_record */1, + _0: list$2 }; } - return Curry._1(funarg.leave_extension_constructor, { - ext_id: ext$1.ext_id, - ext_name: ext$1.ext_name, - ext_type: ext$1.ext_type, - ext_kind: ext_kind, - ext_loc: ext$1.ext_loc, - ext_attributes: ext$1.ext_attributes + var typ_manifest = may_map(map_core_type, decl$1.typ_manifest); + return Curry._1(funarg.leave_type_declaration, { + typ_id: decl$1.typ_id, + typ_name: decl$1.typ_name, + typ_params: typ_params, + typ_type: decl$1.typ_type, + typ_cstrs: typ_cstrs, + typ_kind: typ_kind, + typ_private: decl$1.typ_private, + typ_manifest: typ_manifest, + typ_loc: decl$1.typ_loc, + typ_attributes: decl$1.typ_attributes }); }; - var map_binding = function (vb) { + var map_module_binding = function (x) { return { - vb_pat: map_pattern(vb.vb_pat), - vb_expr: map_expression(vb.vb_expr), - vb_attributes: vb.vb_attributes, - vb_loc: vb.vb_loc + mb_id: x.mb_id, + mb_name: x.mb_name, + mb_expr: map_module_expr(x.mb_expr), + mb_attributes: x.mb_attributes, + mb_loc: x.mb_loc }; }; - var map_class_type_declaration = function (cd) { - var cd$1 = Curry._1(funarg.enter_class_type_declaration, cd); - var ci_params = Stdlib__List.map(map_type_parameter, cd$1.ci_params); - var ci_expr = map_class_type(cd$1.ci_expr); - return Curry._1(funarg.leave_class_type_declaration, { - ci_virt: cd$1.ci_virt, - ci_params: ci_params, - ci_id_name: cd$1.ci_id_name, - ci_id_class: cd$1.ci_id_class, - ci_id_class_type: cd$1.ci_id_class_type, - ci_id_object: cd$1.ci_id_object, - ci_id_typesharp: cd$1.ci_id_typesharp, - ci_expr: ci_expr, - ci_decl: cd$1.ci_decl, - ci_type_decl: cd$1.ci_type_decl, - ci_loc: cd$1.ci_loc, - ci_attributes: cd$1.ci_attributes - }); - }; - var map_class_declaration = function (cd) { - var cd$1 = Curry._1(funarg.enter_class_declaration, cd); - var ci_params = Stdlib__List.map(map_type_parameter, cd$1.ci_params); - var ci_expr = map_class_expr(cd$1.ci_expr); - return Curry._1(funarg.leave_class_declaration, { - ci_virt: cd$1.ci_virt, - ci_params: ci_params, - ci_id_name: cd$1.ci_id_name, - ci_id_class: cd$1.ci_id_class, - ci_id_class_type: cd$1.ci_id_class_type, - ci_id_object: cd$1.ci_id_object, - ci_id_typesharp: cd$1.ci_id_typesharp, - ci_expr: ci_expr, - ci_decl: cd$1.ci_decl, - ci_type_decl: cd$1.ci_type_decl, - ci_loc: cd$1.ci_loc, - ci_attributes: cd$1.ci_attributes - }); - }; - var map_value_description = function (v) { - var v$1 = Curry._1(funarg.enter_value_description, v); - var val_desc = map_core_type(v$1.val_desc); - return Curry._1(funarg.leave_value_description, { - val_id: v$1.val_id, - val_name: v$1.val_name, - val_desc: val_desc, - val_val: v$1.val_val, - val_prim: v$1.val_prim, - val_loc: v$1.val_loc, - val_attributes: v$1.val_attributes - }); - }; - var map_module_expr = function (mexpr) { - var mexpr$1 = Curry._1(funarg.enter_module_expr, mexpr); - var st = mexpr$1.mod_desc; - var mod_desc; - switch (st.TAG | 0) { - case /* Tmod_ident */0 : - mod_desc = mexpr$1.mod_desc; - break; - case /* Tmod_structure */1 : - mod_desc = { - TAG: /* Tmod_structure */1, - _0: map_structure(st._0) - }; - break; - case /* Tmod_functor */2 : - mod_desc = { - TAG: /* Tmod_functor */2, - _0: st._0, - _1: st._1, - _2: may_map(map_module_type, st._2), - _3: map_module_expr(st._3) - }; - break; - case /* Tmod_apply */3 : - mod_desc = { - TAG: /* Tmod_apply */3, - _0: map_module_expr(st._0), - _1: map_module_expr(st._1), - _2: st._2 - }; - break; - case /* Tmod_constraint */4 : - var mtype = st._2; - var mod_type = st._1; - var mexpr$2 = st._0; - mod_desc = mtype ? ({ - TAG: /* Tmod_constraint */4, - _0: map_module_expr(mexpr$2), - _1: mod_type, - _2: /* Tmodtype_explicit */{ - _0: map_module_type(mtype._0) - }, - _3: st._3 - }) : ({ - TAG: /* Tmod_constraint */4, - _0: map_module_expr(mexpr$2), - _1: mod_type, - _2: /* Tmodtype_implicit */0, - _3: st._3 - }); - break; - case /* Tmod_unpack */5 : - mod_desc = { - TAG: /* Tmod_unpack */5, - _0: map_expression(st._0), - _1: st._1 - }; - break; - - } - return Curry._1(funarg.leave_module_expr, { - mod_desc: mod_desc, - mod_loc: mexpr$1.mod_loc, - mod_type: mexpr$1.mod_type, - mod_env: mexpr$1.mod_env, - mod_attributes: mexpr$1.mod_attributes - }); - }; - var map_module_binding = function (x) { - return { - mb_id: x.mb_id, - mb_name: x.mb_name, - mb_expr: map_module_expr(x.mb_expr), - mb_attributes: x.mb_attributes, - mb_loc: x.mb_loc - }; - }; - var map_module_type_declaration = function (mtd) { - var mtd$1 = Curry._1(funarg.enter_module_type_declaration, mtd); - return Curry._1(funarg.leave_module_type_declaration, { - mtd_id: mtd$1.mtd_id, - mtd_name: mtd$1.mtd_name, - mtd_type: may_map(map_module_type, mtd$1.mtd_type), - mtd_attributes: mtd$1.mtd_attributes, - mtd_loc: mtd$1.mtd_loc - }); - }; - var map_type_extension = function (tyext) { - var tyext$1 = Curry._1(funarg.enter_type_extension, tyext); - var tyext_params = Stdlib__List.map(map_type_parameter, tyext$1.tyext_params); - var tyext_constructors = Stdlib__List.map(map_extension_constructor, tyext$1.tyext_constructors); - return Curry._1(funarg.leave_type_extension, { - tyext_path: tyext$1.tyext_path, - tyext_txt: tyext$1.tyext_txt, - tyext_params: tyext_params, - tyext_constructors: tyext_constructors, - tyext_private: tyext$1.tyext_private, - tyext_attributes: tyext$1.tyext_attributes - }); - }; - var map_type_declaration = function (decl) { - var decl$1 = Curry._1(funarg.enter_type_declaration, decl); - var typ_params = Stdlib__List.map(map_type_parameter, decl$1.typ_params); - var typ_cstrs = Stdlib__List.map((function (param) { - return [ - map_core_type(param[0]), - map_core_type(param[1]), - param[2] - ]; - }), decl$1.typ_cstrs); - var list = decl$1.typ_kind; - var typ_kind; - if (typeof list === "number") { - typ_kind = list === /* Ttype_abstract */0 ? /* Ttype_abstract */0 : /* Ttype_open */1; - } else if (list.TAG === /* Ttype_variant */0) { - var list$1 = Stdlib__List.map(map_constructor_declaration, list._0); - typ_kind = { - TAG: /* Ttype_variant */0, - _0: list$1 - }; - } else { - var list$2 = Stdlib__List.map((function (ld) { - return { - ld_id: ld.ld_id, - ld_name: ld.ld_name, - ld_mutable: ld.ld_mutable, - ld_type: map_core_type(ld.ld_type), - ld_loc: ld.ld_loc, - ld_attributes: ld.ld_attributes - }; - }), list._0); - typ_kind = { - TAG: /* Ttype_record */1, - _0: list$2 - }; - } - var typ_manifest = may_map(map_core_type, decl$1.typ_manifest); - return Curry._1(funarg.leave_type_declaration, { - typ_id: decl$1.typ_id, - typ_name: decl$1.typ_name, - typ_params: typ_params, - typ_type: decl$1.typ_type, - typ_cstrs: typ_cstrs, - typ_kind: typ_kind, - typ_private: decl$1.typ_private, - typ_manifest: typ_manifest, - typ_loc: decl$1.typ_loc, - typ_attributes: decl$1.typ_attributes - }); - }; var map_core_type = function (ct) { var ct$1 = Curry._1(funarg.enter_core_type, ct); var list = ct$1.ctyp_desc; @@ -26726,149 +26638,125 @@ function TypedtreeMap_MakeMap(funarg) { ctyp_attributes: ct$1.ctyp_attributes }); }; - var map_class_expr = function (cexpr) { - var cexpr$1 = Curry._1(funarg.enter_class_expr, cexpr); - var clstr = cexpr$1.cl_desc; - var cl_desc; - switch (clstr.TAG | 0) { - case /* Tcl_ident */0 : - cl_desc = { - TAG: /* Tcl_ident */0, - _0: clstr._0, - _1: clstr._1, - _2: Stdlib__List.map(map_core_type, clstr._2) + var map_structure_item = function (item) { + var item$1 = Curry._1(funarg.enter_structure_item, item); + var vd = item$1.str_desc; + var str_desc; + switch (vd.TAG | 0) { + case /* Tstr_eval */0 : + str_desc = { + TAG: /* Tstr_eval */0, + _0: map_expression(vd._0), + _1: vd._1 }; break; - case /* Tcl_structure */1 : - cl_desc = { - TAG: /* Tcl_structure */1, - _0: map_class_structure(clstr._0) + case /* Tstr_value */1 : + var rec_flag = vd._0; + str_desc = { + TAG: /* Tstr_value */1, + _0: rec_flag, + _1: Stdlib__List.map(map_binding, vd._1) }; break; - case /* Tcl_fun */2 : - cl_desc = { - TAG: /* Tcl_fun */2, - _0: clstr._0, - _1: map_pattern(clstr._1), - _2: Stdlib__List.map((function (param) { - return [ - param[0], - param[1], - map_expression(param[2]) - ]; - }), clstr._2), - _3: map_class_expr(clstr._3), - _4: clstr._4 + case /* Tstr_primitive */2 : + str_desc = { + TAG: /* Tstr_primitive */2, + _0: map_value_description(vd._0) }; break; - case /* Tcl_apply */3 : - cl_desc = { - TAG: /* Tcl_apply */3, - _0: map_class_expr(clstr._0), - _1: Stdlib__List.map((function (param) { - return [ - param[0], - may_map(map_expression, param[1]), - param[2] - ]; - }), clstr._1) + case /* Tstr_type */3 : + str_desc = { + TAG: /* Tstr_type */3, + _0: Stdlib__List.map(map_type_declaration, vd._0) }; break; - case /* Tcl_let */4 : - var rec_flat = clstr._0; - cl_desc = { - TAG: /* Tcl_let */4, - _0: rec_flat, - _1: Stdlib__List.map(map_binding, clstr._1), - _2: Stdlib__List.map((function (param) { - return [ - param[0], - param[1], - map_expression(param[2]) - ]; - }), clstr._2), - _3: map_class_expr(clstr._3) + case /* Tstr_typext */4 : + str_desc = { + TAG: /* Tstr_typext */4, + _0: map_type_extension(vd._0) }; break; - case /* Tcl_constraint */5 : - var clty = clstr._1; - var cl = clstr._0; - cl_desc = clty !== undefined ? ({ - TAG: /* Tcl_constraint */5, - _0: map_class_expr(cl), - _1: map_class_type(clty), - _2: clstr._2, - _3: clstr._3, - _4: clstr._4 - }) : ({ - TAG: /* Tcl_constraint */5, - _0: map_class_expr(cl), - _1: undefined, - _2: clstr._2, - _3: clstr._3, - _4: clstr._4 - }); + case /* Tstr_exception */5 : + str_desc = { + TAG: /* Tstr_exception */5, + _0: map_extension_constructor(vd._0) + }; break; - - } - return Curry._1(funarg.leave_class_expr, { - cl_desc: cl_desc, - cl_loc: cexpr$1.cl_loc, - cl_type: cexpr$1.cl_type, - cl_env: cexpr$1.cl_env, - cl_attributes: cexpr$1.cl_attributes - }); - }; - var map_class_type = function (ct) { - var ct$1 = Curry._1(funarg.enter_class_type, ct); - var csg = ct$1.cltyp_desc; - var cltyp_desc; - switch (csg.TAG | 0) { - case /* Tcty_constr */0 : - cltyp_desc = { - TAG: /* Tcty_constr */0, - _0: csg._0, - _1: csg._1, - _2: Stdlib__List.map(map_core_type, csg._2) + case /* Tstr_module */6 : + str_desc = { + TAG: /* Tstr_module */6, + _0: map_module_binding(vd._0) }; break; - case /* Tcty_signature */1 : - cltyp_desc = { - TAG: /* Tcty_signature */1, - _0: map_class_signature(csg._0) + case /* Tstr_recmodule */7 : + var list = Stdlib__List.map(map_module_binding, vd._0); + str_desc = { + TAG: /* Tstr_recmodule */7, + _0: list }; break; - case /* Tcty_arrow */2 : - cltyp_desc = { - TAG: /* Tcty_arrow */2, - _0: csg._0, - _1: map_core_type(csg._1), - _2: map_class_type(csg._2) + case /* Tstr_modtype */8 : + str_desc = { + TAG: /* Tstr_modtype */8, + _0: map_module_type_declaration(vd._0) + }; + break; + case /* Tstr_open */9 : + str_desc = { + TAG: /* Tstr_open */9, + _0: vd._0 + }; + break; + case /* Tstr_class */10 : + var list$1 = Stdlib__List.map((function (param) { + return [ + map_class_declaration(param[0]), + param[1], + param[2] + ]; + }), vd._0); + str_desc = { + TAG: /* Tstr_class */10, + _0: list$1 + }; + break; + case /* Tstr_class_type */11 : + var list$2 = Stdlib__List.map((function (param) { + return [ + param[0], + param[1], + map_class_type_declaration(param[2]) + ]; + }), vd._0); + str_desc = { + TAG: /* Tstr_class_type */11, + _0: list$2 + }; + break; + case /* Tstr_include */12 : + var incl = vd._0; + str_desc = { + TAG: /* Tstr_include */12, + _0: { + incl_mod: map_module_expr(incl.incl_mod), + incl_type: incl.incl_type, + incl_loc: incl.incl_loc, + incl_attributes: incl.incl_attributes + } + }; + break; + case /* Tstr_attribute */13 : + str_desc = { + TAG: /* Tstr_attribute */13, + _0: vd._0 }; break; } - return Curry._1(funarg.leave_class_type, { - cltyp_desc: cltyp_desc, - cltyp_type: ct$1.cltyp_type, - cltyp_env: ct$1.cltyp_env, - cltyp_loc: ct$1.cltyp_loc, - cltyp_attributes: ct$1.cltyp_attributes - }); - }; - var map_type_parameter = function (param) { - return [ - map_core_type(param[0]), - param[1] - ]; - }; - var map_signature = function (sg) { - var sg$1 = Curry._1(funarg.enter_signature, sg); - var sig_items = Stdlib__List.map(map_signature_item, sg$1.sig_items); - return Curry._1(funarg.leave_signature, { - sig_items: sig_items, - sig_type: sg$1.sig_type, - sig_final_env: sg$1.sig_final_env + return Curry._1(funarg.leave_structure_item, { + str_desc: str_desc, + str_loc: item$1.str_loc, + str_env: item$1.str_env }); }; var map_module_type = function (mty) { @@ -26948,15 +26836,119 @@ function TypedtreeMap_MakeMap(funarg) { } return Curry._1(funarg.leave_with_constraint, tmp); }; - var map_class_structure = function (cs) { - var cs$1 = Curry._1(funarg.enter_class_structure, cs); - var cstr_self = map_pattern(cs$1.cstr_self); - var cstr_fields = Stdlib__List.map(map_class_field, cs$1.cstr_fields); - return Curry._1(funarg.leave_class_structure, { - cstr_self: cstr_self, - cstr_fields: cstr_fields, - cstr_type: cs$1.cstr_type, - cstr_meths: cs$1.cstr_meths + var map_signature = function (sg) { + var sg$1 = Curry._1(funarg.enter_signature, sg); + var sig_items = Stdlib__List.map(map_signature_item, sg$1.sig_items); + return Curry._1(funarg.leave_signature, { + sig_items: sig_items, + sig_type: sg$1.sig_type, + sig_final_env: sg$1.sig_final_env + }); + }; + var map_case = function (param) { + return { + c_lhs: map_pattern(param.c_lhs), + c_guard: may_map(map_expression, param.c_guard), + c_rhs: map_expression(param.c_rhs) + }; + }; + var map_type_parameter = function (param) { + return [ + map_core_type(param[0]), + param[1] + ]; + }; + var map_class_type = function (ct) { + var ct$1 = Curry._1(funarg.enter_class_type, ct); + var csg = ct$1.cltyp_desc; + var cltyp_desc; + switch (csg.TAG | 0) { + case /* Tcty_constr */0 : + cltyp_desc = { + TAG: /* Tcty_constr */0, + _0: csg._0, + _1: csg._1, + _2: Stdlib__List.map(map_core_type, csg._2) + }; + break; + case /* Tcty_signature */1 : + cltyp_desc = { + TAG: /* Tcty_signature */1, + _0: map_class_signature(csg._0) + }; + break; + case /* Tcty_arrow */2 : + cltyp_desc = { + TAG: /* Tcty_arrow */2, + _0: csg._0, + _1: map_core_type(csg._1), + _2: map_class_type(csg._2) + }; + break; + + } + return Curry._1(funarg.leave_class_type, { + cltyp_desc: cltyp_desc, + cltyp_type: ct$1.cltyp_type, + cltyp_env: ct$1.cltyp_env, + cltyp_loc: ct$1.cltyp_loc, + cltyp_attributes: ct$1.cltyp_attributes + }); + }; + var map_class_type_field = function (ctf) { + var ctf$1 = Curry._1(funarg.enter_class_type_field, ctf); + var ct = ctf$1.ctf_desc; + var ctf_desc; + switch (ct.TAG | 0) { + case /* Tctf_inherit */0 : + ctf_desc = { + TAG: /* Tctf_inherit */0, + _0: map_class_type(ct._0) + }; + break; + case /* Tctf_val */1 : + var match = ct._0; + ctf_desc = { + TAG: /* Tctf_val */1, + _0: [ + match[0], + match[1], + match[2], + map_core_type(match[3]) + ] + }; + break; + case /* Tctf_method */2 : + var match$1 = ct._0; + ctf_desc = { + TAG: /* Tctf_method */2, + _0: [ + match$1[0], + match$1[1], + match$1[2], + map_core_type(match$1[3]) + ] + }; + break; + case /* Tctf_constraint */3 : + var match$2 = ct._0; + ctf_desc = { + TAG: /* Tctf_constraint */3, + _0: [ + map_core_type(match$2[0]), + map_core_type(match$2[1]) + ] + }; + break; + case /* Tctf_attribute */4 : + ctf_desc = ct; + break; + + } + return Curry._1(funarg.leave_class_type_field, { + ctf_desc: ctf_desc, + ctf_loc: ctf$1.ctf_loc, + ctf_attributes: ctf$1.ctf_attributes }); }; var map_signature_item = function (item) { @@ -27059,24 +27051,92 @@ function TypedtreeMap_MakeMap(funarg) { sig_loc: item$1.sig_loc }); }; - var map_constructor_declaration = function (cd) { - return { - cd_id: cd.cd_id, - cd_name: cd.cd_name, - cd_args: Stdlib__List.map(map_core_type, cd.cd_args), - cd_res: may_map(map_core_type, cd.cd_res), - cd_loc: cd.cd_loc, - cd_attributes: cd.cd_attributes - }; - }; - var map_class_signature = function (cs) { - var cs$1 = Curry._1(funarg.enter_class_signature, cs); - var csig_self = map_core_type(cs$1.csig_self); - var csig_fields = Stdlib__List.map(map_class_type_field, cs$1.csig_fields); - return Curry._1(funarg.leave_class_signature, { - csig_self: csig_self, - csig_fields: csig_fields, - csig_type: cs$1.csig_type + var map_pattern = function (pat) { + var pat$1 = Curry._1(funarg.enter_pattern, pat); + var list = pat$1.pat_desc; + var pat_desc; + if (typeof list === "number") { + pat_desc = pat$1.pat_desc; + } else { + switch (list.TAG | 0) { + case /* Tpat_alias */1 : + var pat1 = map_pattern(list._0); + pat_desc = { + TAG: /* Tpat_alias */1, + _0: pat1, + _1: list._1, + _2: list._2 + }; + break; + case /* Tpat_tuple */3 : + pat_desc = { + TAG: /* Tpat_tuple */3, + _0: Stdlib__List.map(map_pattern, list._0) + }; + break; + case /* Tpat_construct */4 : + pat_desc = { + TAG: /* Tpat_construct */4, + _0: list._0, + _1: list._1, + _2: Stdlib__List.map(map_pattern, list._2) + }; + break; + case /* Tpat_variant */5 : + var pato = list._1; + var pato$1 = pato !== undefined ? map_pattern(pato) : pato; + pat_desc = { + TAG: /* Tpat_variant */5, + _0: list._0, + _1: pato$1, + _2: list._2 + }; + break; + case /* Tpat_record */6 : + pat_desc = { + TAG: /* Tpat_record */6, + _0: Stdlib__List.map((function (param) { + return [ + param[0], + param[1], + map_pattern(param[2]) + ]; + }), list._0), + _1: list._1 + }; + break; + case /* Tpat_array */7 : + pat_desc = { + TAG: /* Tpat_array */7, + _0: Stdlib__List.map(map_pattern, list._0) + }; + break; + case /* Tpat_or */8 : + pat_desc = { + TAG: /* Tpat_or */8, + _0: map_pattern(list._0), + _1: map_pattern(list._1), + _2: list._2 + }; + break; + case /* Tpat_lazy */9 : + pat_desc = { + TAG: /* Tpat_lazy */9, + _0: map_pattern(list._0) + }; + break; + default: + pat_desc = pat$1.pat_desc; + } + } + var pat_extra = Stdlib__List.map(map_pat_extra, pat$1.pat_extra); + return Curry._1(funarg.leave_pattern, { + pat_desc: pat_desc, + pat_loc: pat$1.pat_loc, + pat_extra: pat_extra, + pat_type: pat$1.pat_type, + pat_env: pat$1.pat_env, + pat_attributes: pat$1.pat_attributes }); }; var map_class_field = function (cf) { @@ -27169,281 +27229,124 @@ function TypedtreeMap_MakeMap(funarg) { cf_attributes: cf$1.cf_attributes }); }; - var map_case = function (param) { + var map_constructor_declaration = function (cd) { return { - c_lhs: map_pattern(param.c_lhs), - c_guard: may_map(map_expression, param.c_guard), - c_rhs: map_expression(param.c_rhs) - }; - }; - var map_exp_extra = function (exp_extra) { - var attrs = exp_extra[2]; - var loc = exp_extra[1]; - var desc = exp_extra[0]; - switch (desc.TAG | 0) { - case /* Texp_constraint */0 : - return [ - { - TAG: /* Texp_constraint */0, - _0: map_core_type(desc._0) - }, - loc, - attrs - ]; - case /* Texp_coerce */1 : - var ct1 = desc._0; - if (ct1 !== undefined) { - return [ - { - TAG: /* Texp_coerce */1, - _0: map_core_type(ct1), - _1: map_core_type(desc._1) - }, - loc, - attrs - ]; - } else { - return [ - { - TAG: /* Texp_coerce */1, - _0: undefined, - _1: map_core_type(desc._1) - }, - loc, - attrs - ]; - } - case /* Texp_poly */3 : - var ct = desc._0; - if (ct !== undefined) { - return [ - { - TAG: /* Texp_poly */3, - _0: map_core_type(ct) - }, - loc, - attrs - ]; - } else { - return exp_extra; - } - case /* Texp_open */2 : - case /* Texp_newtype */4 : - return exp_extra; - - } - }; - var map_class_type_field = function (ctf) { - var ctf$1 = Curry._1(funarg.enter_class_type_field, ctf); - var ct = ctf$1.ctf_desc; - var ctf_desc; - switch (ct.TAG | 0) { - case /* Tctf_inherit */0 : - ctf_desc = { - TAG: /* Tctf_inherit */0, - _0: map_class_type(ct._0) - }; - break; - case /* Tctf_val */1 : - var match = ct._0; - ctf_desc = { - TAG: /* Tctf_val */1, - _0: [ - match[0], - match[1], - match[2], - map_core_type(match[3]) - ] - }; - break; - case /* Tctf_method */2 : - var match$1 = ct._0; - ctf_desc = { - TAG: /* Tctf_method */2, - _0: [ - match$1[0], - match$1[1], - match$1[2], - map_core_type(match$1[3]) - ] - }; - break; - case /* Tctf_constraint */3 : - var match$2 = ct._0; - ctf_desc = { - TAG: /* Tctf_constraint */3, - _0: [ - map_core_type(match$2[0]), - map_core_type(match$2[1]) - ] + cd_id: cd.cd_id, + cd_name: cd.cd_name, + cd_args: Stdlib__List.map(map_core_type, cd.cd_args), + cd_res: may_map(map_core_type, cd.cd_res), + cd_loc: cd.cd_loc, + cd_attributes: cd.cd_attributes }; - break; - case /* Tctf_attribute */4 : - ctf_desc = ct; - break; - - } - return Curry._1(funarg.leave_class_type_field, { - ctf_desc: ctf_desc, - ctf_loc: ctf$1.ctf_loc, - ctf_attributes: ctf$1.ctf_attributes - }); - }; - var map_class_description = function (cd) { - var cd$1 = Curry._1(funarg.enter_class_description, cd); - var ci_params = Stdlib__List.map(map_type_parameter, cd$1.ci_params); - var ci_expr = map_class_type(cd$1.ci_expr); - return Curry._1(funarg.leave_class_description, { - ci_virt: cd$1.ci_virt, - ci_params: ci_params, - ci_id_name: cd$1.ci_id_name, - ci_id_class: cd$1.ci_id_class, - ci_id_class_type: cd$1.ci_id_class_type, - ci_id_object: cd$1.ci_id_object, - ci_id_typesharp: cd$1.ci_id_typesharp, - ci_expr: ci_expr, - ci_decl: cd$1.ci_decl, - ci_type_decl: cd$1.ci_type_decl, - ci_loc: cd$1.ci_loc, - ci_attributes: cd$1.ci_attributes - }); - }; - var map_pat_extra = function (pat_extra) { - var ct = pat_extra[0]; - if (typeof ct === "number" || ct.TAG !== /* Tpat_constraint */0) { - return pat_extra; - } else { - return [ - { - TAG: /* Tpat_constraint */0, - _0: map_core_type(ct._0) - }, - pat_extra[1], - pat_extra[2] - ]; - } }; - var map_structure_item = function (item) { - var item$1 = Curry._1(funarg.enter_structure_item, item); - var vd = item$1.str_desc; - var str_desc; - switch (vd.TAG | 0) { - case /* Tstr_eval */0 : - str_desc = { - TAG: /* Tstr_eval */0, - _0: map_expression(vd._0), - _1: vd._1 - }; - break; - case /* Tstr_value */1 : - var rec_flag = vd._0; - str_desc = { - TAG: /* Tstr_value */1, - _0: rec_flag, - _1: Stdlib__List.map(map_binding, vd._1) - }; - break; - case /* Tstr_primitive */2 : - str_desc = { - TAG: /* Tstr_primitive */2, - _0: map_value_description(vd._0) - }; - break; - case /* Tstr_type */3 : - str_desc = { - TAG: /* Tstr_type */3, - _0: Stdlib__List.map(map_type_declaration, vd._0) - }; - break; - case /* Tstr_typext */4 : - str_desc = { - TAG: /* Tstr_typext */4, - _0: map_type_extension(vd._0) - }; - break; - case /* Tstr_exception */5 : - str_desc = { - TAG: /* Tstr_exception */5, - _0: map_extension_constructor(vd._0) - }; - break; - case /* Tstr_module */6 : - str_desc = { - TAG: /* Tstr_module */6, - _0: map_module_binding(vd._0) - }; - break; - case /* Tstr_recmodule */7 : - var list = Stdlib__List.map(map_module_binding, vd._0); - str_desc = { - TAG: /* Tstr_recmodule */7, - _0: list - }; - break; - case /* Tstr_modtype */8 : - str_desc = { - TAG: /* Tstr_modtype */8, - _0: map_module_type_declaration(vd._0) + var map_class_expr = function (cexpr) { + var cexpr$1 = Curry._1(funarg.enter_class_expr, cexpr); + var clstr = cexpr$1.cl_desc; + var cl_desc; + switch (clstr.TAG | 0) { + case /* Tcl_ident */0 : + cl_desc = { + TAG: /* Tcl_ident */0, + _0: clstr._0, + _1: clstr._1, + _2: Stdlib__List.map(map_core_type, clstr._2) }; break; - case /* Tstr_open */9 : - str_desc = { - TAG: /* Tstr_open */9, - _0: vd._0 + case /* Tcl_structure */1 : + cl_desc = { + TAG: /* Tcl_structure */1, + _0: map_class_structure(clstr._0) }; break; - case /* Tstr_class */10 : - var list$1 = Stdlib__List.map((function (param) { - return [ - map_class_declaration(param[0]), - param[1], - param[2] - ]; - }), vd._0); - str_desc = { - TAG: /* Tstr_class */10, - _0: list$1 + case /* Tcl_fun */2 : + cl_desc = { + TAG: /* Tcl_fun */2, + _0: clstr._0, + _1: map_pattern(clstr._1), + _2: Stdlib__List.map((function (param) { + return [ + param[0], + param[1], + map_expression(param[2]) + ]; + }), clstr._2), + _3: map_class_expr(clstr._3), + _4: clstr._4 }; break; - case /* Tstr_class_type */11 : - var list$2 = Stdlib__List.map((function (param) { - return [ - param[0], - param[1], - map_class_type_declaration(param[2]) - ]; - }), vd._0); - str_desc = { - TAG: /* Tstr_class_type */11, - _0: list$2 + case /* Tcl_apply */3 : + cl_desc = { + TAG: /* Tcl_apply */3, + _0: map_class_expr(clstr._0), + _1: Stdlib__List.map((function (param) { + return [ + param[0], + may_map(map_expression, param[1]), + param[2] + ]; + }), clstr._1) }; break; - case /* Tstr_include */12 : - var incl = vd._0; - str_desc = { - TAG: /* Tstr_include */12, - _0: { - incl_mod: map_module_expr(incl.incl_mod), - incl_type: incl.incl_type, - incl_loc: incl.incl_loc, - incl_attributes: incl.incl_attributes - } + case /* Tcl_let */4 : + var rec_flat = clstr._0; + cl_desc = { + TAG: /* Tcl_let */4, + _0: rec_flat, + _1: Stdlib__List.map(map_binding, clstr._1), + _2: Stdlib__List.map((function (param) { + return [ + param[0], + param[1], + map_expression(param[2]) + ]; + }), clstr._2), + _3: map_class_expr(clstr._3) }; break; - case /* Tstr_attribute */13 : - str_desc = { - TAG: /* Tstr_attribute */13, - _0: vd._0 - }; + case /* Tcl_constraint */5 : + var clty = clstr._1; + var cl = clstr._0; + cl_desc = clty !== undefined ? ({ + TAG: /* Tcl_constraint */5, + _0: map_class_expr(cl), + _1: map_class_type(clty), + _2: clstr._2, + _3: clstr._3, + _4: clstr._4 + }) : ({ + TAG: /* Tcl_constraint */5, + _0: map_class_expr(cl), + _1: undefined, + _2: clstr._2, + _3: clstr._3, + _4: clstr._4 + }); break; } - return Curry._1(funarg.leave_structure_item, { - str_desc: str_desc, - str_loc: item$1.str_loc, - str_env: item$1.str_env + return Curry._1(funarg.leave_class_expr, { + cl_desc: cl_desc, + cl_loc: cexpr$1.cl_loc, + cl_type: cexpr$1.cl_type, + cl_env: cexpr$1.cl_env, + cl_attributes: cexpr$1.cl_attributes }); }; + var map_pat_extra = function (pat_extra) { + var ct = pat_extra[0]; + if (typeof ct === "number" || ct.TAG !== /* Tpat_constraint */0) { + return pat_extra; + } else { + return [ + { + TAG: /* Tpat_constraint */0, + _0: map_core_type(ct._0) + }, + pat_extra[1], + pat_extra[2] + ]; + } + }; var map_package_type = function (pack) { var pack$1 = Curry._1(funarg.enter_package_type, pack); var pack_fields = Stdlib__List.map((function (param) { @@ -27475,6 +27378,103 @@ function TypedtreeMap_MakeMap(funarg) { }; } }; + var map_exp_extra = function (exp_extra) { + var attrs = exp_extra[2]; + var loc = exp_extra[1]; + var desc = exp_extra[0]; + switch (desc.TAG | 0) { + case /* Texp_constraint */0 : + return [ + { + TAG: /* Texp_constraint */0, + _0: map_core_type(desc._0) + }, + loc, + attrs + ]; + case /* Texp_coerce */1 : + var ct1 = desc._0; + if (ct1 !== undefined) { + return [ + { + TAG: /* Texp_coerce */1, + _0: map_core_type(ct1), + _1: map_core_type(desc._1) + }, + loc, + attrs + ]; + } else { + return [ + { + TAG: /* Texp_coerce */1, + _0: undefined, + _1: map_core_type(desc._1) + }, + loc, + attrs + ]; + } + case /* Texp_poly */3 : + var ct = desc._0; + if (ct !== undefined) { + return [ + { + TAG: /* Texp_poly */3, + _0: map_core_type(ct) + }, + loc, + attrs + ]; + } else { + return exp_extra; + } + case /* Texp_open */2 : + case /* Texp_newtype */4 : + return exp_extra; + + } + }; + var map_class_structure = function (cs) { + var cs$1 = Curry._1(funarg.enter_class_structure, cs); + var cstr_self = map_pattern(cs$1.cstr_self); + var cstr_fields = Stdlib__List.map(map_class_field, cs$1.cstr_fields); + return Curry._1(funarg.leave_class_structure, { + cstr_self: cstr_self, + cstr_fields: cstr_fields, + cstr_type: cs$1.cstr_type, + cstr_meths: cs$1.cstr_meths + }); + }; + var map_class_description = function (cd) { + var cd$1 = Curry._1(funarg.enter_class_description, cd); + var ci_params = Stdlib__List.map(map_type_parameter, cd$1.ci_params); + var ci_expr = map_class_type(cd$1.ci_expr); + return Curry._1(funarg.leave_class_description, { + ci_virt: cd$1.ci_virt, + ci_params: ci_params, + ci_id_name: cd$1.ci_id_name, + ci_id_class: cd$1.ci_id_class, + ci_id_class_type: cd$1.ci_id_class_type, + ci_id_object: cd$1.ci_id_object, + ci_id_typesharp: cd$1.ci_id_typesharp, + ci_expr: ci_expr, + ci_decl: cd$1.ci_decl, + ci_type_decl: cd$1.ci_type_decl, + ci_loc: cd$1.ci_loc, + ci_attributes: cd$1.ci_attributes + }); + }; + var map_class_signature = function (cs) { + var cs$1 = Curry._1(funarg.enter_class_signature, cs); + var csig_self = map_core_type(cs$1.csig_self); + var csig_fields = Stdlib__List.map(map_class_type_field, cs$1.csig_fields); + return Curry._1(funarg.leave_class_signature, { + csig_self: csig_self, + csig_fields: csig_fields, + csig_type: cs$1.csig_type + }); + }; return { map_structure: map_structure, map_pattern: map_pattern, @@ -33814,97 +33814,6 @@ function unify3(env, t1, t1$p, t2, t2$p) { } -function unify2(env, t1, t2) { - var expand_both = function (_t1$p$p, _t2$p$p) { - while(true) { - var t2$p$p = _t2$p$p; - var t1$p$p = _t1$p$p; - var t1$p = expand_head_unif(env.contents, t1); - var t2$p = expand_head_unif(env.contents, t2); - if (unify_eq(env.contents, t1$p, t1$p$p) && unify_eq(env.contents, t2$p, t2$p$p)) { - return [ - t1$p, - t2$p - ]; - } - _t2$p$p = t2$p; - _t1$p$p = t1$p; - continue ; - }; - }; - var match = expand_both(t1, t2); - var t2$p = match[1]; - var t1$p = match[0]; - var lv = t1$p.level < t2$p.level ? t1$p.level : t2$p.level; - update_level(env.contents, lv, t2); - update_level(env.contents, lv, t1); - if (unify_eq(env.contents, t1$p, t2$p)) { - return ; - } - var t1$1 = repr(t1); - var t2$1 = repr(t2); - if (trace_gadt_instances.contents) { - var ilevel = function (t) { - var lv = gadt_instance_level(env.contents, t); - if (lv !== undefined) { - return lv; - } else { - return 0; - } - }; - var lv1 = ilevel(t1$1); - var lv2 = ilevel(t2$1); - if (lv1 > lv2) { - add_gadt_instance_chain(env.contents, lv1, t2$1); - } else if (lv2 > lv1) { - add_gadt_instance_chain(env.contents, lv2, t1$1); - } - - } - var match$1; - if (principal.contents && (find_lowest_level(t1$p) < lv || find_lowest_level(t2$p) < lv)) { - var match$2 = t1$1.desc; - var tmp; - tmp = typeof match$2 === "number" || !(match$2.TAG === /* Tconstr */3 && !match$2._1) ? t1$1 : t1$p; - var match$3 = t2$1.desc; - var tmp$1; - tmp$1 = typeof match$3 === "number" || !(match$3.TAG === /* Tconstr */3 && !match$3._1) ? t2$1 : t2$p; - match$1 = [ - tmp, - tmp$1 - ]; - } else { - match$1 = [ - t1$1, - t2$1 - ]; - } - var t2$2 = match$1[1]; - var t1$2 = match$1[0]; - if (unify_eq(env.contents, t1$2, t1$p) || !unify_eq(env.contents, t2$2, t2$p)) { - return unify3(env, t1$2, t1$p, t2$2, t2$p); - } - try { - return unify3(env, t2$2, t2$p, t1$2, t1$p); - } - catch (raw_exn){ - var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.MEL_EXN_ID === Unify) { - throw { - MEL_EXN_ID: Unify, - _1: Stdlib__List.map((function (param) { - return [ - param[1], - param[0] - ]; - }), exn._1), - Error: new Error() - }; - } - throw exn; - } -} - function unify_list(env, tl1, tl2) { if (Stdlib__List.length(tl1) !== Stdlib__List.length(tl2)) { throw { @@ -34462,63 +34371,25 @@ function unify_fields(env, ty1, ty2) { MEL_EXN_ID: Unify, _1: { hd: [ - newty2(current_level.contents, desc), - newty2(current_level.contents, desc$1) - ], - tl: exn._1 - }, - Error: new Error() - }; - } - throw exn; - } - }), match$2[0]); - } - catch (exn){ - log_type(rest1); - rest1.desc = d1; - log_type(rest2); - rest2.desc = d2; - throw exn; - } -} - -function unify_kind(k1, k2) { - var k1$1 = field_kind_repr(k1); - var k2$1 = field_kind_repr(k2); - if (k1$1 === k2$1) { - return ; - } - if (typeof k1$1 === "number") { - if (!k1$1) { - if (typeof k2$1 !== "number") { - return set_kind(k2$1._0, k1$1); - } - if (!k2$1) { - return ; - } - - } - - } else { - var r = k1$1._0; - if (typeof k2$1 !== "number") { - return set_kind(r, k2$1); - } - if (!k2$1) { - return set_kind(r, k2$1); - } - + newty2(current_level.contents, desc), + newty2(current_level.contents, desc$1) + ], + tl: exn._1 + }, + Error: new Error() + }; + } + throw exn; + } + }), match$2[0]); + } + catch (exn){ + log_type(rest1); + rest1.desc = d1; + log_type(rest2); + rest2.desc = d2; + throw exn; } - throw { - MEL_EXN_ID: "Assert_failure", - _1: [ - "jscomp/test/ocaml_typedtree_test.ml", - 32636, - 37 - ], - Error: new Error() - }; } function make_rowvar(level, use1, rest1, use2, rest2) { @@ -34593,6 +34464,135 @@ function make_rowvar(level, use1, rest1, use2, rest2) { } } +function unify_kind(k1, k2) { + var k1$1 = field_kind_repr(k1); + var k2$1 = field_kind_repr(k2); + if (k1$1 === k2$1) { + return ; + } + if (typeof k1$1 === "number") { + if (!k1$1) { + if (typeof k2$1 !== "number") { + return set_kind(k2$1._0, k1$1); + } + if (!k2$1) { + return ; + } + + } + + } else { + var r = k1$1._0; + if (typeof k2$1 !== "number") { + return set_kind(r, k2$1); + } + if (!k2$1) { + return set_kind(r, k2$1); + } + + } + throw { + MEL_EXN_ID: "Assert_failure", + _1: [ + "jscomp/test/ocaml_typedtree_test.ml", + 32636, + 37 + ], + Error: new Error() + }; +} + +function unify2(env, t1, t2) { + var expand_both = function (_t1$p$p, _t2$p$p) { + while(true) { + var t2$p$p = _t2$p$p; + var t1$p$p = _t1$p$p; + var t1$p = expand_head_unif(env.contents, t1); + var t2$p = expand_head_unif(env.contents, t2); + if (unify_eq(env.contents, t1$p, t1$p$p) && unify_eq(env.contents, t2$p, t2$p$p)) { + return [ + t1$p, + t2$p + ]; + } + _t2$p$p = t2$p; + _t1$p$p = t1$p; + continue ; + }; + }; + var match = expand_both(t1, t2); + var t2$p = match[1]; + var t1$p = match[0]; + var lv = t1$p.level < t2$p.level ? t1$p.level : t2$p.level; + update_level(env.contents, lv, t2); + update_level(env.contents, lv, t1); + if (unify_eq(env.contents, t1$p, t2$p)) { + return ; + } + var t1$1 = repr(t1); + var t2$1 = repr(t2); + if (trace_gadt_instances.contents) { + var ilevel = function (t) { + var lv = gadt_instance_level(env.contents, t); + if (lv !== undefined) { + return lv; + } else { + return 0; + } + }; + var lv1 = ilevel(t1$1); + var lv2 = ilevel(t2$1); + if (lv1 > lv2) { + add_gadt_instance_chain(env.contents, lv1, t2$1); + } else if (lv2 > lv1) { + add_gadt_instance_chain(env.contents, lv2, t1$1); + } + + } + var match$1; + if (principal.contents && (find_lowest_level(t1$p) < lv || find_lowest_level(t2$p) < lv)) { + var match$2 = t1$1.desc; + var tmp; + tmp = typeof match$2 === "number" || !(match$2.TAG === /* Tconstr */3 && !match$2._1) ? t1$1 : t1$p; + var match$3 = t2$1.desc; + var tmp$1; + tmp$1 = typeof match$3 === "number" || !(match$3.TAG === /* Tconstr */3 && !match$3._1) ? t2$1 : t2$p; + match$1 = [ + tmp, + tmp$1 + ]; + } else { + match$1 = [ + t1$1, + t2$1 + ]; + } + var t2$2 = match$1[1]; + var t1$2 = match$1[0]; + if (unify_eq(env.contents, t1$2, t1$p) || !unify_eq(env.contents, t2$2, t2$p)) { + return unify3(env, t1$2, t1$p, t2$2, t2$p); + } + try { + return unify3(env, t2$2, t2$p, t1$2, t1$p); + } + catch (raw_exn){ + var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + if (exn.MEL_EXN_ID === Unify) { + throw { + MEL_EXN_ID: Unify, + _1: Stdlib__List.map((function (param) { + return [ + param[1], + param[0] + ]; + }), exn._1), + Error: new Error() + }; + } + throw exn; + } +} + function unify$1(env, ty1, ty2) { try { return unify(env, ty1, ty2); @@ -41634,22 +41634,127 @@ function print_out_functor(ppf, m) { } else { return Curry._2(Stdlib__Format.fprintf(ppf)(/* Format */{ _0: { - TAG: /* String_literal */11, - _0: "() ", + TAG: /* String_literal */11, + _0: "() ", + _1: { + TAG: /* Alpha */15, + _0: /* End_of_format */0 + } + }, + _1: "() %a" + }), print_out_functor, m._2); + } + } + Curry._2(Stdlib__Format.fprintf(ppf)(/* Format */{ + _0: { + TAG: /* String_literal */11, + _0: "->", + _1: { + TAG: /* Formatting_lit */17, + _0: { + TAG: /* Break */0, + _0: "@ ", + _1: 1, + _2: 0 + }, + _1: { + TAG: /* Alpha */15, + _0: /* End_of_format */0 + } + } + }, + _1: "->@ %a" + }), print_out_module_type, m); +} + +function print_out_signature(ppf, param) { + if (!param) { + return ; + } + var item = param.hd; + if (!param.tl) { + return Curry._2(out_sig_item.contents, ppf, item); + } + if (item.TAG === /* Osig_typext */2 && !item._1) { + var ext = item._0; + var gather_extensions = function (_acc, _items) { + while(true) { + var items = _items; + var acc = _acc; + if (!items) { + return [ + Stdlib__List.rev(acc), + items + ]; + } + var match = items.hd; + if (match.TAG !== /* Osig_typext */2) { + return [ + Stdlib__List.rev(acc), + items + ]; + } + if (match._1 !== 1) { + return [ + Stdlib__List.rev(acc), + items + ]; + } + var ext = match._0; + _items = items.tl; + _acc = { + hd: [ + ext.oext_name, + ext.oext_args, + ext.oext_ret_type + ], + tl: acc + }; + continue ; + }; + }; + var match = gather_extensions({ + hd: [ + ext.oext_name, + ext.oext_args, + ext.oext_ret_type + ], + tl: /* [] */0 + }, param.tl); + var te_otyext_name = ext.oext_type_name; + var te_otyext_params = ext.oext_type_params; + var te_otyext_constructors = match[0]; + var te_otyext_private = ext.oext_private; + var te = { + otyext_name: te_otyext_name, + otyext_params: te_otyext_params, + otyext_constructors: te_otyext_constructors, + otyext_private: te_otyext_private + }; + return Curry._4(Stdlib__Format.fprintf(ppf)(/* Format */{ + _0: { + TAG: /* Alpha */15, + _0: { + TAG: /* Formatting_lit */17, + _0: { + TAG: /* Break */0, + _0: "@ ", + _1: 1, + _2: 0 + }, _1: { TAG: /* Alpha */15, _0: /* End_of_format */0 } - }, - _1: "() %a" - }), print_out_functor, m._2); - } + } + }, + _1: "%a@ %a" + }), out_type_extension.contents, te, print_out_signature, match[1]); } - Curry._2(Stdlib__Format.fprintf(ppf)(/* Format */{ + Curry._4(Stdlib__Format.fprintf(ppf)(/* Format */{ _0: { - TAG: /* String_literal */11, - _0: "->", - _1: { + TAG: /* Alpha */15, + _0: { TAG: /* Formatting_lit */17, _0: { TAG: /* Break */0, @@ -41663,8 +41768,61 @@ function print_out_functor(ppf, m) { } } }, - _1: "->@ %a" - }), print_out_module_type, m); + _1: "%a@ %a" + }), out_sig_item.contents, item, print_out_signature, param.tl); +} + +function print_out_label(ppf, param) { + Curry._4(Stdlib__Format.fprintf(ppf)(/* Format */{ + _0: { + TAG: /* Formatting_gen */18, + _0: { + TAG: /* Open_box */1, + _0: /* Format */{ + _0: { + TAG: /* String_literal */11, + _0: "<2>", + _1: /* End_of_format */0 + }, + _1: "<2>" + } + }, + _1: { + TAG: /* String */2, + _0: /* No_padding */0, + _1: { + TAG: /* String */2, + _0: /* No_padding */0, + _1: { + TAG: /* String_literal */11, + _0: " :", + _1: { + TAG: /* Formatting_lit */17, + _0: { + TAG: /* Break */0, + _0: "@ ", + _1: 1, + _2: 0 + }, + _1: { + TAG: /* Alpha */15, + _0: { + TAG: /* Formatting_lit */17, + _0: /* Close_box */0, + _1: { + TAG: /* Char_literal */12, + _0: /* ';' */59, + _1: /* End_of_format */0 + } + } + } + } + } + } + } + }, + _1: "@[<2>%s%s :@ %a@];" + }), param[1] ? "mutable " : "", param[0], out_type.contents, param[2]); } function print_out_constr(ppf, param) { @@ -41818,59 +41976,6 @@ function print_out_constr(ppf, param) { } } -function print_out_label(ppf, param) { - Curry._4(Stdlib__Format.fprintf(ppf)(/* Format */{ - _0: { - TAG: /* Formatting_gen */18, - _0: { - TAG: /* Open_box */1, - _0: /* Format */{ - _0: { - TAG: /* String_literal */11, - _0: "<2>", - _1: /* End_of_format */0 - }, - _1: "<2>" - } - }, - _1: { - TAG: /* String */2, - _0: /* No_padding */0, - _1: { - TAG: /* String */2, - _0: /* No_padding */0, - _1: { - TAG: /* String_literal */11, - _0: " :", - _1: { - TAG: /* Formatting_lit */17, - _0: { - TAG: /* Break */0, - _0: "@ ", - _1: 1, - _2: 0 - }, - _1: { - TAG: /* Alpha */15, - _0: { - TAG: /* Formatting_lit */17, - _0: /* Close_box */0, - _1: { - TAG: /* Char_literal */12, - _0: /* ';' */59, - _1: /* End_of_format */0 - } - } - } - } - } - } - } - }, - _1: "@[<2>%s%s :@ %a@];" - }), param[1] ? "mutable " : "", param[0], out_type.contents, param[2]); -} - function print_out_module_type(ppf, t) { if (typeof t === "number") { return ; @@ -41995,111 +42100,6 @@ function print_out_module_type(ppf, t) { } } -function print_out_signature(ppf, param) { - if (!param) { - return ; - } - var item = param.hd; - if (!param.tl) { - return Curry._2(out_sig_item.contents, ppf, item); - } - if (item.TAG === /* Osig_typext */2 && !item._1) { - var ext = item._0; - var gather_extensions = function (_acc, _items) { - while(true) { - var items = _items; - var acc = _acc; - if (!items) { - return [ - Stdlib__List.rev(acc), - items - ]; - } - var match = items.hd; - if (match.TAG !== /* Osig_typext */2) { - return [ - Stdlib__List.rev(acc), - items - ]; - } - if (match._1 !== 1) { - return [ - Stdlib__List.rev(acc), - items - ]; - } - var ext = match._0; - _items = items.tl; - _acc = { - hd: [ - ext.oext_name, - ext.oext_args, - ext.oext_ret_type - ], - tl: acc - }; - continue ; - }; - }; - var match = gather_extensions({ - hd: [ - ext.oext_name, - ext.oext_args, - ext.oext_ret_type - ], - tl: /* [] */0 - }, param.tl); - var te_otyext_name = ext.oext_type_name; - var te_otyext_params = ext.oext_type_params; - var te_otyext_constructors = match[0]; - var te_otyext_private = ext.oext_private; - var te = { - otyext_name: te_otyext_name, - otyext_params: te_otyext_params, - otyext_constructors: te_otyext_constructors, - otyext_private: te_otyext_private - }; - return Curry._4(Stdlib__Format.fprintf(ppf)(/* Format */{ - _0: { - TAG: /* Alpha */15, - _0: { - TAG: /* Formatting_lit */17, - _0: { - TAG: /* Break */0, - _0: "@ ", - _1: 1, - _2: 0 - }, - _1: { - TAG: /* Alpha */15, - _0: /* End_of_format */0 - } - } - }, - _1: "%a@ %a" - }), out_type_extension.contents, te, print_out_signature, match[1]); - } - Curry._4(Stdlib__Format.fprintf(ppf)(/* Format */{ - _0: { - TAG: /* Alpha */15, - _0: { - TAG: /* Formatting_lit */17, - _0: { - TAG: /* Break */0, - _0: "@ ", - _1: 1, - _2: 0 - }, - _1: { - TAG: /* Alpha */15, - _0: /* End_of_format */0 - } - } - }, - _1: "%a@ %a" - }), out_sig_item.contents, item, print_out_signature, param.tl); -} - function print_out_sig_item(ppf, param) { switch (param.TAG | 0) { case /* Osig_class */0 : @@ -46547,6 +46547,14 @@ function filter_params(tyl) { }), /* [] */0, tyl)); } +function tree_of_label(l) { + return [ + l.ld_id.name, + l.ld_mutable === /* Mutable */1, + tree_of_typexp(false, l.ld_type) + ]; +} + function tree_of_constructor(cd) { var name = cd.cd_id.name; var res = cd.cd_res; @@ -46573,14 +46581,6 @@ function tree_of_constructor(cd) { ]; } -function tree_of_label(l) { - return [ - l.ld_id.name, - l.ld_mutable === /* Mutable */1, - tree_of_typexp(false, l.ld_type) - ]; -} - function tree_of_type_decl(id, decl) { reset(undefined); var params = filter_params(decl.type_params); diff --git a/jscomp/test/ffi_array_test.ml b/jscomp/test/ffi_array_test.ml index 58bb10fa2a..c1da49b0bb 100644 --- a/jscomp/test/ffi_array_test.ml +++ b/jscomp/test/ffi_array_test.ml @@ -6,7 +6,7 @@ let eq loc x y = (loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites -external map : 'a Js.Array2.t -> ('a -> 'b [@u]) -> 'b Js.Array2.t = "map" [@@mel.send] +external map : 'a Js.Array.t -> ('a -> 'b [@u]) -> 'b Js.Array.t = "map" [@@mel.send] let () = eq __LOC__ diff --git a/jscomp/test/ffi_js_test.ml b/jscomp/test/ffi_js_test.ml index 3df36be505..42e039f156 100644 --- a/jscomp/test/ffi_js_test.ml +++ b/jscomp/test/ffi_js_test.ml @@ -43,8 +43,8 @@ let v_obj = object method hi__x () = Js.log "hei" end [@u] let () = eq __LOC__ (Array.length (Js.Obj.keys int_config), 2 ); eq __LOC__ (Array.length (Js.Obj.keys string_config), 2 ); - eq __LOC__ (Js.Obj.keys v_obj |. Js.Array2.indexOf "hi_x" , -1 ); - eq __LOC__ (Js.Obj.keys v_obj |. Js.Array2.indexOf "hi", 0 ) + eq __LOC__ (Js.Obj.keys v_obj |. Js.Array.indexOf ~value:"hi_x" (), -1 ); + eq __LOC__ (Js.Obj.keys v_obj |. Js.Array.indexOf ~value:"hi" (), 0 ) let u = ref 3 diff --git a/jscomp/test/js_array_test.ml b/jscomp/test/js_array_test.ml index f4c248a070..cd2bd3af89 100644 --- a/jscomp/test/js_array_test.ml +++ b/jscomp/test/js_array_test.ml @@ -5,7 +5,7 @@ let suites = Mt.[ "from", (fun _ -> Eq( [| 0; 1 |], - [| "a"; "b" |] |. Js.Array2.keys |. Js.Array2.from) + [| "a"; "b" |] |. Js.Array.keys |. Js.Array.from) ); *) @@ -13,225 +13,225 @@ let suites = Mt.[ "fromMap", (fun _ -> Eq( [| (-1); 0 |], - Js.Array2.fromMap - ([| "a"; "b" |] |. Js.Array2.keys) + Js.Array.fromMap + ([| "a"; "b" |] |. Js.Array.keys) ((fun x -> x - 1) [@u])) ); *) (* es2015 *) "isArray_array", (fun _ -> - Eq(true, [||] |. Js.Array2.isArray) + Eq(true, [||] |. Js.Array.isArray) ); "isArray_int", (fun _ -> - Eq(false, 34 |. Js.Array2.isArray) + Eq(false, 34 |. Js.Array.isArray) ); "length", (fun _ -> - Eq(3, [| 1; 2; 3 |] |. Js.Array2.length) + Eq(3, [| 1; 2; 3 |] |. Js.Array.length) ); (* es2015 *) "copyWithin", (fun _ -> Eq([| 1; 2; 3; 1; 2 |], - [| 1; 2; 3; 4; 5 |] |. Js.Array2.copyWithin ~to_:(-2)) + [| 1; 2; 3; 4; 5 |] |. Js.Array.copyWithin ~to_:(-2) ()) ); "copyWithinFrom", (fun _ -> Eq([| 4; 5; 3; 4; 5 |], - [| 1; 2; 3; 4; 5 |] |. Js.Array2.copyWithinFrom ~to_:0 ~from:3) + [| 1; 2; 3; 4; 5 |] |. Js.Array.copyWithin ~to_:0 ~start:3 ()) ); "copyWithinFromRange", (fun _ -> Eq([| 4; 2; 3; 4; 5 |], - [| 1; 2; 3; 4; 5 |] |. Js.Array2.copyWithinFromRange ~to_:0 ~start:3 ~end_:4) + [| 1; 2; 3; 4; 5 |] |. Js.Array.copyWithin ~to_:0 ~start:3 ~end_:4 ()) ); (* es2015 *) "fillInPlace", (fun _ -> Eq([| 4; 4; 4 |], - [| 1; 2; 3 |] |. Js.Array2.fillInPlace 4) + [| 1; 2; 3 |] |. Js.Array.fill ~value:4 ()) ); "fillFromInPlace", (fun _ -> Eq([| 1; 4; 4 |], - [| 1; 2; 3 |] |. Js.Array2.fillFromInPlace 4 ~from:1) + [| 1; 2; 3 |] |. Js.Array.fill ~value:4 ~start:1 ()) ); "fillRangeInPlace", (fun _ -> Eq([| 1; 4; 3 |], - [| 1; 2; 3 |] |. Js.Array2.fillRangeInPlace 4 ~start:1 ~end_:2) + [| 1; 2; 3 |] |. Js.Array.fill ~value:4 ~start:1 ~end_:2 ()) ); "pop", (fun _ -> - Eq(Some 3, [| 1; 2; 3 |] |. Js.Array2.pop) + Eq(Some 3, [| 1; 2; 3 |] |. Js.Array.pop) ); "pop - empty array", (fun _ -> - Eq(None, [||] |. Js.Array2.pop) + Eq(None, [||] |. Js.Array.pop) ); "push", (fun _ -> - Eq(4, [| 1; 2; 3 |] |. Js.Array2.push 4) + Eq(4, [| 1; 2; 3 |] |. Js.Array.push ~value:4) ); "pushMany", (fun _ -> - Eq(5, [| 1; 2; 3 |] |. Js.Array2.pushMany [| 4; 5 |]) + Eq(5, [| 1; 2; 3 |] |. Js.Array.pushMany ~values:[| 4; 5 |]) ); "reverseInPlace", (fun _ -> Eq([| 3; 2; 1 |], - [| 1; 2; 3 |] |. Js.Array2.reverseInPlace) + [| 1; 2; 3 |] |. Js.Array.reverseInPlace) ); "shift", (fun _ -> - Eq(Some 1, [| 1; 2; 3 |] |. Js.Array2.shift) + Eq(Some 1, [| 1; 2; 3 |] |. Js.Array.shift) ); "shift - empty array", (fun _ -> - Eq(None, [||] |. Js.Array2.shift) + Eq(None, [||] |. Js.Array.shift) ); "sortInPlace", (fun _ -> Eq([| 1; 2; 3 |], - [| 3; 1; 2 |] |. Js.Array2.sortInPlace) + [| 3; 1; 2 |] |. Js.Array.sortInPlace) ); "sortInPlaceWith", (fun _ -> Eq([| 3; 2; 1 |], - [| 3; 1; 2 |] |. Js.Array2.sortInPlaceWith ((fun a b -> b - a) )) + [| 3; 1; 2 |] |. Js.Array.sortInPlaceWith ~f:((fun a b -> b - a) )) ); "spliceInPlace", (fun _ -> let arr = [| 1; 2; 3; 4 |] in - let removed = arr |. Js.Array2.spliceInPlace ~pos:2 ~remove:0 ~add:[| 5 |] in + let removed = arr |. Js.Array.spliceInPlace ~pos:2 ~remove:0 ~add:[| 5 |] in Eq(([| 1; 2; 5; 3; 4 |], [||]), (arr, removed)) ); "removeFromInPlace", (fun _ -> let arr = [| 1; 2; 3; 4 |] in - let removed = arr |. Js.Array2.removeFromInPlace ~pos:2 in + let removed = arr |. Js.Array.removeFromInPlace ~pos:2 in Eq(([| 1; 2 |], [| 3; 4 |]), (arr, removed)) ); "removeCountInPlace", (fun _ -> let arr = [| 1; 2; 3; 4 |] in - let removed = arr |. Js.Array2.removeCountInPlace ~pos:2 ~count:1 in + let removed = arr |. Js.Array.removeCountInPlace ~pos:2 ~count:1 in Eq(([| 1; 2; 4 |], [| 3 |]), (arr, removed)) ); "unshift", (fun _ -> - Eq(4, [| 1; 2; 3 |] |. Js.Array2.unshift 4) + Eq(4, [| 1; 2; 3 |] |. Js.Array.unshift ~value:4) ); "unshiftMany", (fun _ -> - Eq(5, [| 1; 2; 3 |] |. Js.Array2.unshiftMany [| 4; 5 |]) + Eq(5, [| 1; 2; 3 |] |. Js.Array.unshiftMany ~values:[| 4; 5 |]) ); "append", (fun _ -> Eq([| 1; 2; 3; 4 |], - [| 1; 2; 3 |] |. Js.Array2.concat [|4|]) + [| 1; 2; 3 |] |. Js.Array.concat ~other:[|4|]) ); "concat", (fun _ -> Eq([| 1; 2; 3; 4; 5 |], - [| 1; 2; 3 |] |. Js.Array2.concat [| 4; 5 |]) + [| 1; 2; 3 |] |. Js.Array.concat ~other:[| 4; 5 |]) ); "concatMany", (fun _ -> Eq([| 1; 2; 3; 4; 5; 6; 7 |], - [| 1; 2; 3 |] |. Js.Array2.concatMany [| [| 4; 5; |]; [| 6; 7; |] |]) + [| 1; 2; 3 |] |. Js.Array.concatMany ~arrays:[| [| 4; 5; |]; [| 6; 7; |] |]) ); (* es2016 *) "includes", (fun _ -> - Eq(true, [| 1; 2; 3 |] |. Js.Array2.includes 3) + Eq(true, [| 1; 2; 3 |] |. Js.Array.includes ~value:3) ); "indexOf", (fun _ -> - Eq(1, [| 1; 2; 3 |] |. Js.Array2.indexOf 2) + Eq(1, [| 1; 2; 3 |] |. Js.Array.indexOf ~value:2 ()) ); "indexOfFrom", (fun _ -> - Eq(3, [| 1; 2; 3; 2 |] |. Js.Array2.indexOfFrom 2 ~from:2) + Eq(3, [| 1; 2; 3; 2 |] |. Js.Array.indexOf ~value:2 ~start:2 ()) ); "join", (fun _ -> - Eq("1,2,3", [| 1; 2; 3 |] |. Js.Array.join) + Eq("1,2,3", [| 1; 2; 3 |] |. Js.Array.join ~sep:",") ); "joinWith", (fun _ -> - Eq("1;2;3", [| 1; 2; 3 |] |. Js.Array2.joinWith ";") + Eq("1;2;3", [| 1; 2; 3 |] |. Js.Array.join ~sep:";") ); "lastIndexOf", (fun _ -> - Eq(1, [| 1; 2; 3 |] |. Js.Array2.lastIndexOf 2) + Eq(1, [| 1; 2; 3 |] |. Js.Array.lastIndexOf ~value:2 ) ); "lastIndexOfFrom", (fun _ -> - Eq(1, [| 1; 2; 3; 2 |] |. Js.Array2.lastIndexOfFrom 2 ~from:2) + Eq(1, [| 1; 2; 3; 2 |] |. Js.Array.lastIndexOfFrom ~value:2 ~start:2 ) ); "slice", (fun _ -> Eq([| 2; 3; |], - [| 1; 2; 3; 4; 5 |] |. Js.Array2.slice ~start:1 ~end_:3) + [| 1; 2; 3; 4; 5 |] |. Js.Array.slice ~start:1 ~end_:3 ()) ); "copy", (fun _ -> Eq([| 1; 2; 3; 4; 5 |], - [| 1; 2; 3; 4; 5 |] |. Js.Array2.copy) + [| 1; 2; 3; 4; 5 |] |. Js.Array.copy) ); "sliceFrom", (fun _ -> Eq([| 3; 4; 5 |], - [| 1; 2; 3; 4; 5 |] |. Js.Array2.sliceFrom 2) + [| 1; 2; 3; 4; 5 |] |. Js.Array.slice ~start:2 ()) ); "toString", (fun _ -> - Eq("1,2,3", [| 1; 2; 3 |] |. Js.Array2.toString) + Eq("1,2,3", [| 1; 2; 3 |] |. Js.Array.toString) ); "toLocaleString", (fun _ -> - Eq("1,2,3", [| 1; 2; 3 |] |. Js.Array2.toLocaleString) + Eq("1,2,3", [| 1; 2; 3 |] |. Js.Array.toLocaleString) ); (* es2015, iterator "entries", (fun _ -> Eq([| (0, "a"); (1, "b"); (2, "c") |], - [| "a"; "b"; "c" |] |. Js.Array2.entries |. Js.Array2.from) + [| "a"; "b"; "c" |] |. Js.Array.entries |. Js.Array.from) ); *) "every", (fun _ -> - Eq(true, [| 1; 2; 3 |] |. Js.Array2.every ((fun n -> (n > 0)) )) + Eq(true, [| 1; 2; 3 |] |. Js.Array.every ~f:((fun n -> (n > 0)) )) ); "everyi", (fun _ -> - Eq(false, [| 1; 2; 3 |] |. Js.Array2.everyi ((fun _ i -> (i > 0)) )) + Eq(false, [| 1; 2; 3 |] |. Js.Array.everyi ~f:((fun _ i -> (i > 0)) )) ); "filter", (fun _ -> Eq([| 2; 4 |], - [| 1; 2; 3; 4 |] |. Js.Array2.filter ((fun n -> n mod 2 = 0) )) + [| 1; 2; 3; 4 |] |. Js.Array.filter ~f:((fun n -> n mod 2 = 0) )) ); "filteri", (fun _ -> Eq([| 1; 3 |], - [| 1; 2; 3; 4 |] |. Js.Array2.filteri ((fun _ i -> (i mod 2 = 0)) )) + [| 1; 2; 3; 4 |] |. Js.Array.filteri ~f:((fun _ i -> (i mod 2 = 0)) )) ); (* es2015 *) "find", (fun _ -> - Eq(Some 2, [| 1; 2; 3; 4 |] |. Js.Array2.find ((fun n -> n mod 2 = 0) )) + Eq(Some 2, [| 1; 2; 3; 4 |] |. Js.Array.find ~f:((fun n -> n mod 2 = 0) )) ); "find - no match", (fun _ -> - Eq(None, [| 1; 2; 3; 4 |] |. Js.Array2.find ((fun n -> n mod 2 = 5) )) + Eq(None, [| 1; 2; 3; 4 |] |. Js.Array.find ~f:((fun n -> n mod 2 = 5) )) ); "findi", (fun _ -> - Eq(Some 1, [| 1; 2; 3; 4 |] |. Js.Array2.findi ((fun _ i -> i mod 2 = 0) )) + Eq(Some 1, [| 1; 2; 3; 4 |] |. Js.Array.findi ~f:((fun _ i -> i mod 2 = 0) )) ); "findi - no match", (fun _ -> - Eq(None, [| 1; 2; 3; 4 |] |. Js.Array2.findi ((fun _ i -> i mod 2 = 5) )) + Eq(None, [| 1; 2; 3; 4 |] |. Js.Array.findi ~f:((fun _ i -> i mod 2 = 5) )) ); (* es2015 *) "findIndex", (fun _ -> - Eq(1, [| 1; 2; 3; 4 |] |. Js.Array2.findIndex ((fun n -> n mod 2 = 0) )) + Eq(1, [| 1; 2; 3; 4 |] |. Js.Array.findIndex ~f:((fun n -> n mod 2 = 0) )) ); "findIndexi", (fun _ -> - Eq(0, [| 1; 2; 3; 4 |] |. Js.Array2.findIndexi ((fun _ i -> i mod 2 = 0) )) + Eq(0, [| 1; 2; 3; 4 |] |. Js.Array.findIndexi ~f:((fun _ i -> i mod 2 = 0) )) ); "forEach", (fun _ -> let sum = ref 0 in - let _ = [| 1; 2; 3; |] |. Js.Array2.forEach ((fun n -> sum := !sum + n) ) in + let _ = [| 1; 2; 3; |] |. Js.Array.forEach ~f:((fun n -> sum := !sum + n) ) in Eq(6, !sum) ); "forEachi", (fun _ -> let sum = ref 0 in - let _ = [| 1; 2; 3; |] |. Js.Array2.forEachi ((fun _ i -> sum := !sum + i) ) in + let _ = [| 1; 2; 3; |] |. Js.Array.forEachi ~f:((fun _ i -> sum := !sum + i) ) in Eq(3, !sum) ); @@ -239,46 +239,46 @@ let suites = Mt.[ (* es2015, iterator "keys", (fun _ -> Eq([| 0; 1; 2 |], - [| "a"; "b"; "c" |] |. Js.Array2.keys |. Js.Array2.from) + [| "a"; "b"; "c" |] |. Js.Array.keys |. Js.Array.from) ); *) "map", (fun _ -> Eq([| 2; 4; 6; 8 |], - [| 1; 2; 3; 4 |] |. Js.Array2.map ((fun n -> n * 2) )) + [| 1; 2; 3; 4 |] |. Js.Array.map ~f:((fun n -> n * 2) )) ); "map", (fun _ -> Eq([| 0; 2; 4; 6 |], - [| 1; 2; 3; 4 |] |. Js.Array2.mapi ((fun _ i -> i * 2) )) + [| 1; 2; 3; 4 |] |. Js.Array.mapi ~f:((fun _ i -> i * 2) )) ); "reduce", (fun _ -> Eq(-10, - [| 1; 2; 3; 4 |] |. Js.Array2.reduce ((fun acc n -> acc - n) ) 0) + [| 1; 2; 3; 4 |] |. Js.Array.reduce ~f:((fun acc n -> acc - n) ) ~init:0) ); "reducei", (fun _ -> Eq(-6, - [| 1; 2; 3; 4 |] |. Js.Array2.reducei ((fun acc _ i -> acc - i) ) 0) + [| 1; 2; 3; 4 |] |. Js.Array.reducei ~f:((fun acc _ i -> acc - i) ) ~init:0) ); "reduceRight", (fun _ -> - Eq(-10, [| 1; 2; 3; 4 |] |. Js.Array2.reduceRight ((fun acc n -> acc - n) ) 0) + Eq(-10, [| 1; 2; 3; 4 |] |. Js.Array.reduceRight ~f:((fun acc n -> acc - n) ) ~init:0) ); "reduceRighti", (fun _ -> - Eq(-6, [| 1; 2; 3; 4 |] |. Js.Array2.reduceRighti ((fun acc _ i -> acc - i) ) 0) + Eq(-6, [| 1; 2; 3; 4 |] |. Js.Array.reduceRighti ~f:((fun acc _ i -> acc - i) ) ~init:0) ); "some", (fun _ -> - Eq(false, [| 1; 2; 3; 4 |] |. Js.Array2.some ((fun n -> (n <= 0)) )) + Eq(false, [| 1; 2; 3; 4 |] |. Js.Array.some ~f:((fun n -> (n <= 0)) )) ); "somei", (fun _ -> - Eq(true, [| 1; 2; 3; 4 |] |. Js.Array2.somei ((fun _ i -> (i <= 0)) )) + Eq(true, [| 1; 2; 3; 4 |] |. Js.Array.somei ~f:((fun _ i -> (i <= 0)) )) ); (* es2015, iterator "values", (fun _ -> Eq([| "a"; "b"; "c" |], - [| "a"; "b"; "c" |] |. Js.Array2.values |. Js.Array2.from) + [| "a"; "b"; "c" |] |. Js.Array.values |. Js.Array.from) ); *) ] diff --git a/jscomp/test/js_json_test.ml b/jscomp/test/js_json_test.ml index 8f92d42596..f0d12119d7 100644 --- a/jscomp/test/js_json_test.ml +++ b/jscomp/test/js_json_test.ml @@ -31,7 +31,7 @@ let () = begin match ty2 with | J.JSONArray x -> (* compiler infer x : J.t array *) x - |. Js.Array2.forEach (fun x -> + |. Js.Array.forEach ~f:(fun x -> let ty3 = J.classify x in match ty3 with | J.JSONNumber _ -> () diff --git a/jscomp/test/key_word_property_plus_test.ml b/jscomp/test/key_word_property_plus_test.ml index 79e9abdf83..46d1ff165b 100644 --- a/jscomp/test/key_word_property_plus_test.ml +++ b/jscomp/test/key_word_property_plus_test.ml @@ -8,7 +8,7 @@ let eq loc x y = let () = eq __LOC__ - (Js.Array2.reduce [|1;2;3;4;5;6;7;8;9;10;11;12;13;14|] (+) 0 ) + (Js.Array.reduce [|1;2;3;4;5;6;7;8;9;10;11;12;13;14|] ~f:(+) ~init:0 ) (Global_mangles.( __dirname + __filename + diff --git a/jscomp/test/ppx_this_obj_field.ml b/jscomp/test/ppx_this_obj_field.ml index 0647965ae6..e173666620 100644 --- a/jscomp/test/ppx_this_obj_field.ml +++ b/jscomp/test/ppx_this_obj_field.ml @@ -75,7 +75,7 @@ let eventObj : < object (self) val events : (string * string) array = [||] method empty () = Js.Array.removeFromInPlace (self##events) ~pos:0 |. ignore - method push a = (Js.Array.push a (self##events) |. ignore : unit ) + method push a = (Js.Array.push (self##events) ~value:a |. ignore : unit ) method needRebuild () = Array.length self##events <> 0 (* method currentEvents () = self##events *) end [@u] diff --git a/jscomp/test/re_or_res/reactDOMRe.re b/jscomp/test/re_or_res/reactDOMRe.re index fb20b6f543..5b2be467e5 100644 --- a/jscomp/test/re_or_res/reactDOMRe.re +++ b/jscomp/test/re_or_res/reactDOMRe.re @@ -4,14 +4,13 @@ that takes in a reactElement, a dom element, and returns unit (nothing) */ /* It's like `let`, except you're pointing the implementation to the JS side. The compiler will inline these calls and add the appropriate `require("react-dom")` in the file calling this `render` */ - [@mel.module "react-dom"] +[@mel.module "react-dom"] external render: (React.element, Dom.element) => unit = "render"; - external _getElementsByClassName: string => array(Dom.element) = "document.getElementsByClassName"; - [@mel.return nullable] +[@mel.return nullable] external _getElementById: string => option(Dom.element) = "document.getElementById"; @@ -68,7 +67,7 @@ module Experimental = { }; }; - [@mel.module "react-dom"] +[@mel.module "react-dom"] external hydrate: (React.element, Dom.element) => unit = "hydrate"; let hydrateToElementWithClassName = (reactElement, className) => @@ -95,15 +94,15 @@ let hydrateToElementWithId = (reactElement, id) => | Some(element) => hydrate(reactElement, element) }; - [@mel.module "react-dom"] +[@mel.module "react-dom"] external createPortal: (React.element, Dom.element) => React.element = "createPortal"; - [@mel.module "react-dom"] +[@mel.module "react-dom"] external unmountComponentAtNode: Dom.element => unit = "unmountComponentAtNode"; - [@mel.module "react-dom"] +[@mel.module "react-dom"] external findDOMNode: ReasonReact.reactRef => Dom.element = "findDOMNode"; external domElementToObj: Dom.element => Js.t({..}) = "%identity"; @@ -2133,7 +2132,7 @@ external objToDOMProps: Js.t({..}) => props = "%identity"; [@deprecated "Please use ReactDOMRe.props instead"] type reactDOMProps = props; -[@mel.splice] [@mel.module "react"] +[@mel.splice] [@mel.module "react"] external createElement: (string, ~props: props=?, array(React.element)) => React.element = "createElement"; @@ -2142,7 +2141,7 @@ external createElement: include ( /* Use varargs to avoid the ReactJS warning for duplicate keys in children */ { - [@mel.module "react"] + [@mel.module "react"] external createElementInternalHack: 'a = "createElement"; [@mel.send] external apply: @@ -2153,7 +2152,7 @@ include ( let createElementVariadic = (domClassName, ~props=?, children) => { let variadicArguments = [|Obj.magic(domClassName), Obj.magic(props)|] - |> Js.Array.concat(children); + |> Js.Array.concat(~other=children); createElementInternalHack->( apply( Js.Nullable.null, @@ -2602,7 +2601,6 @@ module Style = { combine(style, _dictToStyle(dict)); }; - external unsafeAddStyle: ([@mel.as {json|{}|json}] _, style, Js.t({..})) => style = "Object.assign"; diff --git a/jscomp/test/re_or_res/reasonReact.re b/jscomp/test/re_or_res/reasonReact.re index 0547e13aa0..9b6ab984b0 100644 --- a/jscomp/test/re_or_res/reasonReact.re +++ b/jscomp/test/re_or_res/reasonReact.re @@ -10,7 +10,7 @@ type reactElement = React.element; type reactRef; - external null: reactElement = "null"; +external null: reactElement = "null"; external string: string => reactElement = "%identity"; @@ -18,7 +18,7 @@ external array: array(reactElement) => reactElement = "%identity"; external refToJsObj: reactRef => Js.t({..}) = "%identity"; -[@mel.splice] [@mel.module "react"] +[@mel.splice] [@mel.module "react"] external createElement: (reactClass, ~props: Js.t({..})=?, array(reactElement)) => reactElement = "createElement"; @@ -28,17 +28,16 @@ external cloneElement: (reactElement, ~props: Js.t({..})=?, array(reactElement)) => reactElement = "cloneElement"; - [@mel.module "react"] -external createElementVerbatim: 'a = "createElement"; +[@mel.module "react"] external createElementVerbatim: 'a = "createElement"; let createDomElement = (s, ~props, children) => { let vararg = - [|Obj.magic(s), Obj.magic(props)|] |> Js.Array.concat(children); + [|Obj.magic(s), Obj.magic(props)|] |> Js.Array.concat(~other=children); /* Use varargs to avoid warnings on duplicate keys in children */ Obj.magic(createElementVerbatim)##apply(Js.Nullable.null, vararg); }; - external magicNull: 'a = "null"; +external magicNull: 'a = "null"; type reactClassInternal = reactClass; @@ -190,13 +189,15 @@ let convertPropsIfTheyreFromJs = (props, jsPropsToReason, debugName) => { let createClass = (type reasonState, type retainedProps, type action, debugName): reactClass => ReasonReactOptimizedCreateClass.createClass(. - [@u] [@ocaml.warning "-27"] { + [@u] + [@ocaml.warning "-27"] + { /*** * TODO: Null out fields that aren't overridden beyond defaults in * `component`. React optimizes components that don't implement * lifecycles! */ - val displayName = debugName; + val displayName = debugName; val mutable subscriptions = Js.null; /*** * TODO: Avoid allocating this every time we need it. Should be doable. @@ -310,7 +311,8 @@ let createClass = }; switch (Js.Null.toOption(this##subscriptions)) { | None => () - | Some(subs) => Js.Array.forEach(unsubscribe => unsubscribe(), subs) + | Some(subs) => + Js.Array.forEach(~f=unsubscribe => unsubscribe(), subs) }; }; /*** @@ -484,7 +486,7 @@ let createClass = pub onUnmountMethod = subscription => switch (Js.Null.toOption(this##subscriptions)) { | None => this##subscriptions #= Js.Null.return([|subscription|]) - | Some(subs) => ignore(Js.Array.push(subscription, subs)) + | Some(subs) => ignore(Js.Array.push(subs, ~value=subscription)) }; pub handleMethod = callback => { let thisJs: @@ -718,7 +720,7 @@ module WrapProps = { ); let varargs = [|Obj.magic(reactClass), Obj.magic(props)|] - |> Js.Array.concat(Obj.magic(children)); + |> Js.Array.concat(~other=Obj.magic(children)); /* Use varargs under the hood */ Obj.magic(createElementVerbatim)##apply(Js.Nullable.null, varargs); };