From 7db5dce71c89a92ca7b1e1ef9fd946af90678bb5 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Tue, 14 Nov 2023 18:30:31 -0800 Subject: [PATCH 1/5] feat: remove Js.String2, use labeled arguments for Js.String --- jscomp/runtime/js.ml | 3 - jscomp/runtime/js_string.ml | 712 +-- jscomp/runtime/js_string2.ml | 709 --- jscomp/test/bs_string_test.ml | 4 +- jscomp/test/chn_test.ml | 2 +- .../dist/jscomp/test/flow_parser_reg_test.js | 1738 +++--- .../test/dist/jscomp/test/js_string_test.js | 12 +- .../dist/jscomp/test/ocaml_parsetree_test.js | 122 +- .../dist/jscomp/test/ocaml_typedtree_test.js | 4650 ++++++++--------- jscomp/test/exception_repr_test.ml | 20 +- jscomp/test/js_string_test.ml | 118 +- jscomp/test/re_or_res/reactTestUtils.re | 6 +- jscomp/test/re_or_res/reasonReactRouter.re | 20 +- jscomp/test/sexpm_test.ml | 2 +- 14 files changed, 3731 insertions(+), 4387 deletions(-) delete mode 100644 jscomp/runtime/js_string2.ml diff --git a/jscomp/runtime/js.ml b/jscomp/runtime/js.ml index ebbbee7a23..b07bab56fc 100644 --- a/jscomp/runtime/js.ml +++ b/jscomp/runtime/js.ml @@ -92,9 +92,6 @@ module Nullable = Js_null_undefined module Array = Js_array (** Provide bindings to Js array*) -module String2 = Js_string2 -(** Provide bindings to JS string *) - module Re = Js_re (** Provide bindings to Js regex expression *) diff --git a/jscomp/runtime/js_string.ml b/jscomp/runtime/js_string.ml index 4809831c7b..40a19a3b1e 100644 --- a/jscomp/runtime/js_string.ml +++ b/jscomp/runtime/js_string.ml @@ -71,19 +71,14 @@ external fromCodePoint : int -> t = "String.fromCodePoint" *) -(** ES2015 *) - +external fromCodePointMany : int array -> t = "String.fromCodePoint" +[@@mel.splice] (** [fromCharCodeMany \[|n1;n2;n3|\]] creates a string from the characters corresponding to the given code point numbers, using the same rules as [fromCodePoint]. {[ fromCodePointMany([|0xd55c; 0xae00; 0x1f63a|]) = {js|한글😺|js} ]} *) -external fromCodePointMany : int array -> t = "String.fromCodePoint" -[@@mel.splice] -(** ES2015 *) - -(* String.raw: ES2015, meant to be used with template strings, not directly *) external length : t -> int = "length" [@@mel.get] @@ -106,167 +101,191 @@ external get : t -> int -> t = "" ]} *) -external charAt : int -> t = "charAt" -[@@mel.send.pipe: t] -(** [charAt n s] gets the character at index [n] within string [s]. If [n] is negative or greater than the length of [s], returns the empty string. If the string contains characters outside the range [\u0000-\uffff], it will return the first 16-bit value at that position in the string. +external charAt : t -> pos:int -> t = "charAt" +[@@mel.send] +(** [charAt s ~pos] gets the character at index [pos] within string [s]. If + [pos] is negative or greater than the length of [s], returns the empty + string. If the string contains characters outside the range + [\u0000-\uffff], it will return the first 16-bit value at that position in + the string. {[ - charAt 0, "Reason" = "R" - charAt( 12, "Reason") = ""; - charAt( 5, {js|Rẽasöń|js} = {js|ń|js} + charAt "Reason" ~pos:0 = "R" + charAt "Reason" ~pos:12 = ""; + charAt {js|Rẽasöń|js} ~pos:5 = {js|ń|js} ]} *) -external charCodeAt : int -> float = "charCodeAt" -[@@mel.send.pipe: t] -(** [charCodeAt n s] returns the character code at position [n] in string [s]; the result is in the range 0-65535, unlke [codePointAt], so it will not work correctly for characters with code points greater than or equal to [0x10000]. -The return type is [float] because this function returns [NaN] if [n] is less than zero or greater than the length of the string. +external charCodeAt : t -> pos:int -> float = "charCodeAt" +[@@mel.send] +(** [charCodeAt s ~pos] returns the character code at position [pos] in string + [s]; the result is in the range 0-65535, unlke [codePointAt], so it will + not work correctly for characters with code points greater than or equal to + [0x10000]. + The return type is [float] because this function returns [NaN] if [pos] is + less than zero or greater than the length of the string. {[ - charCodeAt 0 {js|😺|js} returns 0xd83d - codePointAt 0 {js|😺|js} returns Some 0x1f63a + charCodeAt {js|😺|js} ~pos:0 returns 0xd83d + codePointAt {js|😺|js} ~pos:0 returns Some 0x1f63a ]} - *) -(** [codePointAt n s] returns the code point at position [n] within string [s] as a [Some] value. The return value handles code points greater than or equal to [0x10000]. If there is no code point at the given position, the function returns [None]. +external codePointAt : t -> pos:int -> int option = "codePointAt" +[@@mel.send] +(** [codePointAt s ~pos] returns the code point at position [pos] within string + [s] as a [Some] value. The return value handles code points greater than or + equal to [0x10000]. If there is no code point at the given position, the + function returns [None]. {[ - codePointAt 1 {js|¿😺?|js} = Some 0x1f63a - codePointAt 5 "abc" = None + codePointAt {js|¿😺?|js} 1 = Some 0x1f63a + codePointAt "abc" 5 = None ]} *) -external codePointAt : int -> int option = "codePointAt" -[@@mel.send.pipe: t] + (** ES2015 *) -external concat : t -> t = "concat" -[@@mel.send.pipe: t] -(** [concat append original] returns a new string with [append] added after [original]. +external concat : t -> other:t -> t = "concat" +[@@mel.send] +(** [concat original ~other] returns a new string with [other] added + after [original]. {[ - concat "bell" "cow" = "cowbell";; + concat "cow" ~other:"bell" = "cowbell";; ]} *) -external concatMany : t array -> t = "concat" -[@@mel.send.pipe: t] [@@mel.splice] -(** [concat arr original] returns a new string consisting of each item of an array of strings added to the [original] string. +external concatMany : t -> strings:t array -> t = "concat" +[@@mel.send] [@@mel.splice] +(** [concatMany original ~strings] returns a new string consisting of each item + of the array of strings [strings] added to the [original] string. {[ - concatMany [|"2nd"; "3rd"; "4th"|] "1st" = "1st2nd3rd4th";; + concatMany "1st" ~strings:[|"2nd"; "3rd"; "4th"|] = "1st2nd3rd4th";; ]} *) -external endsWith : t -> bool = "endsWith" -[@@mel.send.pipe: t] -(** ES2015: - [endsWith substr str] returns [true] if the [str] ends with [substr], [false] otherwise. +external endsWith : t -> suffix:t -> bool = "endsWith" +[@@mel.send] +(** [endsWith str ~suffix] returns [true] if the [str] ends with [suffix], + [false] otherwise. {[ - endsWith "World!" "Hello, World!" = true;; - endsWith "world!" "Hello, World!" = false;; (* case-sensitive *) - endsWith "World" "Hello, World!" = false;; (* exact match *) + endsWith "Hello, World!" ~suffix:"World!" = true;; + endsWith "Hello, World!" ~suffix:"world!" = false;; (* case-sensitive *) + endsWith "Hello, World!" ~suffix:"World" = false;; (* exact match *) ]} *) -(** [endsWithFrom ending len str] returns [true] if the first [len] characters of [str] end with [ending], [false] otherwise. If [n] is greater than or equal to the length of [str], then it works like [endsWith]. (Honestly, this should have been named [endsWithAt], but oh well.) +external endsWithFrom : t -> suffix:t -> len:int -> bool = "endsWith" +[@@mel.send] +(** [endsWithFrom str ~len ~suffix] returns [true] if the first [len] + characters of [str] end with [ending], [false] otherwise. If [len] is + greater than or equal to the length of [str], then it works like + [endsWith]. {[ - endsWithFrom "cd" 4 "abcd" = true;; - endsWithFrom "cd" 3 "abcde" = false;; - endsWithFrom "cde" 99 "abcde" = true;; - endsWithFrom "ple" 7 "example.dat" = true;; + endsWithFrom "abcd" ~suffix:"cd" ~len:4 = true;; + endsWithFrom "abcde" ~suffix:"cd" ~len:3 = false;; + endsWithFrom "abcde" ~suffix:"cde" ~len:99 = true;; + endsWithFrom "example.dat" ~suffix:"ple" ~len:7 = true;; ]} *) -external endsWithFrom : t -> int -> bool = "endsWith" -[@@mel.send.pipe: t] -(** ES2015 *) -(** - [includes searchValue s] returns [true] if [searchValue] is found anywhere within [s], [false] otherwise. +external includes : t -> sub:t -> bool = "includes" +[@@mel.send] +(** [includes s ~sub:searchValue] returns [true] if [searchValue] is found + anywhere within [s], [false] otherwise. {[ - includes "gram" "programmer" = true;; - includes "er" "programmer" = true;; - includes "pro" "programmer" = true;; - includes "xyz" "programmer" = false;; + includes "programmer" ~sub:"gram" = true;; + includes "programmer" ~sub:"er" = true;; + includes "programmer" ~sub:"pro" = true;; + includes "programmer" ~sub:"xyz" = false;; ]} *) -external includes : t -> bool = "includes" -[@@mel.send.pipe: t] -(** ES2015 *) +external includesFrom : t -> sub:t -> pos:int -> bool = "includes" +[@@mel.send] (** - [includes searchValue start s] returns [true] if [searchValue] is found anywhere within [s] starting at character number [start] (where 0 is the first character), [false] otherwise. + [includes s ~sub:searchValue ~start] returns [true] if [searchValue] is found + anywhere within [s] starting at character number [start] (where 0 is the + first character), [false] otherwise. {[ - includesFrom "gram" 1 "programmer" = true;; - includesFrom "gram" 4 "programmer" = false;; - includesFrom {js|한|js} 1 {js|대한민국|js} = true;; + includesFrom "programmer" ~sub:"gram" ~pos:1 = true;; + includesFrom "programmer" ~sub:"gram" ~pos:4 = false;; + includesFrom {js|대한민국|js} ~sub:{js|한|js} ~pos:1 = true;; ]} *) -external includesFrom : t -> int -> bool = "includes" -[@@mel.send.pipe: t] -(** ES2015 *) -external indexOf : t -> int = "indexOf" -[@@mel.send.pipe: t] +external indexOf : t -> sub:t -> int = "indexOf" +[@@mel.send] (** - [indexOf searchValue s] returns the position at which [searchValue] was first found within [s], or [-1] if [searchValue] is not in [s]. + [indexOf s ~sub:searchValue ] returns the position at which [searchValue] was + first found within [s], or [-1] if [searchValue] is not in [s]. {[ - indexOf "ok" "bookseller" = 2;; - indexOf "sell" "bookseller" = 4;; - indexOf "ee" "beekeeper" = 1;; - indexOf "xyz" "bookseller" = -1;; + indexOf "bookseller" ~sub:"ok" = 2;; + indexOf "bookseller" ~sub:"sell" = 4;; + indexOf "beekeeper" ~sub:"ee" = 1;; + indexOf "bookseller" ~sub:"xyz" = -1;; ]} *) -external indexOfFrom : t -> int -> int = "indexOf" -[@@mel.send.pipe: t] -(** - [indexOfFrom searchValue start s] returns the position at which [searchValue] was found within [s] starting at character position [start], or [-1] if [searchValue] is not found in that portion of [s]. The return value is relative to the beginning of the string, no matter where the search started from. +external indexOfFrom : t -> sub:t -> pos:int -> int = "indexOf" +[@@mel.send] +(** [indexOfFrom s ~sub:searchValue ~start] returns the position at which + [searchValue] was found within [s] starting at character position [start], + or [-1] if [searchValue] is not found in that portion of [s]. The return + value is relative to the beginning of the string, no matter where the + search started from. {[ - indexOfFrom "ok" 1 "bookseller" = 2;; - indexOfFrom "sell" 2 "bookseller" = 4;; - indexOfFrom "sell" 5 "bookseller" = -1;; - indexOf "xyz" "bookseller" = -1;; + indexOfFrom "bookseller" ~sub:"ok" ~pos:1 = 2;; + indexOfFrom "bookseller" ~sub:"sell" ~pos:2 = 4;; + indexOfFrom "bookseller" ~sub:"sell" ~pos:5 = -1;; ]} *) -external lastIndexOf : t -> int = "lastIndexOf" -[@@mel.send.pipe: t] +external lastIndexOf : t -> sub:t -> int = "lastIndexOf" +[@@mel.send] (** - [lastIndexOf searchValue s] returns the position of the {i last} occurrence of [searchValue] within [s], searching backwards from the end of the string. Returns [-1] if [searchValue] is not in [s]. The return value is always relative to the beginning of the string. + [lastIndexOf s ~sub:searchValue ] returns the position of the {i last} + occurrence of [searchValue] within [s], searching backwards from the end of + the string. Returns [-1] if [searchValue] is not in [s]. The return value is + always relative to the beginning of the string. {[ - lastIndexOf "ok" "bookseller" = 2;; - lastIndexOf "ee" "beekeeper" = 4;; - lastIndexOf "xyz" "abcdefg" = -1;; + lastIndexOf "bookseller" ~sub:"ok" = 2;; + lastIndexOf "beekeeper" ~sub:"ee" = 4;; + lastIndexOf "abcdefg" ~sub:"xyz" = -1;; ]} *) -external lastIndexOfFrom : t -> int -> int = "lastIndexOf" -[@@mel.send.pipe: t] +external lastIndexOfFrom : t -> sub:t -> pos:int -> int = "lastIndexOf" +[@@mel.send] (** - [lastIndexOfFrom searchValue start s] returns the position of the {i last} occurrence of [searchValue] within [s], searching backwards from the given [start] position. Returns [-1] if [searchValue] is not in [s]. The return value is always relative to the beginning of the string. + [lastIndexOfFrom s ~sub:searchValue ~start] returns the position of the {i + last} occurrence of [searchValue] within [s], searching backwards from the + given [start] position. Returns [-1] if [searchValue] is not in [s]. The + return value is always relative to the beginning of the string. {[ - lastIndexOfFrom "ok" 6 "bookseller" = 2;; - lastIndexOfFrom "ee" 8 "beekeeper" = 4;; - lastIndexOfFrom "ee" 3 "beekeeper" = 1;; - lastIndexOfFrom "xyz" 4 "abcdefg" = -1;; + lastIndexOfFrom "bookseller" ~sub:"ok" ~pos:6 = 2;; + lastIndexOfFrom "beekeeper" ~sub:"ee" ~pos:8 = 4;; + lastIndexOfFrom "beekeeper" ~sub:"ee" ~pos:3 = 1;; + lastIndexOfFrom "abcdefg" ~sub:"xyz" ~pos:4 = -1;; ]} *) (* extended by ECMA-402 *) -external localeCompare : t -> float = "localeCompare" -[@@mel.send.pipe: t] +external localeCompare : t -> other:t -> float = "localeCompare" +[@@mel.send] (** - [localeCompare comparison reference] returns + [localeCompare reference ~other:comparison] returns: {ul {- a negative value if [reference] comes before [comparison] in sort order} @@ -274,150 +293,163 @@ external localeCompare : t -> float = "localeCompare" {- a positive value if [reference] comes after [comparison] in sort order}} {[ - (localeCompare "ant" "zebra") > 0.0;; - (localeCompare "zebra" "ant") < 0.0;; + (localeCompare "zebra" "ant") > 0.0;; + (localeCompare "ant" "zebra") < 0.0;; (localeCompare "cat" "cat") = 0.0;; - (localeCompare "cat" "CAT") > 0.0;; + (localeCompare "CAT" "cat") > 0.0;; ]} *) -external match_ : Js_re.t -> t option array option = "match" -[@@mel.send.pipe: t] [@@mel.return { null_to_opt }] +external match_ : t -> regexp:Js_re.t -> t option array option = "match" +[@@mel.send] [@@mel.return { null_to_opt }] (** - [match regexp str] matches a string against the given [regexp]. If there is no match, it returns [None]. - For regular expressions without the [g] modifier, if there is a match, the return value is [Some array] where the array contains: + [match str ~regexp] matches a string against the given [regexp]. If there is + no match, it returns [None]. For regular expressions without the [g] + modifier, if there is a match, the return value is [Some array] where the + array contains: {ul {- The entire matched string} {- Any capture groups if the [regexp] had parentheses} } - For regular expressions with the [g] modifier, a matched expression returns [Some array] with all the matched substrings and no capture groups. + For regular expressions with the [g] modifier, a matched expression returns + [Some array] with all the matched substrings and no capture groups. {[ - match [%re "/b[aeiou]t/"] "The better bats" = Some [|"bet"|] - match [%re "/b[aeiou]t/g"] "The better bats" = Some [|"bet";"bat"|] - match [%re "/(\\d+)-(\\d+)-(\\d+)/"] "Today is 2018-04-05." = - Some [|"2018-04-05"; "2018"; "04"; "05"|] - match [%re "/b[aeiou]g/"] "The large container." = None + match "The better bats" ~regexp:[%re "/b[aeiou]t/"] = Some [|"bet"|] + match "The better bats" ~regexp:[%re "/b[aeiou]t/g"] = Some [|"bet";"bat"|] + match "Today is 2018-04-05." ~regexp:[%re "/(\\d+)-(\\d+)-(\\d+)/"] = Some [|"2018-04-05"; "2018"; "04"; "05"|] + match "The large container." ~regexp:[%re "/b[aeiou]g/"] = None ]} - *) -(** [normalize str] returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition. +external normalize : t -> t = "normalize" +[@@mel.send] +(** [normalize str] returns the normalized Unicode string using Normalization + Form Canonical (NFC) Composition. -Consider the character [ã], which can be represented as the single codepoint [\u00e3] or the combination of a lower case letter A [\u0061] and a combining tilde [\u0303]. Normalization ensures that both can be stored in an equivalent binary representation. + Consider the character [ã], which can be represented as the single + codepoint [\u00e3] or the combination of a lower case letter A [\u0061] and + a combining tilde [\u0303]. Normalization ensures that both can be stored + in an equivalent binary representation. -@see Unicode technical report for details + @see Unicode technical + report for details *) -external normalize : t = "normalize" -[@@mel.send.pipe: t] -(** ES2015 *) -external normalizeByForm : t -> t = "normalize" -[@@mel.send.pipe: t] -(** - [normalize str form] (ES2015) returns the normalized Unicode string using the specified form of normalization, which may be one of: +external normalizeByForm : t -> form:[ `NFC | `NFD | `NFKC | `NFKD ] -> t + = "normalize" +[@@mel.send] +(** [normalize str ~form] returns the normalized Unicode string using the + specified form of normalization, which may be one of: {ul - {- "NFC" — Normalization Form Canonical Composition.} - {- "NFD" — Normalization Form Canonical Decomposition.} - {- "NFKC" — Normalization Form Compatibility Composition.} - {- "NFKD" — Normalization Form Compatibility Decomposition.} + {- [`NFC] — Normalization Form Canonical Composition.} + {- [`NFD] — Normalization Form Canonical Decomposition.} + {- [`NFKC] — Normalization Form Compatibility Composition.} + {- [`NFKD] — Normalization Form Compatibility Decomposition.} } - @see Unicode technical report for details + @see Unicode technical + report for details *) -(** - [repeat n s] returns a string that consists of [n] repetitions of [s]. Raises [RangeError] if [n] is negative. +external repeat : t -> n:int -> t = "repeat" +[@@mel.send] +(** [repeat s n] returns a string that consists of [n] repetitions of [s]. + Raises [RangeError] if [n] is negative. {[ - repeat 3 "ha" = "hahaha" - repeat 0 "empty" = "" + repeat "ha" ~n:3 = "hahaha" + repeat "empty" ~n:0 = "" ]} *) -external repeat : int -> t = "repeat" -[@@mel.send.pipe: t] -(** ES2015 *) -external replace : t -> t -> t = "replace" -[@@mel.send.pipe: t] -(** [replace substr newSubstr string] returns a new string which is -identical to [string] except with the first matching instance of [substr] -replaced by [newSubstr]. +external replace : t -> sub:t -> replacement:t -> t = "replace" +[@@mel.send] +(** [replace string ~sub ~replacement] returns a new string which is + identical to [string] except with the first matching instance of [sub] + replaced by [replacement]. -[substr] is treated as a verbatim string to match, not a regular -expression. + [sub] is treated as a verbatim string to match, not a regular expression. {[ - replace "old" "new" "old string" = "new string" - replace "the" "this" "the cat and the dog" = "this cat and the dog" + replace "old string" ~sub:"old" ~replacement:"new" = "new string" + replace "the cat and the dog" ~sub:"the" ~replacement:"this" = "this cat and the dog" ]} *) -external replaceByRe : Js_re.t -> t -> t = "replace" -[@@mel.send.pipe: t] -(** [replaceByRe regex replacement string] returns a new string where occurrences matching [regex] -have been replaced by [replacement]. +external replaceByRe : t -> regexp:Js_re.t -> replacement:t -> t = "replace" +[@@mel.send] +(** [replaceByRe string ~regexp ~replacement] returns a new string where + occurrences matching [regexp] have been replaced by [replacement]. {[ - replaceByRe [%re "/[aeiou]/g"] "x" "vowels be gone" = "vxwxls bx gxnx" - replaceByRe [%re "/(\\w+) (\\w+)/"] "$2, $1" "Juan Fulano" = "Fulano, Juan" + replaceByRe "vowels be gone" ~regexp:[%re "/[aeiou]/g"] ~replacement:"x" = "vxwxls bx gxnx" + replaceByRe "Juan Fulano" ~regexp:[%re "/(\\w+) (\\w+)/"] ~replacement:"$2, $1" = "Fulano, Juan" ]} *) -external unsafeReplaceBy0 : Js_re.t -> ((t -> int -> t -> t)[@mel.uncurry]) -> t - = "replace" -[@@mel.send.pipe: t] -(** returns a new string with some or all matches of a pattern with no capturing -parentheses replaced by the value returned from the given function. -The function receives as its parameters the matched string, the offset at which the -match begins, and the whole string being matched +external unsafeReplaceBy0 : + t -> regexp:Js_re.t -> f:((t -> int -> t -> t)[@mel.uncurry]) -> t = "replace" +[@@mel.send] +(** [unsafeReplaceBy0 s ~regexp ~f] returns a new string with some or all + matches of a pattern with no capturing parentheses replaced by the value + returned from the given function. The function receives as its parameters + the matched string, the offset at which the match begins, and the whole + string being matched {[ let str = "beautiful vowels" let re = [%re "/[aeiou]/g"] -let matchFn matchPart offset wholeString = - Js.String.toUpperCase matchPart +let matchFn matchPart offset wholeString = Js.String.toUpperCase matchPart -let replaced = Js.String.unsafeReplaceBy0 re matchFn str +let replaced = Js.String.unsafeReplaceBy0 str ~regexp:re ~f:matchFn let () = Js.log replaced (* prints "bEAUtifUl vOwEls" *) ]} -@see MDN + @see + + MDN *) external unsafeReplaceBy1 : - Js_re.t -> ((t -> t -> int -> t -> t)[@mel.uncurry]) -> t = "replace" -[@@mel.send.pipe: t] -(** returns a new string with some or all matches of a pattern with one set of capturing -parentheses replaced by the value returned from the given function. -The function receives as its parameters the matched string, the captured string, -the offset at which the match begins, and the whole string being matched. + t -> regexp:Js_re.t -> f:((t -> t -> int -> t -> t)[@mel.uncurry]) -> t + = "replace" +[@@mel.send] +(** [unsafeReplaceBy0 s ~regexp ~f] returns a new string with some or all + matches of a pattern with one set of capturing parentheses replaced by the + value returned from the given function. The function receives as its + parameters the matched string, the captured strings, the offset at which + the match begins, and the whole string being matched. -{[ -let str = "increment 23" -let re = [%re "/increment (\\d+)/g"] -let matchFn matchPart p1 offset wholeString = - wholeString ^ " is " ^ (string_of_int ((int_of_string p1) + 1)) + {[ + let str = "increment 23" + let re = [%re "/increment (\\d+)/g"] + let matchFn matchPart p1 offset wholeString = + wholeString ^ " is " ^ (string_of_int ((int_of_string p1) + 1)) -let replaced = Js.String.unsafeReplaceBy1 re matchFn str + let replaced = Js.String.unsafeReplaceBy1 str ~regexp:re ~f:matchFn -let () = Js.log replaced (* prints "increment 23 is 24" *) -]} + let () = Js.log replaced (* prints "increment 23 is 24" *) + ]} -@see MDN + @see + +MDN *) external unsafeReplaceBy2 : - Js_re.t -> ((t -> t -> t -> int -> t -> t)[@mel.uncurry]) -> t = "replace" -[@@mel.send.pipe: t] -(** returns a new string with some or all matches of a pattern with two sets of capturing -parentheses replaced by the value returned from the given function. -The function receives as its parameters the matched string, the captured strings, -the offset at which the match begins, and the whole string being matched. + t -> regexp:Js_re.t -> f:((t -> t -> t -> int -> t -> t)[@mel.uncurry]) -> t + = "replace" +[@@mel.send] +(** [unsafeReplaceBy2 s ~regexp ~f] returns a new string with some or all + matches of a pattern with two sets of capturing parentheses replaced by the + value returned from the given function. The function receives as its + parameters the matched string, the captured strings, the offset at which + the match begins, and the whole string being matched. {[ let str = "7 times 6" @@ -425,7 +457,7 @@ let re = [%re "/(\\d+) times (\\d+)/"] let matchFn matchPart p1 p2 offset wholeString = string_of_int ((int_of_string p1) * (int_of_string p2)) -let replaced = Js.String.unsafeReplaceBy2 re matchFn str +let replaced = Js.String.unsafeReplaceBy2 str ~regexp:re ~f:matchFn let () = Js.log replaced (* prints "42" *) ]} @@ -434,221 +466,229 @@ let () = Js.log replaced (* prints "42" *) *) external unsafeReplaceBy3 : - Js_re.t -> ((t -> t -> t -> t -> int -> t -> t)[@mel.uncurry]) -> t - = "replace" -[@@mel.send.pipe: t] -(** returns a new string with some or all matches of a pattern with three sets of capturing -parentheses replaced by the value returned from the given function. -The function receives as its parameters the matched string, the captured strings, -the offset at which the match begins, and the whole string being matched. + t -> + regexp:Js_re.t -> + f:((t -> t -> t -> t -> int -> t -> t)[@mel.uncurry]) -> + t = "replace" +[@@mel.send] +(** [unsafeReplaceBy3 s ~regexp ~f] returns a new string with some or all + matches of a pattern with three sets of capturing parentheses replaced by + the value returned from the given function. The function receives as its + parameters the matched string, the captured strings, the offset at which + the match begins, and the whole string being matched. -@see MDN + @see MDN *) -external search : Js_re.t -> int = "search" -[@@mel.send.pipe: t] -(** [search regexp str] returns the starting position of the first match of [regexp] in the given [str], or -1 if there is no match. +external search : t -> regexp:Js_re.t -> int = "search" +[@@mel.send] +(** [search str ~regexp] returns the starting position of the first match of + [regexp] in the given [str], or -1 if there is no match. {[ -search [%re "/\\d+/"] "testing 1 2 3" = 8;; -search [%re "/\\d+/"] "no numbers" = -1;; +search "testing 1 2 3" [%re "/\\d+/"] = 8;; +search "no numbers" [%re "/\\d+/"] = -1;; ]} *) -external slice : from:int -> to_:int -> t = "slice" -[@@mel.send.pipe: t] -(** [slice from:n1 to_:n2 str] returns the substring of [str] starting at character [n1] up to but not including [n2] +external slice : t -> from:int -> to_:int -> t = "slice" +[@@mel.send] +(** [slice from:n1 to_:n2 str] returns the substring of [str] starting at + character [n1] up to but not including [n2] -If either [n1] or [n2] is negative, then it is evaluated as [length str - n1] (or [length str - n2]. + If either [n1] or [n2] is negative, then it is evaluated as [length str - + n1] (or [length str - n2]). -If [n2] is greater than the length of [str], then it is treated as [length str]. + If [n2] is greater than the length of [str], then it is treated as [length + str]. -If [n1] is greater than [n2], [slice] returns the empty string. + If [n1] is greater than [n2], [slice] returns the empty string. {[ - slice ~from:2 ~to_:5 "abcdefg" == "cde";; - slice ~from:2 ~to_:9 "abcdefg" == "cdefg";; - slice ~from:(-4) ~to_:(-2) "abcdefg" == "de";; - slice ~from:5 ~to_:1 "abcdefg" == "";; + slice "abcdefg" ~from:2 ~to_:5 == "cde";; + slice "abcdefg" ~from:2 ~to_:9 == "cdefg";; + slice "abcdefg" ~from:(-4) ~to_:(-2) == "de";; + slice "abcdefg" ~from:5 ~to_:1 == "";; ]} *) -external sliceToEnd : from:int -> t = "slice" -[@@mel.send.pipe: t] -(** [sliceToEnd from: n str] returns the substring of [str] starting at character [n] to the end of the string +external sliceToEnd : t -> from:int -> t = "slice" +[@@mel.send] +(** [sliceToEnd from: n str] returns the substring of [str] starting at + character [n] to the end of the string -If [n] is negative, then it is evaluated as [length str - n]. + If [n] is negative, then it is evaluated as [length str - n]. -If [n] is greater than the length of [str], then [sliceToEnd] returns the empty string. + If [n] is greater than the length of [str], then [sliceToEnd] returns the + empty string. {[ - sliceToEnd ~from: 4 "abcdefg" == "efg";; - sliceToEnd ~from: (-2) "abcdefg" == "fg";; - sliceToEnd ~from: 7 "abcdefg" == "";; + sliceToEnd "abcdefg" ~from: 4 == "efg";; + sliceToEnd "abcdefg" ~from: (-2) == "fg";; + sliceToEnd "abcdefg" ~from: 7 == "";; ]} *) -external split : t -> t array = "split" -[@@mel.send.pipe: t] +external split : t -> sep:t -> t array = "split" +[@@mel.send] (** - [split delimiter str] splits the given [str] at every occurrence of [delimiter] and returns an - array of the resulting substrings. + [split str ~sep:delimiter] splits the given [str] at every occurrence of + [delimiter] and returns an array of the resulting substrings. {[ - split "-" "2018-01-02" = [|"2018"; "01"; "02"|];; - split "," "a,b,,c" = [|"a"; "b"; ""; "c"|];; - split "::" "good::bad as great::awful" = [|"good"; "bad as great"; "awful"|];; - split ";" "has-no-delimiter" = [|"has-no-delimiter"|];; + split "2018-01-02" "-" = [|"2018"; "01"; "02"|];; + split "a,b,,c" "," = [|"a"; "b"; ""; "c"|];; + split "good::bad as great::awful" "::" = [|"good"; "bad as great"; "awful"|];; + split "has-no-delimiter" ";" = [|"has-no-delimiter"|];; ]}; *) -external splitAtMost : t -> limit:int -> t array = "split" -[@@mel.send.pipe: t] -(** - [splitAtMost delimiter ~limit: n str] splits the given [str] at every occurrence of [delimiter] and returns an array of the first [n] resulting substrings. If [n] is negative or greater than the number of substrings, the array will contain all the substrings. +external splitAtMost : t -> sep:t -> limit:int -> t array = "split" +[@@mel.send] +(** [splitAtMost delimiter ~limit: n str] splits the given [str] at every + occurrence of [delimiter] and returns an array of the first [n] resulting + substrings. If [n] is negative or greater than the number of substrings, + the array will contain all the substrings. {[ - splitAtMost "/" ~limit: 3 "ant/bee/cat/dog/elk" = [|"ant"; "bee"; "cat"|];; - splitAtMost "/" ~limit: 0 "ant/bee/cat/dog/elk" = [| |];; - splitAtMost "/" ~limit: 9 "ant/bee/cat/dog/elk" = [|"ant"; "bee"; "cat"; "dog"; "elk"|];; + splitAtMost "ant/bee/cat/dog/elk" ~sep:"/" ~limit: 3 = [|"ant"; "bee"; "cat"|];; + splitAtMost "ant/bee/cat/dog/elk" ~sep:"/" ~limit: 0 = [| |];; + splitAtMost "ant/bee/cat/dog/elk" ~sep:"/" ~limit: 9 = [|"ant"; "bee"; "cat"; "dog"; "elk"|];; ]} *) -external splitLimited : t -> int -> t array = "split" -[@@mel.send.pipe: t] [@@deprecated "Please use splitAtMost"] -(** - Deprecated - Please use [splitAtMost] -*) - -external splitByRe : Js_re.t -> t option array = "split" -[@@mel.send.pipe: t] -(** - [splitByRe regex str] splits the given [str] at every occurrence of [regex] and returns an - array of the resulting substrings. +external splitByRe : t -> regexp:Js_re.t -> t option array = "split" +[@@mel.send] +(** [splitByRe str ~regexp] splits the given [str] at every occurrence of + [regexp] and returns an array of the resulting substrings. {[ - splitByRe [%re "/\\s*[,;]\\s*/"] "art; bed , cog ;dad" = [|Some "art"; Some "bed"; Some "cog"; Some "dad"|];; - splitByRe [%re "/[,;]/"] "has:no:match" = [|Some "has:no:match"|];; - splitByRe [%re "/(#)(:)?/"] "a#b#:c" = [|Some "a"; Some "#"; None; Some "b"; Some "#"; Some ":"; Some "c"|];; + splitByRe "art; bed , cog ;dad" ~regexp:[%re "/\\s*[,;]\\s*/"] = [|"art"; "bed"; "cog"; "dad"|];; + splitByRe "has:no:match" ~regexp:[%re "/[,;]/"] = [|"has:no:match"|];; ]}; *) -external splitByReAtMost : Js_re.t -> limit:int -> t option array = "split" -[@@mel.send.pipe: t] -(** - [splitByReAtMost regex ~limit: n str] splits the given [str] at every occurrence of [regex] and returns an - array of the first [n] resulting substrings. If [n] is negative or greater than the number of substrings, the array will contain all the substrings. +external splitByReAtMost : t -> regexp:Js_re.t -> limit:int -> t option array + = "split" +[@@mel.send] +(** [splitByReAtMost ~regexp ~limit:n str] splits the given [str] at every + occurrence of [regexp] and returns an array of the first [n] resulting + substrings. If [n] is negative or greater than the number of substrings, + the array will contain all the substrings. {[ - splitByReAtMost [%re "/\\s*:\\s*/"] ~limit: 3 "one: two: three: four" = [|Some "one"; Some "two"; Some "three"|];; - splitByReAtMost [%re "/\\s*:\\s*/"] ~limit: 0 "one: two: three: four" = [| |];; - splitByReAtMost [%re "/\\s*:\\s*/"] ~limit: 8 "one: two: three: four" = [|Some "one"; Some "two"; Some "three"; Some "four"|];; - splitByReAtMost [%re "/(#)(:)?/"] ~limit:3 "a#b#:c" = [|Some "a"; Some "#"; None|];; + splitByReAtMost "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit: 3 = [|"one"; "two"; "three"|];; + splitByReAtMost "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit: 0 = [| |];; + splitByReAtMost "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit: 8 = [|"one"; "two"; "three"; "four"|];; ]}; *) -external splitRegexpLimited : Js_re.t -> int -> t array = "split" -[@@mel.send.pipe: t] [@@deprecated "Please use splitByReAtMost"] -(** - Deprecated - Please use [splitByReAtMost] -*) - -external startsWith : t -> bool = "startsWith" -[@@mel.send.pipe: t] -(** ES2015: - [startsWith substr str] returns [true] if the [str] starts with [substr], [false] otherwise. +external startsWith : t -> prefix:t -> bool = "startsWith" +[@@mel.send] +(** [startsWith str ~prefix] returns [true] if the [str] starts with [prefix], + [false] otherwise. {[ - startsWith "Hello" "Hello, World!" = true;; - startsWith "hello" "Hello, World!" = false;; (* case-sensitive *) - startsWith "World" "Hello, World!" = false;; (* exact match *) + startsWith "Hello, World!" ~prefix:"Hello" = true;; + startsWith "Hello, World!" ~prefix:"hello" = false;; (* case-sensitive *) + startsWith "Hello, World!" ~prefix:"World" = false;; (* exact match *) ]} *) -external startsWithFrom : t -> int -> bool = "startsWith" -[@@mel.send.pipe: t] -(** ES2015: - [startsWithFrom substr n str] returns [true] if the [str] starts with [substr] starting at position [n], [false] otherwise. If [n] is negative, the search starts at the beginning of [str]. +external startsWithFrom : t -> prefix:t -> pos:int -> bool = "startsWith" +[@@mel.send] +(** [startsWithFrom str ~prefix ~start] returns [true] if the [str] starts with + [prefix] starting at position [start], [false] otherwise. If [n] is + negative, the search starts at the beginning of [str]. {[ - startsWithFrom "Hello" 0 "Hello, World!" = true;; - startsWithFrom "World" 7 "Hello, World!" = true;; - startsWithFrom "World" 8 "Hello, World!" = false;; + startsWithFrom "Hello, World!" "Hello" 0 = true;; + startsWithFrom "Hello, World!" "World" 7 = true;; + startsWithFrom "Hello, World!" "World" 8 = false;; ]} *) -external substr : from:int -> t = "substr" -[@@mel.send.pipe: t] -(** - [substr ~from: n str] returns the substring of [str] from position [n] to the end of the string. +external substr : t -> from:int -> t = "substr" +[@@mel.send] +(** [substr ~from:n str] returns the substring of [str] from position [n] to + the end of the string. - If [n] is less than zero, the starting position is the length of [str] - [n]. + If [n] is less than zero, the starting position is the length of [str] - + [n]. - If [n] is greater than or equal to the length of [str], returns the empty string. + If [n] is greater than or equal to the length of [str], returns the empty + string. {[ - substr ~from: 3 "abcdefghij" = "defghij" - substr ~from: (-3) "abcdefghij" = "hij" - substr ~from: 12 "abcdefghij" = "" + substr "abcdefghij" ~from: 3 = "defghij" + substr "abcdefghij" ~from: (-3) = "hij" + substr "abcdefghij" ~from: 12 = "" ]} *) -external substrAtMost : from:int -> length:int -> t = "substr" -[@@mel.send.pipe: t] -(** - [substrAtMost ~from: pos ~length: n str] returns the substring of [str] of length [n] starting at position [pos]. +external substrAtMost : t -> from:int -> length:int -> t = "substr" +[@@mel.send] +(** [substrAtMost ~from:pos ~length:n str] returns the substring of [str] of + length [n] starting at position [pos]. - If [pos] is less than zero, the starting position is the length of [str] - [pos]. + If [pos] is less than zero, the starting position is the length of [str] - + [pos]. - If [pos] is greater than or equal to the length of [str], returns the empty string. + If [pos] is greater than or equal to the length of [str], returns the empty + string. - If [n] is less than or equal to zero, returns the empty string. + If [n] is less than or equal to zero, returns the empty string. {[ - substrAtMost ~from: 3 ~length: 4 "abcdefghij" = "defghij" - substrAtMost ~from: (-3) ~length: 4 "abcdefghij" = "hij" - substrAtMost ~from: 12 ~ length: 2 "abcdefghij" = "" + substrAtMost "abcdefghij" ~from: 3 ~length: 4 = "defghij" + substrAtMost "abcdefghij" ~from: (-3) ~length: 4 = "hij" + substrAtMost "abcdefghij" ~from: 12 ~ length: 2 = "" ]} *) -external substring : from:int -> to_:int -> t = "substring" -[@@mel.send.pipe: t] -(** - [substring ~from: start ~to_: finish str] returns characters [start] up to but not including [finish] from [str]. +external substring : t -> from:int -> to_:int -> t = "substring" +[@@mel.send] +(** [substring ~from: start ~to_: finish str] returns characters [start] up to + but not including [finish] from [str]. - If [start] is less than zero, it is treated as zero. + If [start] is less than zero, it is treated as zero. - If [finish] is zero or negative, the empty string is returned. + If [finish] is zero or negative, the empty string is returned. - If [start] is greater than [finish], the start and finish points are swapped. + If [start] is greater than [finish], the start and finish points are + swapped. {[ - substring ~from: 3 ~to_: 6 "playground" = "ygr";; - substring ~from: 6 ~to_: 3 "playground" = "ygr";; - substring ~from: 4 ~to_: 12 "playground" = "ground";; + substring "playground" ~from: 3 ~to_: 6 = "ygr";; + substring "playground" ~from: 6 ~to_: 3 = "ygr";; + substring "playground" ~from: 4 ~to_: 12 = "ground";; ]} *) -external substringToEnd : from:int -> t = "substring" -[@@mel.send.pipe: t] -(** - [substringToEnd ~from: start str] returns the substring of [str] from position [start] to the end. +external substringToEnd : t -> from:int -> t = "substring" +[@@mel.send] +(** [substringToEnd ~from: start str] returns the substring of [str] from + position [start] to the end. - If [start] is less than or equal to zero, the entire string is returned. + If [start] is less than or equal to zero, the entire string is returned. - If [start] is greater than or equal to the length of [str], the empty string is returned. + If [start] is greater than or equal to the length of [str], the empty + string is returned. {[ - substringToEnd ~from: 4 "playground" = "ground";; - substringToEnd ~from: (-3) "playground" = "playground";; - substringToEnd ~from: 12 "playground" = ""; + substringToEnd "playground" ~from: 4 = "ground";; + substringToEnd "playground" ~from: (-3) = "playground";; + substringToEnd "playground" ~from: 12 = ""; ]} *) -external toLowerCase : t = "toLowerCase" -[@@mel.send.pipe: t] -(** - [toLowerCase str] converts [str] to lower case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can give different results depending upon context, for example with the Greek letter sigma, which has two different lower case forms when it is the last character in a string or not. +external toLowerCase : t -> t = "toLowerCase" +[@@mel.send] +(** [toLowerCase str] converts [str] to lower case using the locale-insensitive + case mappings in the Unicode Character Database. Notice that the conversion + can give different results depending upon context, for example with the + Greek letter sigma, which has two different lower case forms when it is the + last character in a string or not. {[ toLowerCase "ABC" = "abc";; @@ -657,16 +697,19 @@ external toLowerCase : t = "toLowerCase" ]} *) -external toLocaleLowerCase : t = "toLocaleLowerCase" -[@@mel.send.pipe: t] +external toLocaleLowerCase : t -> t = "toLocaleLowerCase" +[@@mel.send] (** [toLocaleLowerCase str] converts [str] to lower case using the current locale *) -external toUpperCase : t = "toUpperCase" -[@@mel.send.pipe: t] +external toUpperCase : t -> t = "toUpperCase" +[@@mel.send] (** - [toUpperCase str] converts [str] to upper case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can expand the number of letters in the result; for example the German [ß] capitalizes to two [S]es in a row. + [toUpperCase str] converts [str] to upper case using the locale-insensitive + case mappings in the Unicode Character Database. Notice that the conversion + can expand the number of letters in the result; for example the German [ß] + capitalizes to two [S]es in a row. {[ toUpperCase "abc" = "ABC";; @@ -675,16 +718,16 @@ external toUpperCase : t = "toUpperCase" ]} *) -external toLocaleUpperCase : t = "toLocaleUpperCase" -[@@mel.send.pipe: t] -(** - [toLocaleUpperCase str] converts [str] to upper case using the current locale +external toLocaleUpperCase : t -> t = "toLocaleUpperCase" +[@@mel.send] +(** [toLocaleUpperCase str] converts [str] to upper case using the current + locale *) -external trim : t = "trim" -[@@mel.send.pipe: t] -(** - [trim str] returns a string that is [str] with whitespace stripped from both ends. Internal whitespace is not removed. +external trim : t -> t = "trim" +[@@mel.send] +(** [trim str] returns a string that is [str] with whitespace stripped from + both ends. Internal whitespace is not removed. {[ trim " abc def " = "abc def" @@ -694,29 +737,28 @@ external trim : t = "trim" (* HTML wrappers *) -(** - [anchor anchorName anchorText] creates a string with an HTML [] element with [name] attribute of [anchorName] and [anchorText] as its content. +external anchor : t -> name:t -> t = "anchor" +[@@mel.send] +(** [anchor anchorName ~text:anchorText] creates a string with an HTML [] + element with [name] attribute of [anchorName] and [anchorText] as its + content. {[ anchor "page1" "Page One" = "Page One" ]} *) -external anchor : t -> t = "anchor" -[@@mel.send.pipe: t] -(** ES2015 *) -(** - [link urlText linkText] creates a string withan HTML [] element with [href] attribute of [urlText] and [linkText] as its content. +external link : t -> href:t -> t = "link" +[@@mel.send] +(** [link linkText ~href:urlText] creates a string with an HTML [] element + with [href] attribute of [urlText] and [linkText] as its content. {[ - link "page2.html" "Go to page two" = "Go to page two" + link "Go to page two" "page2.html" = "Go to page two" ]} *) -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 deleted file mode 100644 index e3b843b5ea..0000000000 --- a/jscomp/runtime/js_string2.ml +++ /dev/null @@ -1,709 +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 String API *) - -type t = string - -external make : 'a -> t = "String" - -(** [make value] converts the given value to a string - -{[ - make 3.5 = "3.5";; - make [|1;2;3|]) = "1,2,3";; -]} -*) - -external fromCharCode : int -> t = "String.fromCharCode" - -(** [fromCharCode n] - creates a string containing the character corresponding to that number; {i n} ranges from 0 to 65535. If out of range, the lower 16 bits of the value are used. Thus, [fromCharCode 0x1F63A] gives the same result as [fromCharCode 0xF63A]. - -{[ - fromCharCode 65 = "A";; - fromCharCode 0x3c8 = {js|ψ|js};; - fromCharCode 0xd55c = {js|한|js};; - fromCharCode -64568 = {js|ψ|js};; -]} -*) - -external fromCharCodeMany : int array -> t = "String.fromCharCode" -[@@mel.splice] -(** [fromCharCodeMany \[|n1;n2;n3|\]] creates a string from the characters corresponding to the given numbers, using the same rules as [fromCharCode]. - -{[ - fromCharCodeMany([|0xd55c, 0xae00, 33|]) = {js|한글!|js};; -]} -*) - -external fromCodePoint : int -> t = "String.fromCodePoint" -(** [fromCodePoint n] - creates a string containing the character corresponding to that numeric code point. If the number is not a valid code point, {b raises} [RangeError]. Thus, [fromCodePoint 0x1F63A] will produce a correct value, unlike [fromCharCode 0x1F63A], and [fromCodePoint -5] will raise a [RangeError]. - -{[ - fromCodePoint 65 = "A";; - fromCodePoint 0x3c8 = {js|ψ|js};; - fromCodePoint 0xd55c = {js|한|js};; - fromCodePoint 0x1f63a = {js|😺|js};; -]} - -*) - -(** ES2015 *) - -(** [fromCharCodeMany \[|n1;n2;n3|\]] creates a string from the characters corresponding to the given code point numbers, using the same rules as [fromCodePoint]. - -{[ - fromCodePointMany([|0xd55c; 0xae00; 0x1f63a|]) = {js|한글😺|js} -]} -*) -external fromCodePointMany : int array -> t = "String.fromCodePoint" -[@@mel.splice] -(** ES2015 *) - -(* String.raw: ES2015, meant to be used with template strings, not directly *) - -external length : t -> int = "length" -[@@mel.get] -(** [length s] returns the length of the given string. - -{[ - length "abcd" = 4;; -]} - -*) - -external get : t -> int -> t = "" -[@@mel.get_index] -(** [get s n] returns as a string the character at the given index number. If [n] is out of range, this function returns [undefined], so at some point this function may be modified to return [t option]. - -{[ - get "Reason" 0 = "R";; - get "Reason" 4 = "o";; - get {js|Rẽasöń|js} 5 = {js|ń|js};; -]} -*) - -external charAt : t -> int -> t = "charAt" -[@@mel.send] -(** [charAt n s] gets the character at index [n] within string [s]. If [n] is negative or greater than the length of [s], returns the empty string. If the string contains characters outside the range [\u0000-\uffff], it will return the first 16-bit value at that position in the string. - -{[ - charAt "Reason" 0 = "R" - charAt "Reason" 12 = ""; - charAt {js|Rẽasöń|js} 5 = {js|ń|js} -]} -*) - -external charCodeAt : t -> int -> float = "charCodeAt" -[@@mel.send] -(** [charCodeAt n s] returns the character code at position [n] in string [s]; the result is in the range 0-65535, unlke [codePointAt], so it will not work correctly for characters with code points greater than or equal to [0x10000]. -The return type is [float] because this function returns [NaN] if [n] is less than zero or greater than the length of the string. - -{[ - charCodeAt {js|😺|js} 0 returns 0xd83d - codePointAt {js|😺|js} 0 returns Some 0x1f63a -]} - -*) - -(** [codePointAt n s] returns the code point at position [n] within string [s] as a [Some] value. The return value handles code points greater than or equal to [0x10000]. If there is no code point at the given position, the function returns [None]. - -{[ - codePointAt {js|¿😺?|js} 1 = Some 0x1f63a - codePointAt "abc" 5 = None -]} -*) -external codePointAt : t -> int -> int option = "codePointAt" -[@@mel.send] -(** ES2015 *) - -external concat : t -> t -> t = "concat" -[@@mel.send] -(** [concat append original] returns a new string with [append] added after [original]. - -{[ - concat "cow" "bell" = "cowbell";; -]} -*) - -external concatMany : t -> t array -> t = "concat" -[@@mel.send] [@@mel.splice] -(** [concat arr original] returns a new string consisting of each item of an array of strings added to the [original] string. - -{[ - concatMany "1st" [|"2nd"; "3rd"; "4th"|] = "1st2nd3rd4th";; -]} -*) - -external endsWith : t -> t -> bool = "endsWith" -[@@mel.send] -(** ES2015: - [endsWith substr str] returns [true] if the [str] ends with [substr], [false] otherwise. - -{[ - endsWith "Hello, World!" "World!" = true;; - endsWith "Hello, World!" "world!" = false;; (* case-sensitive *) - endsWith "Hello, World!" "World" = false;; (* exact match *) -]} -*) - -(** [endsWithFrom ending len str] returns [true] if the first [len] characters of [str] end with [ending], [false] otherwise. If [n] is greater than or equal to the length of [str], then it works like [endsWith]. (Honestly, this should have been named [endsWithAt], but oh well.) - -{[ - endsWithFrom "abcd" "cd" 4 = true;; - endsWithFrom "abcde" "cd" 3 = false;; - endsWithFrom "abcde" "cde" 99 = true;; - endsWithFrom "example.dat" "ple" 7 = true;; -]} -*) -external endsWithFrom : t -> t -> int -> bool = "endsWith" -[@@mel.send] -(** ES2015 *) - -(** - [includes searchValue s] returns [true] if [searchValue] is found anywhere within [s], [false] otherwise. - -{[ - includes "programmer" "gram" = true;; - includes "programmer" "er" = true;; - includes "programmer" "pro" = true;; - includes "programmer" "xyz" = false;; -]} -*) -external includes : t -> t -> bool = "includes" -[@@mel.send] -(** ES2015 *) - -(** - [includes searchValue start s] returns [true] if [searchValue] is found anywhere within [s] starting at character number [start] (where 0 is the first character), [false] otherwise. - -{[ - includesFrom "programmer" "gram" 1 = true;; - includesFrom "programmer" "gram" 4 = false;; - includesFrom {js|대한민국|js} {js|한|js} 1 = true;; -]} -*) -external includesFrom : t -> t -> int -> bool = "includes" -[@@mel.send] -(** ES2015 *) - -external indexOf : t -> t -> int = "indexOf" -[@@mel.send] -(** - [indexOf searchValue s] returns the position at which [searchValue] was first found within [s], or [-1] if [searchValue] is not in [s]. - -{[ - indexOf "bookseller" "ok" = 2;; - indexOf "bookseller" "sell" = 4;; - indexOf "beekeeper" "ee" = 1;; - indexOf "bookseller" "xyz" = -1;; -]} -*) - -external indexOfFrom : t -> t -> int -> int = "indexOf" -[@@mel.send] -(** - [indexOfFrom searchValue start s] returns the position at which [searchValue] was found within [s] starting at character position [start], or [-1] if [searchValue] is not found in that portion of [s]. The return value is relative to the beginning of the string, no matter where the search started from. - -{[ - indexOfFrom "bookseller" "ok" 1 = 2;; - indexOfFrom "bookseller" "sell" 2 = 4;; - indexOfFrom "bookseller" "sell" 5 = -1;; - indexOf "bookseller" "xyz" = -1;; -]} -*) - -external lastIndexOf : t -> t -> int = "lastIndexOf" -[@@mel.send] -(** - [lastIndexOf searchValue s] returns the position of the {i last} occurrence of [searchValue] within [s], searching backwards from the end of the string. Returns [-1] if [searchValue] is not in [s]. The return value is always relative to the beginning of the string. - -{[ - lastIndexOf "bookseller" "ok" = 2;; - lastIndexOf "beekeeper" "ee" = 4;; - lastIndexOf "abcdefg" "xyz" = -1;; -]} -*) - -external lastIndexOfFrom : t -> t -> int -> int = "lastIndexOf" -[@@mel.send] -(** - [lastIndexOfFrom searchValue start s] returns the position of the {i last} occurrence of [searchValue] within [s], searching backwards from the given [start] position. Returns [-1] if [searchValue] is not in [s]. The return value is always relative to the beginning of the string. - -{[ - lastIndexOfFrom "bookseller" "ok" 6 = 2;; - lastIndexOfFrom "beekeeper" "ee" 8 = 4;; - lastIndexOfFrom "beekeeper" "ee" 3 = 1;; - lastIndexOfFrom "abcdefg" "xyz" 4 = -1;; -]} -*) - -(* extended by ECMA-402 *) - -external localeCompare : t -> t -> float = "localeCompare" -[@@mel.send] -(** - [localeCompare comparison reference] returns - -{ul - {- a negative value if [reference] comes before [comparison] in sort order} - {- zero if [reference] and [comparison] have the same sort order} - {- a positive value if [reference] comes after [comparison] in sort order}} - -{[ - (localeCompare "zebra" "ant") > 0.0;; - (localeCompare "ant" "zebra") < 0.0;; - (localeCompare "cat" "cat") = 0.0;; - (localeCompare "CAT" "cat") > 0.0;; -]} -*) - -external match_ : t -> Js_re.t -> t option array option = "match" -[@@mel.send] [@@mel.return { null_to_opt }] -(** - [match regexp str] matches a string against the given [regexp]. If there is no match, it returns [None]. - For regular expressions without the [g] modifier, if there is a match, the return value is [Some array] where the array contains: - - {ul - {- The entire matched string} - {- Any capture groups if the [regexp] had parentheses} - } - - For regular expressions with the [g] modifier, a matched expression returns [Some array] with all the matched substrings and no capture groups. - -{[ - match "The better bats" [%re "/b[aeiou]t/"] = Some [|"bet"|] - match "The better bats" [%re "/b[aeiou]t/g"] = Some [|"bet";"bat"|] - match "Today is 2018-04-05." [%re "/(\\d+)-(\\d+)-(\\d+)/"] = Some [|"2018-04-05"; "2018"; "04"; "05"|] - match "The large container." [%re "/b[aeiou]g/"] = None -]} - -*) - -(** [normalize str] returns the normalized Unicode string using Normalization Form Canonical (NFC) Composition. - -Consider the character [ã], which can be represented as the single codepoint [\u00e3] or the combination of a lower case letter A [\u0061] and a combining tilde [\u0303]. Normalization ensures that both can be stored in an equivalent binary representation. - -@see Unicode technical report for details -*) -external normalize : t -> t = "normalize" -[@@mel.send] -(** ES2015 *) - -external normalizeByForm : t -> t -> t = "normalize" -[@@mel.send] -(** - [normalize str form] (ES2015) returns the normalized Unicode string using the specified form of normalization, which may be one of: - - {ul - {- "NFC" — Normalization Form Canonical Composition.} - {- "NFD" — Normalization Form Canonical Decomposition.} - {- "NFKC" — Normalization Form Compatibility Composition.} - {- "NFKD" — Normalization Form Compatibility Decomposition.} - } - - @see Unicode technical report for details -*) - -(** - [repeat n s] returns a string that consists of [n] repetitions of [s]. Raises [RangeError] if [n] is negative. - -{[ - repeat "ha" 3 = "hahaha" - repeat "empty" 0 = "" -]} -*) -external repeat : t -> int -> t = "repeat" -[@@mel.send] -(** ES2015 *) - -external replace : t -> t -> t -> t = "replace" -[@@mel.send] -(** [replace substr newSubstr string] returns a new string which is -identical to [string] except with the first matching instance of [substr] -replaced by [newSubstr]. - -[substr] is treated as a verbatim string to match, not a regular -expression. - -{[ - replace "old string" "old" "new" = "new string" - replace "the cat and the dog" "the" "this" = "this cat and the dog" -]} -*) - -external replaceByRe : t -> Js_re.t -> t -> t = "replace" -[@@mel.send] -(** [replaceByRe regex replacement string] returns a new string where occurrences matching [regex] -have been replaced by [replacement]. - -{[ - replaceByRe "vowels be gone" [%re "/[aeiou]/g"] "x" = "vxwxls bx gxnx" - replaceByRe "Juan Fulano" [%re "/(\\w+) (\\w+)/"] "$2, $1" = "Fulano, Juan" -]} -*) - -external unsafeReplaceBy0 : - t -> Js_re.t -> ((t -> int -> t -> t)[@mel.uncurry]) -> t = "replace" -[@@mel.send] -(** returns a new string with some or all matches of a pattern with no capturing -parentheses replaced by the value returned from the given function. -The function receives as its parameters the matched string, the offset at which the -match begins, and the whole string being matched - -{[ -let str = "beautiful vowels" -let re = [%re "/[aeiou]/g"] -let matchFn matchPart offset wholeString = - Js.String2.toUpperCase matchPart - -let replaced = Js.String2.unsafeReplaceBy0 str re matchFn - -let () = Js.log replaced (* prints "bEAUtifUl vOwEls" *) -]} - -@see MDN -*) - -external unsafeReplaceBy1 : - t -> Js_re.t -> ((t -> t -> int -> t -> t)[@mel.uncurry]) -> t = "replace" -[@@mel.send] -(** returns a new string with some or all matches of a pattern with one set of capturing -parentheses replaced by the value returned from the given function. -The function receives as its parameters the matched string, the captured string, -the offset at which the match begins, and the whole string being matched. - -{[ -let str = "increment 23" -let re = [%re "/increment (\\d+)/g"] -let matchFn matchPart p1 offset wholeString = - wholeString ^ " is " ^ (string_of_int ((int_of_string p1) + 1)) - -let replaced = Js.String2.unsafeReplaceBy1 str re matchFn - -let () = Js.log replaced (* prints "increment 23 is 24" *) -]} - -@see MDN -*) - -external unsafeReplaceBy2 : - t -> Js_re.t -> ((t -> t -> t -> int -> t -> t)[@mel.uncurry]) -> t - = "replace" -[@@mel.send] -(** returns a new string with some or all matches of a pattern with two sets of capturing -parentheses replaced by the value returned from the given function. -The function receives as its parameters the matched string, the captured strings, -the offset at which the match begins, and the whole string being matched. - -{[ -let str = "7 times 6" -let re = [%re "/(\\d+) times (\\d+)/"] -let matchFn matchPart p1 p2 offset wholeString = - string_of_int ((int_of_string p1) * (int_of_string p2)) - -let replaced = Js.String2.unsafeReplaceBy2 str re matchFn - -let () = Js.log replaced (* prints "42" *) -]} - -@see MDN -*) - -external unsafeReplaceBy3 : - t -> Js_re.t -> ((t -> t -> t -> t -> int -> t -> t)[@mel.uncurry]) -> t - = "replace" -[@@mel.send] -(** returns a new string with some or all matches of a pattern with three sets of capturing -parentheses replaced by the value returned from the given function. -The function receives as its parameters the matched string, the captured strings, -the offset at which the match begins, and the whole string being matched. - -@see MDN -*) - -external search : t -> Js_re.t -> int = "search" -[@@mel.send] -(** [search regexp str] returns the starting position of the first match of [regexp] in the given [str], or -1 if there is no match. - -{[ -search "testing 1 2 3" [%re "/\\d+/"] = 8;; -search "no numbers" [%re "/\\d+/"] = -1;; -]} -*) - -external slice : t -> from:int -> to_:int -> t = "slice" -[@@mel.send] -(** [slice from:n1 to_:n2 str] returns the substring of [str] starting at character [n1] up to but not including [n2] - -If either [n1] or [n2] is negative, then it is evaluated as [length str - n1] (or [length str - n2]. - -If [n2] is greater than the length of [str], then it is treated as [length str]. - -If [n1] is greater than [n2], [slice] returns the empty string. - -{[ - slice "abcdefg" ~from:2 ~to_:5 == "cde";; - slice "abcdefg" ~from:2 ~to_:9 == "cdefg";; - slice "abcdefg" ~from:(-4) ~to_:(-2) == "de";; - slice "abcdefg" ~from:5 ~to_:1 == "";; -]} -*) - -external sliceToEnd : t -> from:int -> t = "slice" -[@@mel.send] -(** [sliceToEnd from: n str] returns the substring of [str] starting at character [n] to the end of the string - -If [n] is negative, then it is evaluated as [length str - n]. - -If [n] is greater than the length of [str], then [sliceToEnd] returns the empty string. - -{[ - sliceToEnd "abcdefg" ~from: 4 == "efg";; - sliceToEnd "abcdefg" ~from: (-2) == "fg";; - sliceToEnd "abcdefg" ~from: 7 == "";; -]} -*) - -external split : t -> t -> t array = "split" -[@@mel.send] -(** - [split delimiter str] splits the given [str] at every occurrence of [delimiter] and returns an - array of the resulting substrings. - -{[ - split "2018-01-02" "-" = [|"2018"; "01"; "02"|];; - split "a,b,,c" "," = [|"a"; "b"; ""; "c"|];; - split "good::bad as great::awful" "::" = [|"good"; "bad as great"; "awful"|];; - split "has-no-delimiter" ";" = [|"has-no-delimiter"|];; -]}; -*) - -external splitAtMost : t -> t -> limit:int -> t array = "split" -[@@mel.send] -(** - [splitAtMost delimiter ~limit: n str] splits the given [str] at every occurrence of [delimiter] and returns an array of the first [n] resulting substrings. If [n] is negative or greater than the number of substrings, the array will contain all the substrings. - -{[ - splitAtMost "ant/bee/cat/dog/elk" "/" ~limit: 3 = [|"ant"; "bee"; "cat"|];; - splitAtMost "ant/bee/cat/dog/elk" "/" ~limit: 0 = [| |];; - splitAtMost "ant/bee/cat/dog/elk" "/" ~limit: 9 = [|"ant"; "bee"; "cat"; "dog"; "elk"|];; -]} -*) - -external splitByRe : t -> Js_re.t -> t option array = "split" -[@@mel.send] -(** - [splitByRe regex str] splits the given [str] at every occurrence of [regex] and returns an - array of the resulting substrings. - -{[ - splitByRe "art; bed , cog ;dad" [%re "/\\s*[,;]\\s*/"] = [|"art"; "bed"; "cog"; "dad"|];; - splitByRe "has:no:match" [%re "/[,;]/"] = [|"has:no:match"|];; -]}; -*) - -external splitByReAtMost : t -> Js_re.t -> limit:int -> t option array = "split" -[@@mel.send] -(** - [splitByReAtMost regex ~limit: n str] splits the given [str] at every occurrence of [regex] and returns an - array of the first [n] resulting substrings. If [n] is negative or greater than the number of substrings, the array will contain all the substrings. - -{[ - splitByReAtMost "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit: 3 = [|"one"; "two"; "three"|];; - splitByReAtMost "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit: 0 = [| |];; - splitByReAtMost "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit: 8 = [|"one"; "two"; "three"; "four"|];; -]}; -*) - -external startsWith : t -> t -> bool = "startsWith" -[@@mel.send] -(** ES2015: - [startsWith substr str] returns [true] if the [str] starts with [substr], [false] otherwise. - -{[ - startsWith "Hello, World!" "Hello" = true;; - startsWith "Hello, World!" "hello" = false;; (* case-sensitive *) - startsWith "Hello, World!" "World" = false;; (* exact match *) -]} -*) - -external startsWithFrom : t -> t -> int -> bool = "startsWith" -[@@mel.send] -(** ES2015: - [startsWithFrom substr n str] returns [true] if the [str] starts with [substr] starting at position [n], [false] otherwise. If [n] is negative, the search starts at the beginning of [str]. - -{[ - startsWithFrom "Hello, World!" "Hello" 0 = true;; - startsWithFrom "Hello, World!" "World" 7 = true;; - startsWithFrom "Hello, World!" "World" 8 = false;; -]} -*) - -external substr : t -> from:int -> t = "substr" -[@@mel.send] -(** - [substr ~from: n str] returns the substring of [str] from position [n] to the end of the string. - - If [n] is less than zero, the starting position is the length of [str] - [n]. - - If [n] is greater than or equal to the length of [str], returns the empty string. - -{[ - substr "abcdefghij" ~from: 3 = "defghij" - substr "abcdefghij" ~from: (-3) = "hij" - substr "abcdefghij" ~from: 12 = "" -]} -*) - -external substrAtMost : t -> from:int -> length:int -> t = "substr" -[@@mel.send] -(** - [substrAtMost ~from: pos ~length: n str] returns the substring of [str] of length [n] starting at position [pos]. - - If [pos] is less than zero, the starting position is the length of [str] - [pos]. - - If [pos] is greater than or equal to the length of [str], returns the empty string. - - If [n] is less than or equal to zero, returns the empty string. - -{[ - substrAtMost "abcdefghij" ~from: 3 ~length: 4 = "defghij" - substrAtMost "abcdefghij" ~from: (-3) ~length: 4 = "hij" - substrAtMost "abcdefghij" ~from: 12 ~ length: 2 = "" -]} -*) - -external substring : t -> from:int -> to_:int -> t = "substring" -[@@mel.send] -(** - [substring ~from: start ~to_: finish str] returns characters [start] up to but not including [finish] from [str]. - - If [start] is less than zero, it is treated as zero. - - If [finish] is zero or negative, the empty string is returned. - - If [start] is greater than [finish], the start and finish points are swapped. - -{[ - substring "playground" ~from: 3 ~to_: 6 = "ygr";; - substring "playground" ~from: 6 ~to_: 3 = "ygr";; - substring "playground" ~from: 4 ~to_: 12 = "ground";; -]} -*) - -external substringToEnd : t -> from:int -> t = "substring" -[@@mel.send] -(** - [substringToEnd ~from: start str] returns the substring of [str] from position [start] to the end. - - If [start] is less than or equal to zero, the entire string is returned. - - If [start] is greater than or equal to the length of [str], the empty string is returned. - -{[ - substringToEnd "playground" ~from: 4 = "ground";; - substringToEnd "playground" ~from: (-3) = "playground";; - substringToEnd "playground" ~from: 12 = ""; -]} -*) - -external toLowerCase : t -> t = "toLowerCase" -[@@mel.send] -(** - [toLowerCase str] converts [str] to lower case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can give different results depending upon context, for example with the Greek letter sigma, which has two different lower case forms when it is the last character in a string or not. - -{[ - toLowerCase "ABC" = "abc";; - toLowerCase {js|ΣΠ|js} = {js|σπ|js};; - toLowerCase {js|ΠΣ|js} = {js|πς|js};; -]} -*) - -external toLocaleLowerCase : t -> t = "toLocaleLowerCase" -[@@mel.send] -(** - [toLocaleLowerCase str] converts [str] to lower case using the current locale -*) - -external toUpperCase : t -> t = "toUpperCase" -[@@mel.send] -(** - [toUpperCase str] converts [str] to upper case using the locale-insensitive case mappings in the Unicode Character Database. Notice that the conversion can expand the number of letters in the result; for example the German [ß] capitalizes to two [S]es in a row. - -{[ - toUpperCase "abc" = "ABC";; - toUpperCase {js|Straße|js} = {js|STRASSE|js};; - toLowerCase {js|πς|js} = {js|ΠΣ|js};; -]} -*) - -external toLocaleUpperCase : t -> t = "toLocaleUpperCase" -[@@mel.send] -(** - [toLocaleUpperCase str] converts [str] to upper case using the current locale -*) - -external trim : t -> t = "trim" -[@@mel.send] -(** - [trim str] returns a string that is [str] with whitespace stripped from both ends. Internal whitespace is not removed. - -{[ - trim " abc def " = "abc def" - trim "\n\r\t abc def \n\n\t\r " = "abc def" -]} -*) - -(* HTML wrappers *) - -(** - [anchor anchorName anchorText] creates a string with an HTML [] element with [name] attribute of [anchorName] and [anchorText] as its content. - -{[ - anchor "Page One" "page1" = "Page One" -]} -*) -external anchor : t -> t -> t = "anchor" -[@@mel.send] -(** ES2015 *) - -(** - [link urlText linkText] creates a string withan HTML [] element with [href] attribute of [urlText] and [linkText] as its content. - -{[ - link "Go to page two" "page2.html" = "Go to page two" -]} -*) -external link : t -> t -> t = "link" -[@@mel.send] -(** ES2015 *) - -external castToArrayLike : t -> t Js_array2.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/bs_string_test.ml b/jscomp/test/bs_string_test.ml index a31910d936..062814df72 100644 --- a/jscomp/test/bs_string_test.ml +++ b/jscomp/test/bs_string_test.ml @@ -10,10 +10,10 @@ let eq loc x y = let () = eq __LOC__ ("ghso ghso g" - |. Js.String2.split " " + |. Js.String.split ~sep:" " |. Js.Array2.reduce (fun x y -> x ^ "-" ^ y) "" ) "-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..942219b0a5 100644 --- a/jscomp/test/chn_test.ml +++ b/jscomp/test/chn_test.ml @@ -16,7 +16,7 @@ let convert (s : string) : int list = Js.Array2.fromMap (Js.String.castToArrayLike s) (fun x -> - match Js.String.codePointAt 0 x with + match Js.String.codePointAt ~pos:0 x with | None -> assert false | Some x -> x ) |> Array.to_list 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 f6fc420fb6..23583b6480 100644 --- a/jscomp/test/dist/jscomp/test/flow_parser_reg_test.js +++ b/jscomp/test/dist/jscomp/test/flow_parser_reg_test.js @@ -15547,6 +15547,255 @@ function parse(content, options) { string(param[1].name) ]]); }; + var _type = function (param) { + var t = param[1]; + var loc = param[0]; + if (typeof t === "number") { + switch (t) { + case /* Any */0 : + return node("AnyTypeAnnotation", loc, []); + case /* Void */1 : + return node("VoidTypeAnnotation", loc, []); + case /* Null */2 : + return node("NullTypeAnnotation", loc, []); + case /* Number */3 : + return node("NumberTypeAnnotation", loc, []); + case /* String */4 : + return node("StringTypeAnnotation", loc, []); + case /* Boolean */5 : + return node("BooleanTypeAnnotation", loc, []); + case /* Exists */6 : + return node("ExistsTypeAnnotation", loc, []); + + } + } else { + switch (t.TAG | 0) { + case /* Nullable */0 : + var t$1 = t._0; + return node("NullableTypeAnnotation", loc, [[ + "typeAnnotation", + _type(t$1) + ]]); + case /* Function */1 : + return function_type([ + loc, + t._0 + ]); + case /* Object */2 : + return object_type([ + loc, + t._0 + ]); + case /* Array */3 : + var t$2 = t._0; + return node("ArrayTypeAnnotation", loc, [[ + "elementType", + _type(t$2) + ]]); + case /* Generic */4 : + var param$1 = [ + loc, + t._0 + ]; + var g = param$1[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("GenericTypeAnnotation", param$1[0], [ + [ + "id", + id$1 + ], + [ + "typeParameters", + option(type_parameter_instantiation, g.typeParameters) + ] + ]); + case /* Union */5 : + var param$2 = [ + loc, + t._0 + ]; + return node("UnionTypeAnnotation", param$2[0], [[ + "types", + array_of_list(_type, param$2[1]) + ]]); + case /* Intersection */6 : + var param$3 = [ + loc, + t._0 + ]; + return node("IntersectionTypeAnnotation", param$3[0], [[ + "types", + array_of_list(_type, param$3[1]) + ]]); + case /* Typeof */7 : + var param$4 = [ + loc, + t._0 + ]; + return node("TypeofTypeAnnotation", param$4[0], [[ + "argument", + _type(param$4[1]) + ]]); + case /* Tuple */8 : + var param$5 = [ + loc, + t._0 + ]; + return node("TupleTypeAnnotation", param$5[0], [[ + "types", + array_of_list(_type, param$5[1]) + ]]); + case /* StringLiteral */9 : + var param$6 = [ + loc, + t._0 + ]; + var s = param$6[1]; + return node("StringLiteralTypeAnnotation", param$6[0], [ + [ + "value", + string(s.value) + ], + [ + "raw", + string(s.raw) + ] + ]); + case /* NumberLiteral */10 : + var param$7 = [ + loc, + t._0 + ]; + var s$1 = param$7[1]; + return node("NumberLiteralTypeAnnotation", param$7[0], [ + [ + "value", + number$1(s$1.value) + ], + [ + "raw", + string(s$1.raw) + ] + ]); + case /* BooleanLiteral */11 : + var param$8 = [ + loc, + t._0 + ]; + var s$2 = param$8[1]; + return node("BooleanLiteralTypeAnnotation", param$8[0], [ + [ + "value", + bool(s$2.value) + ], + [ + "raw", + string(s$2.raw) + ] + ]); + + } + } + }; + 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 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 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 + ] + ]; + } + if (exit === 1) { + props = [ + [ + "value", + value_ + ], + [ + "raw", + string(raw) + ] + ]; + } + return node("Literal", loc, props); + }; var identifier = function (param) { var id = param[1]; return node("Identifier", param[0], [ @@ -15564,24 +15813,54 @@ function parse(content, options) { ] ]); }; - var type_parameter_instantiation = function (param) { - return node("TypeParameterInstantiation", param[0], [[ - "params", - array_of_list(_type, param[1].params) - ]]); - }; - var export_specifier = function (param) { - var specifier = param[1]; - return node("ExportSpecifier", param[0], [ - [ - "id", - identifier(specifier.id) - ], - [ - "name", - option(identifier, specifier.name) - ] - ]); + var pattern = function (param) { + var obj = param[1]; + var loc = param[0]; + switch (obj.TAG | 0) { + case /* Object */0 : + var obj$1 = obj._0; + return node("ObjectPattern", loc, [ + [ + "properties", + array_of_list(object_pattern_property, obj$1.properties) + ], + [ + "typeAnnotation", + option(type_annotation, obj$1.typeAnnotation) + ] + ]); + case /* Array */1 : + var arr = obj._0; + return node("ArrayPattern", loc, [ + [ + "elements", + array_of_list((function (param) { + return option(array_pattern_element, param); + }), arr.elements) + ], + [ + "typeAnnotation", + option(type_annotation, arr.typeAnnotation) + ] + ]); + case /* Assignment */2 : + var match = obj._0; + return node("AssignmentPattern", loc, [ + [ + "left", + pattern(match.left) + ], + [ + "right", + expression(match.right) + ] + ]); + case /* Identifier */3 : + return identifier(obj._0); + case /* Expression */4 : + return expression(obj._0); + + } }; var expression = function (param) { var arr = param[1]; @@ -16011,546 +16290,158 @@ function parse(content, options) { case /* Literal */19 : return literal([ loc, - arr._0 - ]); - case /* TemplateLiteral */20 : - return template_literal([ - loc, - arr._0 - ]); - case /* TaggedTemplate */21 : - var param$1 = [ - loc, - arr._0 - ]; - var tagged = param$1[1]; - return node("TaggedTemplateExpression", param$1[0], [ - [ - "tag", - expression(tagged.tag) - ], - [ - "quasi", - template_literal(tagged.quasi) - ] - ]); - case /* JSXElement */22 : - return jsx_element([ - loc, - arr._0 - ]); - case /* Class */23 : - var param$2 = [ - loc, - arr._0 - ]; - var c = param$2[1]; - return node("ClassExpression", param$2[0], [ - [ - "id", - option(identifier, c.id) - ], - [ - "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 /* TypeCast */24 : - var typecast = arr._0; - return node("TypeCastExpression", loc, [ - [ - "expression", - expression(typecast.expression) - ], - [ - "typeAnnotation", - type_annotation(typecast.typeAnnotation) - ] - ]); - - } - }; - var pattern = function (param) { - var obj = param[1]; - var loc = param[0]; - switch (obj.TAG | 0) { - case /* Object */0 : - var obj$1 = obj._0; - return node("ObjectPattern", loc, [ - [ - "properties", - array_of_list(object_pattern_property, obj$1.properties) - ], - [ - "typeAnnotation", - option(type_annotation, obj$1.typeAnnotation) - ] - ]); - case /* Array */1 : - var arr = obj._0; - return node("ArrayPattern", loc, [ - [ - "elements", - array_of_list((function (param) { - return option(array_pattern_element, param); - }), arr.elements) - ], - [ - "typeAnnotation", - option(type_annotation, arr.typeAnnotation) - ] - ]); - case /* Assignment */2 : - var match = obj._0; - return node("AssignmentPattern", loc, [ - [ - "left", - pattern(match.left) - ], - [ - "right", - expression(match.right) - ] - ]); - case /* Identifier */3 : - return identifier(obj._0); - case /* Expression */4 : - return expression(obj._0); - - } - }; - 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 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 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 _type = function (param) { - var t = param[1]; - var loc = param[0]; - if (typeof t === "number") { - switch (t) { - case /* Any */0 : - return node("AnyTypeAnnotation", loc, []); - case /* Void */1 : - return node("VoidTypeAnnotation", loc, []); - case /* Null */2 : - return node("NullTypeAnnotation", loc, []); - case /* Number */3 : - return node("NumberTypeAnnotation", loc, []); - case /* String */4 : - return node("StringTypeAnnotation", loc, []); - case /* Boolean */5 : - return node("BooleanTypeAnnotation", loc, []); - case /* Exists */6 : - return node("ExistsTypeAnnotation", loc, []); - - } - } else { - switch (t.TAG | 0) { - case /* Nullable */0 : - var t$1 = t._0; - return node("NullableTypeAnnotation", loc, [[ - "typeAnnotation", - _type(t$1) - ]]); - case /* Function */1 : - return function_type([ - loc, - t._0 - ]); - case /* Object */2 : - return object_type([ - loc, - t._0 - ]); - case /* Array */3 : - var t$2 = t._0; - return node("ArrayTypeAnnotation", loc, [[ - "elementType", - _type(t$2) - ]]); - case /* Generic */4 : - var param$1 = [ - loc, - t._0 - ]; - var g = param$1[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("GenericTypeAnnotation", param$1[0], [ - [ - "id", - id$1 - ], - [ - "typeParameters", - option(type_parameter_instantiation, g.typeParameters) - ] - ]); - case /* Union */5 : - var param$2 = [ - loc, - t._0 - ]; - return node("UnionTypeAnnotation", param$2[0], [[ - "types", - array_of_list(_type, param$2[1]) - ]]); - case /* Intersection */6 : - var param$3 = [ - loc, - t._0 - ]; - return node("IntersectionTypeAnnotation", param$3[0], [[ - "types", - array_of_list(_type, param$3[1]) - ]]); - case /* Typeof */7 : - var param$4 = [ - loc, - t._0 - ]; - return node("TypeofTypeAnnotation", param$4[0], [[ - "argument", - _type(param$4[1]) - ]]); - case /* Tuple */8 : - var param$5 = [ - loc, - t._0 - ]; - return node("TupleTypeAnnotation", param$5[0], [[ - "types", - array_of_list(_type, param$5[1]) - ]]); - case /* StringLiteral */9 : - var param$6 = [ - loc, - t._0 - ]; - var s = param$6[1]; - return node("StringLiteralTypeAnnotation", param$6[0], [ - [ - "value", - string(s.value) - ], - [ - "raw", - string(s.raw) - ] - ]); - case /* NumberLiteral */10 : - var param$7 = [ - loc, - t._0 - ]; - var s$1 = param$7[1]; - return node("NumberLiteralTypeAnnotation", param$7[0], [ - [ - "value", - number$1(s$1.value) - ], - [ - "raw", - string(s$1.raw) - ] - ]); - case /* BooleanLiteral */11 : - var param$8 = [ - loc, - t._0 - ]; - var s$2 = param$8[1]; - return node("BooleanLiteralTypeAnnotation", param$8[0], [ - [ - "value", - bool(s$2.value) - ], - [ - "raw", - string(s$2.raw) - ] - ]); - - } - } - }; - 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 - ] - ]; - } - if (exit === 1) { - props = [ - [ - "value", - value_ - ], - [ - "raw", - string(raw) - ] - ]; + arr._0 + ]); + case /* TemplateLiteral */20 : + return template_literal([ + loc, + arr._0 + ]); + case /* TaggedTemplate */21 : + var param$1 = [ + loc, + arr._0 + ]; + var tagged = param$1[1]; + return node("TaggedTemplateExpression", param$1[0], [ + [ + "tag", + expression(tagged.tag) + ], + [ + "quasi", + template_literal(tagged.quasi) + ] + ]); + case /* JSXElement */22 : + return jsx_element([ + loc, + arr._0 + ]); + case /* Class */23 : + var param$2 = [ + loc, + arr._0 + ]; + var c = param$2[1]; + return node("ClassExpression", param$2[0], [ + [ + "id", + option(identifier, c.id) + ], + [ + "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 /* TypeCast */24 : + var typecast = arr._0; + return node("TypeCastExpression", loc, [ + [ + "expression", + expression(typecast.expression) + ], + [ + "typeAnnotation", + type_annotation(typecast.typeAnnotation) + ] + ]); + } - return node("Literal", loc, props); }; - var type_annotation = function (param) { - return node("TypeAnnotation", param[0], [[ - "typeAnnotation", - _type(param[1]) + var type_parameter_instantiation = function (param) { + return node("TypeParameterInstantiation", param[0], [[ + "params", + array_of_list(_type, param[1].params) ]]); }; - var let_assignment = function (assignment) { - return obj([ + 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], [ [ - "id", - pattern(assignment.id) + "qualification", + qualification ], [ - "init", - option(expression, assignment.init) + "id", + identifier(q.id) ] ]); }; - 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_element = function (param) { - var element = param[1]; - return node("JSXElement", param[0], [ - [ - "openingElement", - jsx_opening(element.openingElement) - ], + var function_type_param = function (param) { + var param$1 = param[1]; + return node("FunctionTypeParam", param[0], [ [ - "closingElement", - option(jsx_closing, element.closingElement) + "name", + identifier(param$1.name) ], [ - "children", - array_of_list(jsx_child, element.children) - ] - ]); - }; - var template_literal = function (param) { - var value = param[1]; - return node("TemplateLiteral", param[0], [ - [ - "quasis", - array_of_list(template_element, value.quasis) + "typeAnnotation", + _type(param$1.typeAnnotation) ], [ - "expressions", - array_of_list(expression, value.expressions) + "optional", + bool(param$1.optional) ] ]); }; - var block = function (param) { - return node("BlockStatement", param[0], [[ - "body", - array_of_list(statement, param[1].body) + var type_parameter_declaration = function (param) { + return node("TypeParameterDeclaration", param[0], [[ + "params", + array_of_list(type_param, param[1].params) ]]); }; - 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) - ], + var function_type = function (param) { + var fn = param[1]; + return node("FunctionTypeAnnotation", param[0], [ [ "params", - array_of_list(pattern, _function.params) + array_of_list(function_type_param, fn.params) ], [ - "defaults", - array_of_list((function (param) { - return option(expression, param); - }), _function.defaults) + "returnType", + _type(fn.returnType) ], [ "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) + option(function_type_param, fn.rest) ], [ "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) + option(type_parameter_declaration, fn.typeParameters) ] ]); }; - var type_parameter_declaration = function (param) { - return node("TypeParameterDeclaration", param[0], [[ - "params", - array_of_list(type_param, param[1].params) + var type_annotation = function (param) { + return node("TypeAnnotation", param[0], [[ + "typeAnnotation", + _type(param[1]) ]]); }; - var object_property = function (param) { + var object_pattern_property = function (param) { if (param.TAG === /* Property */0) { var match = param._0; var prop = match[1]; @@ -16577,51 +16468,87 @@ function parse(content, options) { 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], [ + return node("PropertyPattern", match[0], [ [ "key", match$1[0] ], [ - "value", - expression(prop.value) - ], - [ - "kind", - string(kind) + "pattern", + pattern(prop.pattern) ], [ - "method", - bool(prop._method) + "computed", + bool(match$1[1]) ], [ "shorthand", bool(prop.shorthand) - ], - [ - "computed", - bool(match$1[1]) ] ]); } - var match$3 = param._0; - return node("SpreadProperty", match$3[0], [[ + 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", - expression(match$3[1].argument) + pattern(match[1].argument) + ]]); + }; + 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 block = function (param) { + return node("BlockStatement", param[0], [[ + "body", + array_of_list(statement, param[1].body) + ]]); + }; + 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 declare_variable = function (param) { + return node("DeclareVariable", param[0], [[ + "id", + identifier(param[1].id) ]]); }; var statement = function (param) { @@ -17144,29 +17071,6 @@ function parse(content, options) { } }; - 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 declare_function = function (param) { - return node("DeclareFunction", param[0], [[ - "id", - identifier(param[1].id) - ]]); - }; var interface_declaration = function (param) { var i = param[1]; return node("InterfaceDeclaration", param[0], [ @@ -17188,40 +17092,6 @@ function parse(content, options) { ] ]); }; - 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 export_specifiers = function (param) { if (param !== undefined) { if (param.TAG === /* ExportSpecifiers */0) { @@ -17236,29 +17106,6 @@ function parse(content, options) { return array([]); } }; - 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_variable = function (param) { - return node("DeclareVariable", param[0], [[ - "id", - identifier(param[1].id) - ]]); - }; var variable_declaration = function (param) { var $$var = param[1]; var match = $$var.kind; @@ -17286,90 +17133,110 @@ function parse(content, options) { ] ]); }; - var class_implements = function (param) { - var $$implements = param[1]; - return node("ClassImplements", param[0], [ + var declare_class = function (param) { + var d = param[1]; + return node("DeclareClass", param[0], [ [ "id", - identifier($$implements.id) + identifier(d.id) ], [ "typeParameters", - option(type_parameter_instantiation, $$implements.typeParameters) + option(type_parameter_declaration, d.typeParameters) + ], + [ + "body", + object_type(d.body) + ], + [ + "extends", + array_of_list(interface_extends, d.extends) ] ]); }; - var class_body = function (param) { - return node("ClassBody", param[0], [[ + var $$catch = function (param) { + var c = param[1]; + return node("CatchClause", param[0], [ + [ + "param", + pattern(c.param) + ], + [ + "guard", + option(expression, c.guard) + ], + [ "body", - array_of_list(class_element, param[1].body) - ]]); + block(c.body) + ] + ]); }; - 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 type_alias = function (param) { + var alias = param[1]; + return node("TypeAlias", param[0], [ [ - "qualification", - qualification + "id", + identifier(alias.id) + ], + [ + "typeParameters", + option(type_parameter_declaration, alias.typeParameters) ], + [ + "right", + _type(alias.right) + ] + ]); + }; + var let_assignment = function (assignment) { + return obj([ [ "id", - identifier(q.id) + pattern(assignment.id) + ], + [ + "init", + option(expression, assignment.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 declare_function = function (param) { + return node("DeclareFunction", param[0], [[ + "id", + identifier(param[1].id) ]]); }; - 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], [ + var comprehension_block = function (param) { + var b = param[1]; + return node("ComprehensionBlock", param[0], [ [ - "object", - _object + "left", + pattern(b.left) ], [ - "property", - jsx_identifier(member_expression.property) + "right", + expression(b.right) + ], + [ + "each", + bool(b.each) ] ]); }; - var jsx_namespaced_name = function (param) { - var namespaced_name = param[1]; - return node("JSXNamespacedName", param[0], [ + var template_literal = function (param) { + var value = param[1]; + return node("TemplateLiteral", param[0], [ [ - "namespace", - jsx_identifier(namespaced_name.namespace) + "quasis", + array_of_list(template_element, value.quasis) ], - [ - "name", - jsx_identifier(namespaced_name.name) + [ + "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 object_pattern_property = function (param) { + var object_property = function (param) { if (param.TAG === /* Property */0) { var match = param._0; var prop = match[1]; @@ -17396,66 +17263,287 @@ function parse(content, options) { break; } - return node("PropertyPattern", match[0], [ + 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] ], [ - "pattern", - pattern(prop.pattern) + "value", + expression(prop.value) ], [ - "computed", - bool(match$1[1]) + "kind", + string(kind) + ], + [ + "method", + bool(prop._method) ], [ "shorthand", bool(prop.shorthand) + ], + [ + "computed", + bool(match$1[1]) ] ]); } - var match$2 = param._0; - return node("SpreadPropertyPattern", match$2[0], [[ + var match$3 = param._0; + return node("SpreadProperty", match$3[0], [[ "argument", - pattern(match$2[1].argument) + expression(match$3[1].argument) ]]); }; - var function_type = function (param) { - var fn = param[1]; - return node("FunctionTypeAnnotation", param[0], [ + 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 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 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], [ + [ + "key", + key + ], + [ + "value", + _type(prop.value) + ], + [ + "optional", + bool(prop.optional) + ], + [ + "static", + bool(prop.static) + ] + ]); + }; + var object_type_call_property = function (param) { + var callProperty = param[1]; + return node("ObjectTypeCallProperty", param[0], [ + [ + "value", + function_type(callProperty.value) + ], + [ + "static", + bool(callProperty.static) + ] + ]); + }; + var object_type_indexer = function (param) { + var indexer = param[1]; + return node("ObjectTypeIndexer", param[0], [ + [ + "id", + identifier(indexer.id) + ], + [ + "key", + _type(indexer.key) + ], + [ + "value", + _type(indexer.value) + ], + [ + "static", + bool(indexer.static) + ] + ]); + }; + 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 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 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 variable_declarator = function (param) { + var declarator = param[1]; + return node("VariableDeclarator", param[0], [ + [ + "id", + pattern(declarator.id) + ], + [ + "init", + option(expression, declarator.init) + ] + ]); + }; + 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], [ [ - "params", - array_of_list(function_type_param, fn.params) + "name", + string(tp.name) ], [ - "returnType", - _type(fn.returnType) + "bound", + option(type_annotation, tp.bound) ], [ - "rest", - option(function_type_param, fn.rest) + "variance", + option(variance, tp.variance) ], [ - "typeParameters", - option(type_parameter_declaration, fn.typeParameters) + "default", + option(_type, tp.default) ] ]); }; - var object_type = function (param) { - var o = param[1]; - return node("ObjectTypeAnnotation", param[0], [ - [ - "properties", - array_of_list(object_type_property, o.properties) - ], + var jsx_namespaced_name = function (param) { + var namespaced_name = param[1]; + return node("JSXNamespacedName", param[0], [ [ - "indexers", - array_of_list(object_type_indexer, o.indexers) + "namespace", + jsx_identifier(namespaced_name.namespace) ], [ - "callProperties", - array_of_list(object_type_call_property, o.callProperties) + "name", + jsx_identifier(namespaced_name.name) ] ]); }; @@ -17472,6 +17560,41 @@ function parse(content, options) { ]); } }; + 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 class_implements = function (param) { + var $$implements = param[1]; + return node("ClassImplements", param[0], [ + [ + "id", + identifier($$implements.id) + ], + [ + "typeParameters", + option(type_parameter_instantiation, $$implements.typeParameters) + ] + ]); + }; + var class_body = function (param) { + return node("ClassBody", param[0], [[ + "body", + array_of_list(class_element, param[1].body) + ]]); + }; var interface_extends = function (param) { var g = param[1]; var id = g.id; @@ -17488,16 +17611,33 @@ function parse(content, options) { ] ]); }; - var variable_declarator = function (param) { - var declarator = param[1]; - return node("VariableDeclarator", param[0], [ + 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 export_specifier = function (param) { + var specifier = param[1]; + return node("ExportSpecifier", param[0], [ [ "id", - pattern(declarator.id) + identifier(specifier.id) ], [ - "init", - option(expression, declarator.init) + "name", + option(identifier, specifier.name) ] ]); }; @@ -17620,6 +17760,12 @@ function parse(content, options) { ]); } }; + var jsx_closing = function (param) { + return node("JSXClosingElement", param[0], [[ + "name", + jsx_name(param[1].name) + ]]); + }; var jsx_opening = function (param) { var opening = param[1]; return node("JSXOpeningElement", param[0], [ @@ -17637,12 +17783,6 @@ function parse(content, options) { ] ]); }; - var jsx_closing = function (param) { - return node("JSXClosingElement", param[0], [[ - "name", - jsx_name(param[1].name) - ]]); - }; var jsx_child = function (param) { var element = param[1]; var loc = param[0]; @@ -17676,146 +17816,6 @@ function parse(content, options) { } }; - 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 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], [ - [ - "key", - key - ], - [ - "value", - _type(prop.value) - ], - [ - "optional", - bool(prop.optional) - ], - [ - "static", - bool(prop.static) - ] - ]); - }; - var object_type_call_property = function (param) { - var callProperty = param[1]; - return node("ObjectTypeCallProperty", param[0], [ - [ - "value", - function_type(callProperty.value) - ], - [ - "static", - bool(callProperty.static) - ] - ]); - }; - var object_type_indexer = function (param) { - var indexer = param[1]; - return node("ObjectTypeIndexer", param[0], [ - [ - "id", - identifier(indexer.id) - ], - [ - "key", - _type(indexer.key) - ], - [ - "value", - _type(indexer.value) - ], - [ - "static", - bool(indexer.static) - ] - ]); - }; - 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 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], [ - [ - "name", - string(tp.name) - ], - [ - "bound", - option(type_annotation, tp.bound) - ], - [ - "variance", - option(variance, tp.variance) - ], - [ - "default", - option(_type, tp.default) - ] - ]); - }; var program$2 = function (param) { return node("Program", param[0], [ [ diff --git a/jscomp/test/dist/jscomp/test/js_string_test.js b/jscomp/test/dist/jscomp/test/js_string_test.js index 93a20379ae..0ea63b6a5f 100644 --- a/jscomp/test/dist/jscomp/test/js_string_test.js +++ b/jscomp/test/dist/jscomp/test/js_string_test.js @@ -481,6 +481,7 @@ var suites_1 = { hd: [ "splitByRe", (function (param) { + var arg = /(#)(:)?/; return { TAG: /* Eq */0, _0: [ @@ -492,7 +493,9 @@ var suites_1 = { ":", "c" ], - _1: "a#b#:c".split(/(#)(:)?/) + _1: (function (param) { + return param.split(arg); + })("a#b#:c") }; }) ], @@ -500,6 +503,7 @@ var suites_1 = { hd: [ "splitByReAtMost", (function (param) { + var arg = /(#)(:)?/; return { TAG: /* Eq */0, _0: [ @@ -507,7 +511,9 @@ var suites_1 = { "#", undefined ], - _1: "a#b#:c".split(/(#)(:)?/, 3) + _1: (function (param) { + return param.split(arg, 3); + })("a#b#:c") }; }) ], @@ -656,7 +662,7 @@ var suites_1 = { ], tl: { hd: [ - "File \"jscomp/test/js_string_test.ml\", line 214, characters 4-11", + "File \"jscomp/test/js_string_test.ml\", line 222, characters 4-11", (function (param) { return { TAG: /* Ok */4, diff --git a/jscomp/test/dist/jscomp/test/ocaml_parsetree_test.js b/jscomp/test/dist/jscomp/test/ocaml_parsetree_test.js index 55f95a32c1..ef1bf95919 100644 --- a/jscomp/test/dist/jscomp/test/ocaml_parsetree_test.js +++ b/jscomp/test/dist/jscomp/test/ocaml_parsetree_test.js @@ -12796,67 +12796,6 @@ function token(lexbuf) { }; } -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; - while(true) { - var __ocaml_lex_state = ___ocaml_lex_state; - var __ocaml_lex_state$1 = Stdlib__Lexing.new_engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf); - switch (__ocaml_lex_state$1) { - case 0 : - return ; - case 1 : - var space = Stdlib__Lexing.sub_lexeme(lexbuf, Caml_array.get(lexbuf.lex_mem, 0), lexbuf.lex_curr_pos); - update_loc(lexbuf, undefined, 1, false, space.length); - return string(lexbuf); - case 2 : - store_string_char(char_for_backslash(Stdlib__Lexing.lexeme_char(lexbuf, 1))); - return string(lexbuf); - case 3 : - store_string_char(char_for_decimal_code(lexbuf, 1)); - return string(lexbuf); - case 4 : - store_string_char(char_for_hexadecimal_code(lexbuf, 2)); - return string(lexbuf); - case 5 : - if (Caml_obj.caml_notequal(comment_start_loc.contents, /* [] */0)) { - return string(lexbuf); - } - var loc = curr(lexbuf); - prerr_warning(loc, /* Illegal_backslash */7); - store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); - store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 1)); - return string(lexbuf); - case 6 : - if (!Caml_obj.caml_notequal(comment_start_loc.contents, /* [] */0)) { - prerr_warning(curr(lexbuf), /* Eol_in_string */14); - } - update_loc(lexbuf, undefined, 1, false, 0); - store_string(Stdlib__Lexing.lexeme(lexbuf)); - return string(lexbuf); - case 7 : - is_in_string.contents = false; - throw { - MEL_EXN_ID: $$Error$2, - _1: /* Unterminated_string */0, - _2: string_start_loc.contents, - Error: new Error() - }; - case 8 : - store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); - return string(lexbuf); - default: - Curry._1(lexbuf.refill_buff, lexbuf); - ___ocaml_lex_state = __ocaml_lex_state$1; - continue ; - } - }; -} - function __ocaml_lex_comment_rec(lexbuf, ___ocaml_lex_state) { while(true) { var __ocaml_lex_state = ___ocaml_lex_state; @@ -13042,6 +12981,67 @@ function __ocaml_lex_comment_rec(lexbuf, ___ocaml_lex_state) { }; } +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; + while(true) { + var __ocaml_lex_state = ___ocaml_lex_state; + var __ocaml_lex_state$1 = Stdlib__Lexing.new_engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf); + switch (__ocaml_lex_state$1) { + case 0 : + return ; + case 1 : + var space = Stdlib__Lexing.sub_lexeme(lexbuf, Caml_array.get(lexbuf.lex_mem, 0), lexbuf.lex_curr_pos); + update_loc(lexbuf, undefined, 1, false, space.length); + return string(lexbuf); + case 2 : + store_string_char(char_for_backslash(Stdlib__Lexing.lexeme_char(lexbuf, 1))); + return string(lexbuf); + case 3 : + store_string_char(char_for_decimal_code(lexbuf, 1)); + return string(lexbuf); + case 4 : + store_string_char(char_for_hexadecimal_code(lexbuf, 2)); + return string(lexbuf); + case 5 : + if (Caml_obj.caml_notequal(comment_start_loc.contents, /* [] */0)) { + return string(lexbuf); + } + var loc = curr(lexbuf); + prerr_warning(loc, /* Illegal_backslash */7); + store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); + store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 1)); + return string(lexbuf); + case 6 : + if (!Caml_obj.caml_notequal(comment_start_loc.contents, /* [] */0)) { + prerr_warning(curr(lexbuf), /* Eol_in_string */14); + } + update_loc(lexbuf, undefined, 1, false, 0); + store_string(Stdlib__Lexing.lexeme(lexbuf)); + return string(lexbuf); + case 7 : + is_in_string.contents = false; + throw { + MEL_EXN_ID: $$Error$2, + _1: /* Unterminated_string */0, + _2: string_start_loc.contents, + Error: new Error() + }; + case 8 : + store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); + return string(lexbuf); + default: + Curry._1(lexbuf.refill_buff, lexbuf); + ___ocaml_lex_state = __ocaml_lex_state$1; + continue ; + } + }; +} + function __ocaml_lex_quoted_string_rec(delim, lexbuf, ___ocaml_lex_state) { while(true) { var __ocaml_lex_state = ___ocaml_lex_state; diff --git a/jscomp/test/dist/jscomp/test/ocaml_typedtree_test.js b/jscomp/test/dist/jscomp/test/ocaml_typedtree_test.js index f26d384719..4986f6b04f 100644 --- a/jscomp/test/dist/jscomp/test/ocaml_typedtree_test.js +++ b/jscomp/test/dist/jscomp/test/ocaml_typedtree_test.js @@ -24966,102 +24966,6 @@ 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 string(lexbuf) { - lexbuf.lex_mem = Caml_array.make(2, -1); - var ___ocaml_lex_state = 164; - while(true) { - var __ocaml_lex_state = ___ocaml_lex_state; - var __ocaml_lex_state$1 = Stdlib__Lexing.new_engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf); - switch (__ocaml_lex_state$1) { - case 0 : - return ; - case 1 : - var space = Stdlib__Lexing.sub_lexeme(lexbuf, Caml_array.get(lexbuf.lex_mem, 0), lexbuf.lex_curr_pos); - update_loc(lexbuf, undefined, 1, false, space.length); - return string(lexbuf); - case 2 : - store_string_char(char_for_backslash(Stdlib__Lexing.lexeme_char(lexbuf, 1))); - return string(lexbuf); - case 3 : - store_string_char(char_for_decimal_code(lexbuf, 1)); - return string(lexbuf); - case 4 : - store_string_char(char_for_hexadecimal_code(lexbuf, 2)); - return string(lexbuf); - case 5 : - if (Caml_obj.caml_notequal(comment_start_loc.contents, /* [] */0)) { - return string(lexbuf); - } - var loc = curr(lexbuf); - prerr_warning(loc, /* Illegal_backslash */7); - store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); - store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 1)); - return string(lexbuf); - case 6 : - if (!Caml_obj.caml_notequal(comment_start_loc.contents, /* [] */0)) { - prerr_warning(curr(lexbuf), /* Eol_in_string */14); - } - update_loc(lexbuf, undefined, 1, false, 0); - store_string(Stdlib__Lexing.lexeme(lexbuf)); - return string(lexbuf); - case 7 : - is_in_string.contents = false; - throw { - MEL_EXN_ID: $$Error$4, - _1: /* Unterminated_string */0, - _2: string_start_loc.contents, - Error: new Error() - }; - case 8 : - store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); - return string(lexbuf); - default: - Curry._1(lexbuf.refill_buff, lexbuf); - ___ocaml_lex_state = __ocaml_lex_state$1; - continue ; - } - }; -} - function __ocaml_lex_comment_rec(lexbuf, ___ocaml_lex_state) { while(true) { var __ocaml_lex_state = ___ocaml_lex_state; @@ -25251,6 +25155,102 @@ 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; + while(true) { + var __ocaml_lex_state = ___ocaml_lex_state; + var __ocaml_lex_state$1 = Stdlib__Lexing.new_engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf); + switch (__ocaml_lex_state$1) { + case 0 : + return ; + case 1 : + var space = Stdlib__Lexing.sub_lexeme(lexbuf, Caml_array.get(lexbuf.lex_mem, 0), lexbuf.lex_curr_pos); + update_loc(lexbuf, undefined, 1, false, space.length); + return string(lexbuf); + case 2 : + store_string_char(char_for_backslash(Stdlib__Lexing.lexeme_char(lexbuf, 1))); + return string(lexbuf); + case 3 : + store_string_char(char_for_decimal_code(lexbuf, 1)); + return string(lexbuf); + case 4 : + store_string_char(char_for_hexadecimal_code(lexbuf, 2)); + return string(lexbuf); + case 5 : + if (Caml_obj.caml_notequal(comment_start_loc.contents, /* [] */0)) { + return string(lexbuf); + } + var loc = curr(lexbuf); + prerr_warning(loc, /* Illegal_backslash */7); + store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); + store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 1)); + return string(lexbuf); + case 6 : + if (!Caml_obj.caml_notequal(comment_start_loc.contents, /* [] */0)) { + prerr_warning(curr(lexbuf), /* Eol_in_string */14); + } + update_loc(lexbuf, undefined, 1, false, 0); + store_string(Stdlib__Lexing.lexeme(lexbuf)); + return string(lexbuf); + case 7 : + is_in_string.contents = false; + throw { + MEL_EXN_ID: $$Error$4, + _1: /* Unterminated_string */0, + _2: string_start_loc.contents, + Error: new Error() + }; + case 8 : + store_string_char(Stdlib__Lexing.lexeme_char(lexbuf, 0)); + return string(lexbuf); + default: + Curry._1(lexbuf.refill_buff, lexbuf); + ___ocaml_lex_state = __ocaml_lex_state$1; + continue ; + } + }; +} + +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; @@ -26198,15 +26198,13 @@ function TypedtreeMap_MakeMap(funarg) { str_env: item$1.str_env }); }; - 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_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_core_type = function (ct) { var ct$1 = Curry._1(funarg.enter_core_type, ct); @@ -26338,107 +26336,465 @@ function TypedtreeMap_MakeMap(funarg) { 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; - + var map_package_type = function (pack) { + var pack$1 = Curry._1(funarg.enter_package_type, pack); + var pack_fields = Stdlib__List.map((function (param) { + return [ + param[0], + map_core_type(param[1]) + ]; + }), pack$1.pack_fields); + return Curry._1(funarg.leave_package_type, { + pack_path: pack$1.pack_path, + pack_fields: pack_fields, + pack_type: pack$1.pack_type, + pack_txt: pack$1.pack_txt + }); + }; + var map_row_field = function (rf) { + if (rf.TAG === /* Ttag */0) { + return { + TAG: /* Ttag */0, + _0: rf._0, + _1: rf._1, + _2: rf._2, + _3: Stdlib__List.map(map_core_type, rf._3) + }; + } else { + return { + TAG: /* Tinherit */1, + _0: map_core_type(rf._0) + }; } - 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_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_signature_item = function (item) { - var item$1 = Curry._1(funarg.enter_signature_item, item); - var vd = item$1.sig_desc; - var sig_desc; - switch (vd.TAG | 0) { - case /* Tsig_value */0 : - sig_desc = { - TAG: /* Tsig_value */0, - _0: map_value_description(vd._0) + var map_class_field = function (cf) { + var cf$1 = Curry._1(funarg.enter_class_field, cf); + var exp = cf$1.cf_desc; + var cf_desc; + switch (exp.TAG | 0) { + case /* Tcf_inherit */0 : + cf_desc = { + TAG: /* Tcf_inherit */0, + _0: exp._0, + _1: map_class_expr(exp._1), + _2: exp._2, + _3: exp._3, + _4: exp._4 }; break; - case /* Tsig_type */1 : - sig_desc = { - TAG: /* Tsig_type */1, - _0: Stdlib__List.map(map_type_declaration, vd._0) + case /* Tcf_val */1 : + var cty = exp._3; + var ident = exp._2; + var mut = exp._1; + var lab = exp._0; + cf_desc = cty.TAG === /* Tcfk_virtual */0 ? ({ + TAG: /* Tcf_val */1, + _0: lab, + _1: mut, + _2: ident, + _3: { + TAG: /* Tcfk_virtual */0, + _0: map_core_type(cty._0) + }, + _4: exp._4 + }) : ({ + TAG: /* Tcf_val */1, + _0: lab, + _1: mut, + _2: ident, + _3: { + TAG: /* Tcfk_concrete */1, + _0: cty._0, + _1: map_expression(cty._1) + }, + _4: exp._4 + }); + break; + case /* Tcf_method */2 : + var cty$1 = exp._2; + var priv = exp._1; + var lab$1 = exp._0; + cf_desc = cty$1.TAG === /* Tcfk_virtual */0 ? ({ + TAG: /* Tcf_method */2, + _0: lab$1, + _1: priv, + _2: { + TAG: /* Tcfk_virtual */0, + _0: map_core_type(cty$1._0) + } + }) : ({ + TAG: /* Tcf_method */2, + _0: lab$1, + _1: priv, + _2: { + TAG: /* Tcfk_concrete */1, + _0: cty$1._0, + _1: map_expression(cty$1._1) + } + }); + break; + case /* Tcf_constraint */3 : + cf_desc = { + TAG: /* Tcf_constraint */3, + _0: map_core_type(exp._0), + _1: map_core_type(exp._1) }; break; - case /* Tsig_typext */2 : - sig_desc = { - TAG: /* Tsig_typext */2, - _0: map_type_extension(vd._0) + case /* Tcf_initializer */4 : + cf_desc = { + TAG: /* Tcf_initializer */4, + _0: map_expression(exp._0) }; break; - case /* Tsig_exception */3 : - sig_desc = { - TAG: /* Tsig_exception */3, - _0: map_extension_constructor(vd._0) + case /* Tcf_attribute */5 : + cf_desc = exp; + break; + + } + return Curry._1(funarg.leave_class_field, { + cf_desc: cf_desc, + cf_loc: cf$1.cf_loc, + cf_attributes: cf$1.cf_attributes + }); + }; + var map_module_type = function (mty) { + var mty$1 = Curry._1(funarg.enter_module_type, mty); + var sg = mty$1.mty_desc; + var mty_desc; + switch (sg.TAG | 0) { + case /* Tmty_signature */1 : + mty_desc = { + TAG: /* Tmty_signature */1, + _0: map_signature(sg._0) }; break; - case /* Tsig_module */4 : - var md = vd._0; - sig_desc = { - TAG: /* Tsig_module */4, - _0: { - md_id: md.md_id, - md_name: md.md_name, - md_type: map_module_type(md.md_type), - md_attributes: md.md_attributes, - md_loc: md.md_loc - } + case /* Tmty_functor */2 : + mty_desc = { + TAG: /* Tmty_functor */2, + _0: sg._0, + _1: sg._1, + _2: may_map(map_module_type, sg._2), + _3: map_module_type(sg._3) }; break; - case /* Tsig_recmodule */5 : - sig_desc = { - TAG: /* Tsig_recmodule */5, + case /* Tmty_with */3 : + mty_desc = { + TAG: /* Tmty_with */3, + _0: map_module_type(sg._0), + _1: Stdlib__List.map((function (param) { + return [ + param[0], + param[1], + map_with_constraint(param[2]) + ]; + }), sg._1) + }; + break; + case /* Tmty_typeof */4 : + mty_desc = { + TAG: /* Tmty_typeof */4, + _0: map_module_expr(sg._0) + }; + break; + case /* Tmty_ident */0 : + case /* Tmty_alias */5 : + mty_desc = mty$1.mty_desc; + break; + + } + return Curry._1(funarg.leave_module_type, { + mty_desc: mty_desc, + mty_type: mty$1.mty_type, + mty_env: mty$1.mty_env, + mty_loc: mty$1.mty_loc, + mty_attributes: mty$1.mty_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 + }; + } else { + ext_kind = { + TAG: /* Text_rebind */1, + _0: match._0, + _1: match._1 + }; + } + 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_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_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_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_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_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_signature_item = function (item) { + var item$1 = Curry._1(funarg.enter_signature_item, item); + var vd = item$1.sig_desc; + var sig_desc; + switch (vd.TAG | 0) { + case /* Tsig_value */0 : + sig_desc = { + TAG: /* Tsig_value */0, + _0: map_value_description(vd._0) + }; + break; + case /* Tsig_type */1 : + sig_desc = { + TAG: /* Tsig_type */1, + _0: Stdlib__List.map(map_type_declaration, vd._0) + }; + break; + case /* Tsig_typext */2 : + sig_desc = { + TAG: /* Tsig_typext */2, + _0: map_type_extension(vd._0) + }; + break; + case /* Tsig_exception */3 : + sig_desc = { + TAG: /* Tsig_exception */3, + _0: map_extension_constructor(vd._0) + }; + break; + case /* Tsig_module */4 : + var md = vd._0; + sig_desc = { + TAG: /* Tsig_module */4, + _0: { + md_id: md.md_id, + md_name: md.md_name, + md_type: map_module_type(md.md_type), + md_attributes: md.md_attributes, + md_loc: md.md_loc + } + }; + break; + case /* Tsig_recmodule */5 : + sig_desc = { + TAG: /* Tsig_recmodule */5, _0: Stdlib__List.map((function (md) { return { md_id: md.md_id, @@ -26494,32 +26850,258 @@ function TypedtreeMap_MakeMap(funarg) { sig_loc: item$1.sig_loc }); }; - 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), + var map_type_parameter = function (param) { + return [ + map_core_type(param[0]), + param[1] + ]; + }; + 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 /* Tcl_structure */1 : + cl_desc = { + TAG: /* Tcl_structure */1, + _0: map_class_structure(clstr._0) + }; + 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 + }; + 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) + }; + 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) + }; + 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 + }); + 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_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_with_constraint = function (cstr) { + var cstr$1 = Curry._1(funarg.enter_with_constraint, cstr); + var tmp; + switch (cstr$1.TAG | 0) { + case /* Twith_type */0 : + tmp = { + TAG: /* Twith_type */0, + _0: map_type_declaration(cstr$1._0) + }; + break; + case /* Twith_typesubst */2 : + tmp = { + TAG: /* Twith_typesubst */2, + _0: map_type_declaration(cstr$1._0) + }; + break; + case /* Twith_module */1 : + case /* Twith_modsubst */3 : + tmp = cstr$1; + break; + + } + return Curry._1(funarg.leave_with_constraint, tmp); + }; + 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_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_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_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; @@ -26725,756 +27307,174 @@ function TypedtreeMap_MakeMap(funarg) { exp_attributes: exp$1.exp_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_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_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) }; - break; - case /* Tcl_structure */1 : - cl_desc = { - TAG: /* Tcl_structure */1, - _0: map_class_structure(clstr._0) + }; + 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_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_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 /* 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 /* 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 /* 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 /* 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 /* 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 /* 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 /* 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 /* Tctf_attribute */4 : + ctf_desc = ct; 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 + 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_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_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_module_type = function (mty) { - var mty$1 = Curry._1(funarg.enter_module_type, mty); - var sg = mty$1.mty_desc; - var mty_desc; - switch (sg.TAG | 0) { - case /* Tmty_signature */1 : - mty_desc = { - TAG: /* Tmty_signature */1, - _0: map_signature(sg._0) - }; - break; - case /* Tmty_functor */2 : - mty_desc = { - TAG: /* Tmty_functor */2, - _0: sg._0, - _1: sg._1, - _2: may_map(map_module_type, sg._2), - _3: map_module_type(sg._3) - }; - break; - case /* Tmty_with */3 : - mty_desc = { - TAG: /* Tmty_with */3, - _0: map_module_type(sg._0), - _1: Stdlib__List.map((function (param) { - return [ - param[0], - param[1], - map_with_constraint(param[2]) - ]; - }), sg._1) - }; - break; - case /* Tmty_typeof */4 : - mty_desc = { - TAG: /* Tmty_typeof */4, - _0: map_module_expr(sg._0) - }; - break; - case /* Tmty_ident */0 : - case /* Tmty_alias */5 : - mty_desc = mty$1.mty_desc; - break; - - } - return Curry._1(funarg.leave_module_type, { - mty_desc: mty_desc, - mty_type: mty$1.mty_type, - mty_env: mty$1.mty_env, - mty_loc: mty$1.mty_loc, - mty_attributes: mty$1.mty_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_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_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_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_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 { - ext_kind = { - TAG: /* Text_rebind */1, - _0: match._0, - _1: match._1 - }; - } - 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_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_package_type = function (pack) { - var pack$1 = Curry._1(funarg.enter_package_type, pack); - var pack_fields = Stdlib__List.map((function (param) { - return [ - param[0], - map_core_type(param[1]) - ]; - }), pack$1.pack_fields); - return Curry._1(funarg.leave_package_type, { - pack_path: pack$1.pack_path, - pack_fields: pack_fields, - pack_type: pack$1.pack_type, - pack_txt: pack$1.pack_txt - }); - }; - var map_row_field = function (rf) { - if (rf.TAG === /* Ttag */0) { - return { - TAG: /* Ttag */0, - _0: rf._0, - _1: rf._1, - _2: rf._2, - _3: Stdlib__List.map(map_core_type, rf._3) - }; - } else { - return { - TAG: /* Tinherit */1, - _0: map_core_type(rf._0) - }; - } - }; - var map_type_parameter = function (param) { - return [ - map_core_type(param[0]), - param[1] - ]; - }; - 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_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_class_field = function (cf) { - var cf$1 = Curry._1(funarg.enter_class_field, cf); - var exp = cf$1.cf_desc; - var cf_desc; - switch (exp.TAG | 0) { - case /* Tcf_inherit */0 : - cf_desc = { - TAG: /* Tcf_inherit */0, - _0: exp._0, - _1: map_class_expr(exp._1), - _2: exp._2, - _3: exp._3, - _4: exp._4 - }; - break; - case /* Tcf_val */1 : - var cty = exp._3; - var ident = exp._2; - var mut = exp._1; - var lab = exp._0; - cf_desc = cty.TAG === /* Tcfk_virtual */0 ? ({ - TAG: /* Tcf_val */1, - _0: lab, - _1: mut, - _2: ident, - _3: { - TAG: /* Tcfk_virtual */0, - _0: map_core_type(cty._0) - }, - _4: exp._4 - }) : ({ - TAG: /* Tcf_val */1, - _0: lab, - _1: mut, - _2: ident, - _3: { - TAG: /* Tcfk_concrete */1, - _0: cty._0, - _1: map_expression(cty._1) - }, - _4: exp._4 - }); - break; - case /* Tcf_method */2 : - var cty$1 = exp._2; - var priv = exp._1; - var lab$1 = exp._0; - cf_desc = cty$1.TAG === /* Tcfk_virtual */0 ? ({ - TAG: /* Tcf_method */2, - _0: lab$1, - _1: priv, - _2: { - TAG: /* Tcfk_virtual */0, - _0: map_core_type(cty$1._0) - } - }) : ({ - TAG: /* Tcf_method */2, - _0: lab$1, - _1: priv, - _2: { - TAG: /* Tcfk_concrete */1, - _0: cty$1._0, - _1: map_expression(cty$1._1) - } - }); - break; - case /* Tcf_constraint */3 : - cf_desc = { - TAG: /* Tcf_constraint */3, - _0: map_core_type(exp._0), - _1: map_core_type(exp._1) - }; - break; - case /* Tcf_initializer */4 : - cf_desc = { - TAG: /* Tcf_initializer */4, - _0: map_expression(exp._0) - }; - break; - case /* Tcf_attribute */5 : - cf_desc = exp; - break; - - } - return Curry._1(funarg.leave_class_field, { - cf_desc: cf_desc, - cf_loc: cf$1.cf_loc, - cf_attributes: cf$1.cf_attributes - }); - }; - 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_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_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_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_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_with_constraint = function (cstr) { - var cstr$1 = Curry._1(funarg.enter_with_constraint, cstr); - var tmp; - switch (cstr$1.TAG | 0) { - case /* Twith_type */0 : - tmp = { - TAG: /* Twith_type */0, - _0: map_type_declaration(cstr$1._0) - }; - break; - case /* Twith_typesubst */2 : - tmp = { - TAG: /* Twith_typesubst */2, - _0: map_type_declaration(cstr$1._0) - }; - break; - case /* Twith_module */1 : - case /* Twith_modsubst */3 : - tmp = cstr$1; - break; - - } - return Curry._1(funarg.leave_with_constraint, tmp); - }; - 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_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_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_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 - }; - }; return { map_structure: map_structure, map_pattern: map_pattern, @@ -33165,1430 +33165,1430 @@ function unify(env, t1, t2) { Error: new Error() }; } - throw exn$1; - } -} - -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 make_rowvar(level, use1, rest1, use2, rest2) { - var set_name = function (ty, name) { - var match = ty.desc; - if (typeof match === "number" || !(match.TAG === /* Tvar */0 && match._0 === undefined)) { - return ; - } else { - log_type(ty); - ty.desc = { - TAG: /* Tvar */0, - _0: name - }; - return ; - } - }; - var match = rest1.desc; - var match$1 = rest2.desc; - var name; - var exit = 0; - if (typeof match === "number" || match.TAG !== /* Tvar */0) { - exit = 1; - } else { - var name1 = match._0; - if (name1 !== undefined) { - var exit$1 = 0; - if (typeof match$1 === "number" || match$1.TAG !== /* Tvar */0) { - exit$1 = 2; - } else { - var name2 = match$1._0; - if (name2 !== undefined) { - name = rest1.level <= rest2.level ? name1 : name2; - } else { - exit$1 = 2; - } - } - if (exit$1 === 2) { - if (use2) { - set_name(rest2, name1); - } - name = name1; - } - - } else { - exit = 1; - } - } - if (exit === 1) { - if (typeof match$1 === "number" || match$1.TAG !== /* Tvar */0) { - name = undefined; - } else { - var name$1 = match$1._0; - if (name$1 !== undefined) { - if (use1) { - set_name(rest2, name$1); - } - name = name$1; - } else { - name = undefined; - } - } - } - if (use1) { - return rest1; - } else if (use2) { - return rest2; - } else { - return newty2(level, { - TAG: /* Tvar */0, - _0: name - }); - } -} - -function unify_fields(env, ty1, ty2) { - var match = flatten_fields(ty1); - var rest1 = match[1]; - var match$1 = flatten_fields(ty2); - var rest2 = match$1[1]; - var match$2 = associate_fields(match[0], match$1[0]); - var miss2 = match$2[2]; - var miss1 = match$2[1]; - var l1 = repr(ty1).level; - var l2 = repr(ty2).level; - var va = make_rowvar(l1 < l2 ? l1 : l2, Caml_obj.caml_equal(miss2, /* [] */0), rest1, Caml_obj.caml_equal(miss1, /* [] */0), rest2); - var d1 = rest1.desc; - var d2 = rest2.desc; - try { - unify(env, build_fields(l1)(miss1, va), rest2); - unify(env, rest1, build_fields(l2)(miss2, va)); - return Stdlib__List.iter((function (param) { - var t2 = param[4]; - var k2 = param[3]; - var t1 = param[2]; - var k1 = param[1]; - var n = param[0]; - unify_kind(k1, k2); - try { - if (trace_gadt_instances.contents) { - update_level(env.contents, va.level, t1); - } - return unify(env, t1, t2); - } - catch (raw_exn){ - var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.MEL_EXN_ID === Unify) { - var desc_3 = newty2(current_level.contents, /* Tnil */0); - var desc = { - TAG: /* Tfield */5, - _0: n, - _1: k1, - _2: t1, - _3: desc_3 - }; - var desc_3$1 = newty2(current_level.contents, /* Tnil */0); - var desc$1 = { - TAG: /* Tfield */5, - _0: n, - _1: k2, - _2: t2, - _3: desc_3$1 - }; - throw { - 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; + throw exn$1; } } -function unify_list(env, tl1, tl2) { - if (Stdlib__List.length(tl1) !== Stdlib__List.length(tl2)) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; +function make_rowvar(level, use1, rest1, use2, rest2) { + var set_name = function (ty, name) { + var match = ty.desc; + if (typeof match === "number" || !(match.TAG === /* Tvar */0 && match._0 === undefined)) { + return ; + } else { + log_type(ty); + ty.desc = { + TAG: /* Tvar */0, + _0: name + }; + return ; + } + }; + var match = rest1.desc; + var match$1 = rest2.desc; + var name; + var exit = 0; + if (typeof match === "number" || match.TAG !== /* Tvar */0) { + exit = 1; + } else { + var name1 = match._0; + if (name1 !== undefined) { + var exit$1 = 0; + if (typeof match$1 === "number" || match$1.TAG !== /* Tvar */0) { + exit$1 = 2; + } else { + var name2 = match$1._0; + if (name2 !== undefined) { + name = rest1.level <= rest2.level ? name1 : name2; + } else { + exit$1 = 2; + } + } + if (exit$1 === 2) { + if (use2) { + set_name(rest2, name1); + } + name = name1; + } + + } else { + exit = 1; + } + } + if (exit === 1) { + if (typeof match$1 === "number" || match$1.TAG !== /* Tvar */0) { + name = undefined; + } else { + var name$1 = match$1._0; + if (name$1 !== undefined) { + if (use1) { + set_name(rest2, name$1); + } + name = name$1; + } else { + name = undefined; + } + } + } + if (use1) { + return rest1; + } else if (use2) { + return rest2; + } else { + return newty2(level, { + TAG: /* Tvar */0, + _0: name + }); } - Stdlib__List.iter2((function (param, param$1) { - return unify(env, param, param$1); - }), tl1, tl2); } -function unify_row(env, row1, row2) { - var row1$1 = row_repr_aux(/* [] */0, row1); - var row2$1 = row_repr_aux(/* [] */0, row2); - var rm1 = row_more(row1$1); - var rm2 = row_more(row2$1); - if (unify_eq(env.contents, rm1, rm2)) { +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 ; } - var match = merge_row_fields(row1$1.row_fields, row2$1.row_fields); - var pairs = match[2]; - var r2 = match[1]; - var r1 = match[0]; - if (Caml_obj.caml_notequal(r1, /* [] */0) && Caml_obj.caml_notequal(r2, /* [] */0)) { - var ht = Stdlib__Hashtbl.create(undefined, Stdlib__List.length(r1)); - Stdlib__List.iter((function (param) { - var l = param[0]; - Stdlib__Hashtbl.add(ht, hash_variant(l), l); - }), r1); - Stdlib__List.iter((function (param) { - var l = param[0]; - try { - throw { - MEL_EXN_ID: Tags, - _1: l, - _2: Stdlib__Hashtbl.find(ht, hash_variant(l)), - Error: new Error() - }; - } - catch (raw_exn){ - var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.MEL_EXN_ID === Stdlib.Not_found) { - return ; - } - throw exn; - } - }), r2); + 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); + } + } - var fixed1 = row_fixed(row1$1); - var fixed2 = row_fixed(row2$1); - var more = fixed1 ? rm1 : ( - fixed2 ? rm2 : newty2(rm1.level < rm2.level ? rm1.level : rm2.level, { - TAG: /* Tvar */0, - _0: undefined - }) - ); - var fixed = fixed1 || fixed2; - var closed = row1$1.row_closed || row2$1.row_closed; - var keep = function ($$switch) { - return Stdlib__List.for_all((function (param) { - var match = Curry._2($$switch, param[1], param[2]); - if (Caml_obj.caml_equal(row_field_repr_aux(/* [] */0, match[0]), /* Rabsent */0)) { - return true; - } else { - return Caml_obj.caml_notequal(row_field_repr_aux(/* [] */0, match[1]), /* Rabsent */0); - } - }), pairs); - }; - var empty = function (fields) { - return Stdlib__List.for_all((function (param) { - return Caml_obj.caml_equal(row_field_repr_aux(/* [] */0, param[1]), /* Rabsent */0); - }), fields); - }; - if (closed && (empty(r1) || row2$1.row_closed) && (empty(r2) || row1$1.row_closed) && Stdlib__List.for_all((function (param) { - if (Caml_obj.caml_equal(row_field_repr_aux(/* [] */0, param[1]), /* Rabsent */0)) { - return true; - } else { - return Caml_obj.caml_equal(row_field_repr_aux(/* [] */0, param[2]), /* Rabsent */0); + throw { + MEL_EXN_ID: "Assert_failure", + _1: [ + "jscomp/test/ocaml_typedtree_test.ml", + 32636, + 37 + ], + Error: new Error() + }; +} + +function unify3(env, t1, t1$p, t2, t2$p) { + var d1 = t1$p.desc; + var d2 = t2$p.desc; + var create_recursion = t2 !== t2$p && deep_occur(t1$p, t2); + var exit = 0; + var exit$1 = 0; + if (typeof d1 === "number") { + exit$1 = 2; + } else { + switch (d1.TAG | 0) { + case /* Tvar */0 : + occur(env.contents, t1$p, t2); + occur_univar(env.contents, t2); + return link_type(t1$p, t2); + case /* Tfield */5 : + if (typeof d2 === "number") { + exit = 1; + } else { + switch (d2.TAG | 0) { + case /* Tvar */0 : + exit$1 = 2; + break; + case /* Tfield */5 : + return unify_fields(env, t1$p, t2$p); + default: + exit = 1; } - }), pairs)) { - throw { - MEL_EXN_ID: Unify, - _1: { - hd: [ - mkvariant(/* [] */0, true), - mkvariant(/* [] */0, true) - ], - tl: /* [] */0 - }, - Error: new Error() - }; - } - var name = row1$1.row_name !== undefined && (row1$1.row_closed || empty(r2)) && (!row2$1.row_closed || keep(function (f1, f2) { - return [ - f1, - f2 - ]; - }) && empty(r1)) ? row1$1.row_name : ( - row2$1.row_name !== undefined && (row2$1.row_closed || empty(r1)) && (!row1$1.row_closed || keep(function (f1, f2) { - return [ - f2, - f1 - ]; - }) && empty(r2)) ? row2$1.row_name : undefined - ); - var set_more = function (row, rest) { - var rest$1 = closed ? filter_row_fields(row.row_closed, rest) : rest; - if (Caml_obj.caml_notequal(rest$1, /* [] */0) && (row.row_closed || row_fixed(row)) || closed && row_fixed(row) && !row.row_closed) { - var t1 = mkvariant(/* [] */0, true); - var t2 = mkvariant(rest$1, false); - throw { - MEL_EXN_ID: Unify, - _1: { - hd: row === row1$1 ? [ - t1, - t2 - ] : [ - t2, - t1 - ], - tl: /* [] */0 - }, - Error: new Error() - }; + } + break; + case /* Tunivar */9 : + if (typeof d2 === "number") { + exit = 1; + } else { + switch (d2.TAG | 0) { + case /* Tvar */0 : + exit$1 = 2; + break; + case /* Tunivar */9 : + unify_univar(t1$p, t2$p, univar_pairs.contents); + return link_type(t1$p, t2$p); + default: + exit = 1; + } + } + break; + default: + exit$1 = 2; } - var rm = row_more(row); - if (trace_gadt_instances.contents && Caml_obj.caml_equal(rm.desc, /* Tnil */0) || !trace_gadt_instances.contents) { - + } + if (exit$1 === 2) { + if (typeof d2 === "number") { + exit = 1; } else { - update_level(env.contents, rm.level, newty2(100000000, { - TAG: /* Tvariant */8, - _0: row - })); - } - if (row_fixed(row)) { - if (more === rm) { - return ; - } else if (is_Tvar(rm)) { - return link_type(rm, more); - } else { - return unify(env, rm, more); + if (d2.TAG === /* Tvar */0) { + occur(env.contents, t2$p, t1); + occur_univar(env.contents, t1); + return link_type(t2$p, t1); } + exit = 1; } - var ty = newty2(100000000, { - TAG: /* Tvariant */8, - _0: { - row_fields: rest$1, - row_more: more, - row_bound: undefined, - row_closed: closed, - row_fixed: fixed, - row_name: name + } + if (exit === 1) { + var match = umode.contents; + if (match) { + add_type_equality(t1$p, t2$p); + } else { + occur(env.contents, t1$p, t2$p); + link_type(t1$p, t2); + } + try { + var exit$2 = 0; + var f; + var kind; + var rem; + var exit$3 = 0; + var exit$4 = 0; + if (typeof d1 === "number") { + if (typeof d2 !== "number") { + switch (d2.TAG | 0) { + case /* Tconstr */3 : + exit$4 = 5; + break; + case /* Tfield */5 : + f = d2._0; + kind = d2._1; + rem = d2._3; + exit$2 = 3; + break; + default: + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; } - }); - update_level(env.contents, rm.level, ty); - link_type(rm, ty); - }; - var md1 = rm1.desc; - var md2 = rm2.desc; - try { - set_more(row2$1, r1); - set_more(row1$1, r2); - return Stdlib__List.iter((function (param) { - var f2 = param[2]; - var f1 = param[1]; - var l = param[0]; - try { - var _f1 = f1; - var _f2 = f2; - while(true) { - var f2$1 = _f2; - var f1$1 = _f1; - var f1$2 = row_field_repr_aux(/* [] */0, f1$1); - var f2$2 = row_field_repr_aux(/* [] */0, f2$1); - if (f1$2 === f2$2) { - return ; - } - if (typeof f1$2 === "number") { - if (typeof f2$2 === "number") { - return ; - } - if (f2$2.TAG === /* Rpresent */0) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; + } + + } else { + switch (d1.TAG | 0) { + case /* Tarrow */1 : + var l1 = d1._0; + if (typeof d2 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + switch (d2.TAG | 0) { + case /* Tarrow */1 : + var l2 = d2._0; + if (l1 === l2 || classic.contents && !(is_optional(l1) || is_optional(l2))) { + unify(env, d1._1, d2._1); + unify(env, d1._2, d2._2); + var match$1 = commu_repr(d1._3); + var match$2 = commu_repr(d2._3); + if (typeof match$1 === "number") { + if (typeof match$2 === "number") { + + } else { + set_commu(match$2._0, match$1); } - if (f2$2._2) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; + } else { + set_commu(match$1._0, match$2); + } + } else { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + break; + case /* Tconstr */3 : + exit$4 = 5; + break; + default: + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + break; + case /* Ttuple */2 : + if (typeof d2 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + switch (d2.TAG | 0) { + case /* Ttuple */2 : + unify_list(env, d1._0, d2._0); + break; + case /* Tconstr */3 : + exit$4 = 5; + break; + default: + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + break; + case /* Tconstr */3 : + var p1 = d1._0; + var exit$5 = 0; + if (typeof d2 === "number" || d2.TAG !== /* Tconstr */3) { + exit$5 = 6; + } else { + var tl2 = d2._1; + var tl1 = d1._1; + if (same(p1, d2._0)) { + if (umode.contents === /* Expression */0 || !generate_equations.contents) { + unify_list(env, tl1, tl2); + } else if (assume_injective.contents) { + set_mode_pattern(true, false, (function (param) { + unify_list(env, tl1, tl2); + })); + } else { + var tmp = true; + if (!in_current_module(p1)) { + var partial_arg = env.contents; + tmp = Stdlib__List.exists((function (param) { + return expands_to_datatype(partial_arg, param); + }), { + hd: t1$p, + tl: { + hd: t1, + tl: { + hd: t2, + tl: /* [] */0 + } + } + }); + } + if (tmp) { + unify_list(env, tl1, tl2); + } else { + var inj; + try { + inj = Stdlib__List.map(Curry._1(Types_Variance.mem, /* Inj */3), find_type_full(p1, env.contents)[0].type_variance); + } + catch (raw_exn){ + var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + if (exn.MEL_EXN_ID === Stdlib.Not_found) { + inj = Stdlib__List.map((function (param) { + return false; + }), tl1); + } else { + throw exn; } - if (!fixed2) { - return set_row_field(f2$2._3, f1$2); + } + Stdlib__List.iter2((function (i, param) { + var t2 = param[1]; + var t1 = param[0]; + if (i) { + return unify(env, t1, t2); + } else { + return set_mode_pattern(false, false, (function (param) { + var snap = snapshot(undefined); + try { + return unify(env, t1, t2); + } + catch (raw_exn){ + var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + if (exn.MEL_EXN_ID === Unify) { + backtrack(snap); + reify(env, t1); + return reify(env, t2); + } + throw exn; + } + })); + } + }), inj, Stdlib__List.combine(tl1, tl2)); + } + } + } else { + exit$5 = 6; + } + } + if (exit$5 === 6) { + switch (p1.TAG | 0) { + case /* Pident */0 : + if (d1._1) { + exit$4 = 5; + } else { + var p = p1._0; + var exit$6 = 0; + if (typeof d2 === "number" || d2.TAG !== /* Tconstr */3) { + exit$6 = 7; + } else { + var path$p = d2._0; + switch (path$p.TAG | 0) { + case /* Pident */0 : + if (d2._1 || !(is_newtype(env.contents, p1) && is_newtype(env.contents, path$p) && generate_equations.contents)) { + exit$6 = 7; + } else { + var match$3 = Caml_obj.caml_greaterthan(find_newtype_level(env.contents, p1), find_newtype_level(env.contents, path$p)) ? [ + p, + t2$p + ] : [ + path$p._0, + t1$p + ]; + add_gadt_equation(env, match$3[0], match$3[1]); + } + break; + case /* Pdot */1 : + case /* Papply */2 : + exit$6 = 7; + break; + + } } - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } else if (f1$2.TAG === /* Rpresent */0) { - var t1 = f1$2._0; - if (t1 !== undefined) { - if (typeof f2$2 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; + if (exit$6 === 7) { + if (is_newtype(env.contents, p1) && generate_equations.contents) { + reify(env, t2$p); + add_gadt_equation(env, p, t2$p); + } else { + exit$4 = 5; } - if (f2$2.TAG === /* Rpresent */0) { - var t2 = f2$2._0; - if (t2 !== undefined) { - return unify(env, t1, t2); + } + + } + break; + case /* Pdot */1 : + case /* Papply */2 : + exit$4 = 5; + break; + + } + } + break; + case /* Tobject */4 : + if (typeof d2 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + switch (d2.TAG | 0) { + case /* Tconstr */3 : + exit$4 = 5; + break; + case /* Tobject */4 : + unify_fields(env, d1._0, d2._0); + var match$4 = repr(t2$p).desc; + if (typeof match$4 !== "number" && match$4.TAG === /* Tobject */4) { + var exit$7 = 0; + var match$5 = match$4._1.contents; + if (match$5 !== undefined) { + var match$6 = match$5[1]; + if (match$6) { + var match$7 = repr(match$6.hd).desc; + var tmp$1; + if (typeof match$7 === "number") { + tmp$1 = true; + } else { + switch (match$7.TAG | 0) { + case /* Tvar */0 : + case /* Tunivar */9 : + tmp$1 = true; + break; + default: + tmp$1 = false; } - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (f2$2._0) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (fixed2) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - var e2 = f2$2._3; - set_row_field(e2, f1$2); - update_level(env.contents, repr(more).level, t1); - try { - return Stdlib__List.iter((function(t1){ - return function (param) { - return unify(env, t1, param); - } - }(t1)), f2$2._1); } - catch (exn){ - e2.contents = undefined; - throw exn; + if (!tmp$1) { + exit$7 = 6; } + } else { - if (typeof f2$2 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (f2$2.TAG === /* Rpresent */0) { - if (f2$2._0 === undefined) { - return ; - } - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (f2$2._0) { - if (f2$2._1) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (!fixed2) { - return set_row_field(f2$2._3, f1$2); - } - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; + exit$7 = 6; + } + } else { + exit$7 = 6; + } + if (exit$7 === 6) { + set_name(match$4._1, d1._1.contents); + } + + } + break; + default: + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + break; + case /* Tfield */5 : + if (typeof d2 === "number") { + f = d1._0; + kind = d1._1; + rem = d1._3; + exit$2 = 3; + } else if (d2.TAG === /* Tconstr */3) { + exit$4 = 5; + } else { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + break; + case /* Tvariant */8 : + var row1 = d1._0; + if (typeof d2 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + switch (d2.TAG | 0) { + case /* Tconstr */3 : + exit$4 = 5; + break; + case /* Tvariant */8 : + var row2 = d2._0; + if (umode.contents === /* Expression */0) { + unify_row(env, row1, row2); + } else { + var snap = snapshot(undefined); + try { + unify_row(env, row1, row2); + } + catch (raw_exn$1){ + var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); + if (exn$1.MEL_EXN_ID === Unify) { + backtrack(snap); + reify(env, t1$p); + reify(env, t2$p); + if (generate_equations.contents) { + mcomp$1(env.contents, t1$p, t2$p); } - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; + + } else { + throw exn$1; } + } + } + break; + default: + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + break; + case /* Tpoly */10 : + var tl1$1 = d1._1; + var t1$1 = d1._0; + var exit$8 = 0; + if (tl1$1) { + exit$8 = 6; + } else { + if (typeof d2 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + switch (d2.TAG | 0) { + case /* Tconstr */3 : + exit$4 = 5; + break; + case /* Tpoly */10 : + if (d2._1) { + exit$8 = 6; } else { - var c1 = f1$2._0; - var m1 = f1$2._2; - var tl1 = f1$2._1; - var e1 = f1$2._3; - if (typeof f2$2 === "number") { - if (m1) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (!fixed1) { - return set_row_field(f1$2._3, f2$2); - } + unify(env, t1$1, d2._0); + } + break; + default: + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + } + if (exit$8 === 6) { + if (typeof d2 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + switch (d2.TAG | 0) { + case /* Tconstr */3 : + exit$4 = 5; + break; + case /* Tpoly */10 : + enter_poly(env.contents, univar_pairs, t1$1, tl1$1, d2._0, d2._1, (function (param, param$1) { + return unify(env, param, param$1); + })); + break; + default: + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + } + break; + case /* Tpackage */11 : + var tl1$2 = d1._2; + if (typeof d2 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + switch (d2.TAG | 0) { + case /* Tconstr */3 : + exit$4 = 5; + break; + case /* Tpackage */11 : + var tl2$1 = d2._2; + try { + unify_package(env.contents, (function (param, param$1) { + return unify_list(env, param, param$1); + }), t1.level, d1._0, d1._1, tl1$2, t2.level, d2._0, d2._1, tl2$1); + } + catch (raw_exn$2){ + var exn$2 = Caml_js_exceptions.internalToOCamlException(raw_exn$2); + if (exn$2.MEL_EXN_ID === Stdlib.Not_found) { + if (umode.contents === /* Expression */0) { throw { MEL_EXN_ID: Unify, _1: /* [] */0, Error: new Error() - }; - } - if (f2$2.TAG === /* Rpresent */0) { - if (c1) { - if (f1$2._1) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (f2$2._0 !== undefined) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (!fixed1) { - return set_row_field(f1$2._3, f2$2); - } - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - var t2$1 = f2$2._0; - if (t2$1 !== undefined) { - if (fixed1) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - var e1$1 = f1$2._3; - set_row_field(e1$1, f2$2); - update_level(env.contents, repr(more).level, t2$1); - try { - return Stdlib__List.iter((function(t2$1){ - return function (t1) { - unify(env, t1, t2$1); - } - }(t2$1)), f1$2._1); - } - catch (exn$1){ - e1$1.contents = undefined; - throw exn$1; - } - } else { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - } else { - var e2$1 = f2$2._3; - if (e1 === e2$1) { - return ; - } - var m2 = f2$2._2; - var tl2 = f2$2._1; - var c2 = f2$2._0; - var redo = false; - if (m1 || m2 || fixed1 || fixed2 || rigid_variants.contents && (Stdlib__List.length(tl1) === 1 || Stdlib__List.length(tl2) === 1)) { - var match = Stdlib.$at(tl1, tl2); - var tmp; - if (match) { - var t1$1 = match.hd; - if (c1 || c2) { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - Stdlib__List.iter((function(t1$1){ - return function (param) { - return unify(env, t1$1, param); - } - }(t1$1)), match.tl); - tmp = e1.contents !== undefined || e2$1.contents !== undefined; - } else { - tmp = false; - } - redo = tmp; - } - if (redo) { - _f2 = f2$2; - _f1 = f1$2; - continue ; - } - var tl1$1 = Stdlib__List.map(repr, tl1); - var tl2$1 = Stdlib__List.map(repr, tl2); - var remq = function (tl, _param) { - while(true) { - var param = _param; - if (!param) { - return /* [] */0; - } - var tl$p = param.tl; - var ty = param.hd; - if (!Stdlib__List.memq(ty, tl)) { - return { - hd: ty, - tl: remq(tl, tl$p) - }; - } - _param = tl$p; - continue ; - }; - }; - var tl2$p = remq(tl2$1, tl1$1); - var tl1$p = remq(tl1$1, tl2$1); - var partial_arg = repr(more).level; - var partial_arg$1 = env.contents; - Stdlib__List.iter((function(partial_arg,partial_arg$1){ - return function (param) { - return update_level(partial_arg$1, partial_arg, param); - } - }(partial_arg,partial_arg$1)), Stdlib.$at(tl1$p, tl2$p)); - var e = { - contents: undefined - }; - var f1$p_0 = c1 || c2; - var f1$p_2 = m1 || m2; - var f1$p = { - TAG: /* Reither */1, - _0: f1$p_0, - _1: tl1$p, - _2: f1$p_2, - _3: e - }; - var f2$p_0 = c1 || c2; - var f2$p_2 = m1 || m2; - var f2$p = { - TAG: /* Reither */1, - _0: f2$p_0, - _1: tl2$p, - _2: f2$p_2, - _3: e - }; - set_row_field(e1, f1$p); - return set_row_field(e2$1, f2$p); + }; } + Stdlib__List.iter((function (param) { + return reify(env, param); + }), Stdlib.$at(tl1$2, tl2$1)); + } else { + throw exn$2; } - }; - } - catch (raw_exn){ - var exn$2 = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn$2.MEL_EXN_ID === Unify) { - throw { - MEL_EXN_ID: Unify, - _1: { - hd: [ - mkvariant({ - hd: [ - l, - f1 - ], - tl: /* [] */0 - }, true), - mkvariant({ - hd: [ - l, - f2 - ], - tl: /* [] */0 - }, true) - ], - tl: exn$2._1 - }, - Error: new Error() - }; } - throw exn$2; - } - }), pairs); - } - catch (exn){ - log_type(rm1); - rm1.desc = md1; - log_type(rm2); - rm2.desc = md2; - throw exn; - } -} - -function unify3(env, t1, t1$p, t2, t2$p) { - var d1 = t1$p.desc; - var d2 = t2$p.desc; - var create_recursion = t2 !== t2$p && deep_occur(t1$p, t2); - var exit = 0; - var exit$1 = 0; - if (typeof d1 === "number") { - exit$1 = 2; - } else { - switch (d1.TAG | 0) { - case /* Tvar */0 : - occur(env.contents, t1$p, t2); - occur_univar(env.contents, t2); - return link_type(t1$p, t2); - case /* Tfield */5 : - if (typeof d2 === "number") { - exit = 1; - } else { - switch (d2.TAG | 0) { - case /* Tvar */0 : - exit$1 = 2; - break; - case /* Tfield */5 : - return unify_fields(env, t1$p, t2$p); - default: - exit = 1; - } + break; + default: + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + break; + default: + exit$4 = 5; + } + } + if (exit$4 === 5) { + if (typeof d2 === "number" || d2.TAG !== /* Tconstr */3) { + exit$3 = 4; + } else { + var path = d2._0; + switch (path.TAG | 0) { + case /* Pident */0 : + if (d2._1 || !(is_newtype(env.contents, path) && generate_equations.contents)) { + exit$2 = 2; + } else { + reify(env, t1$p); + add_gadt_equation(env, path._0, t1$p); + } + break; + case /* Pdot */1 : + case /* Papply */2 : + exit$2 = 2; + break; + } - break; - case /* Tunivar */9 : - if (typeof d2 === "number") { - exit = 1; - } else { - switch (d2.TAG | 0) { - case /* Tvar */0 : - exit$1 = 2; - break; - case /* Tunivar */9 : - unify_univar(t1$p, t2$p, univar_pairs.contents); - return link_type(t1$p, t2$p); - default: - exit = 1; + } + } + if (exit$3 === 4) { + if (typeof d1 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (d1.TAG === /* Tconstr */3) { + exit$2 = 2; + } else { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + } + switch (exit$2) { + case 2 : + if (umode.contents === /* Pattern */1) { + reify(env, t1$p); + reify(env, t2$p); + if (generate_equations.contents) { + mcomp$1(env.contents, t1$p, t2$p); + } + + } else { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; } - } - break; - default: - exit$1 = 2; + break; + case 3 : + var r = field_kind_repr(kind); + if (typeof r === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (f !== dummy_method) { + set_kind(r._0, /* Fabsent */1); + if (Caml_obj.caml_equal(d2, /* Tnil */0)) { + unify(env, rem, t2$p); + } else { + unify(env, newty2(rem.level, /* Tnil */0), rem); + } + } else { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + break; + + } + if (!create_recursion) { + return ; + } + var match$8 = t2.desc; + if (typeof match$8 === "number") { + return ; + } + if (match$8.TAG !== /* Tconstr */3) { + return ; + } + forget_abbrev(match$8._2, match$8._0); + var t2$p$p = expand_head_unif(env.contents, t2); + if (!closed_parameterized_type(match$8._1, t2$p$p)) { + return link_type(repr(t2), repr(t2$p)); + } else { + return ; + } + } + catch (raw_exn$3){ + var exn$3 = Caml_js_exceptions.internalToOCamlException(raw_exn$3); + if (exn$3.MEL_EXN_ID === Unify) { + t1$p.desc = d1; + throw { + MEL_EXN_ID: Unify, + _1: exn$3._1, + Error: new Error() + }; + } + throw exn$3; } } - if (exit$1 === 2) { - if (typeof d2 === "number") { - exit = 1; - } else { - if (d2.TAG === /* Tvar */0) { - occur(env.contents, t2$p, t1); - occur_univar(env.contents, t1); - return link_type(t2$p, t1); + +} + +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; } - exit = 1; + }; + 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); } + } - if (exit === 1) { - var match = umode.contents; - if (match) { - add_type_equality(t1$p, t2$p); - } else { - occur(env.contents, t1$p, t2$p); - link_type(t1$p, t2); + 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() + }; } - try { - var exit$2 = 0; - var f; - var kind; - var rem; - var exit$3 = 0; - var exit$4 = 0; - if (typeof d1 === "number") { - if (typeof d2 !== "number") { - switch (d2.TAG | 0) { - case /* Tconstr */3 : - exit$4 = 5; - break; - case /* Tfield */5 : - f = d2._0; - kind = d2._1; - rem = d2._3; - exit$2 = 3; - break; - default: - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - } - - } else { - switch (d1.TAG | 0) { - case /* Tarrow */1 : - var l1 = d1._0; - if (typeof d2 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - switch (d2.TAG | 0) { - case /* Tarrow */1 : - var l2 = d2._0; - if (l1 === l2 || classic.contents && !(is_optional(l1) || is_optional(l2))) { - unify(env, d1._1, d2._1); - unify(env, d1._2, d2._2); - var match$1 = commu_repr(d1._3); - var match$2 = commu_repr(d2._3); - if (typeof match$1 === "number") { - if (typeof match$2 === "number") { - - } else { - set_commu(match$2._0, match$1); - } - } else { - set_commu(match$1._0, match$2); - } - } else { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - break; - case /* Tconstr */3 : - exit$4 = 5; - break; - default: - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - break; - case /* Ttuple */2 : - if (typeof d2 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - switch (d2.TAG | 0) { - case /* Ttuple */2 : - unify_list(env, d1._0, d2._0); - break; - case /* Tconstr */3 : - exit$4 = 5; - break; - default: - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - break; - case /* Tconstr */3 : - var p1 = d1._0; - var exit$5 = 0; - if (typeof d2 === "number" || d2.TAG !== /* Tconstr */3) { - exit$5 = 6; - } else { - var tl2 = d2._1; - var tl1 = d1._1; - if (same(p1, d2._0)) { - if (umode.contents === /* Expression */0 || !generate_equations.contents) { - unify_list(env, tl1, tl2); - } else if (assume_injective.contents) { - set_mode_pattern(true, false, (function (param) { - unify_list(env, tl1, tl2); - })); - } else { - var tmp = true; - if (!in_current_module(p1)) { - var partial_arg = env.contents; - tmp = Stdlib__List.exists((function (param) { - return expands_to_datatype(partial_arg, param); - }), { - hd: t1$p, - tl: { - hd: t1, - tl: { - hd: t2, - tl: /* [] */0 - } - } - }); - } - if (tmp) { - unify_list(env, tl1, tl2); - } else { - var inj; - try { - inj = Stdlib__List.map(Curry._1(Types_Variance.mem, /* Inj */3), find_type_full(p1, env.contents)[0].type_variance); - } - catch (raw_exn){ - var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.MEL_EXN_ID === Stdlib.Not_found) { - inj = Stdlib__List.map((function (param) { - return false; - }), tl1); - } else { - throw exn; - } - } - Stdlib__List.iter2((function (i, param) { - var t2 = param[1]; - var t1 = param[0]; - if (i) { - return unify(env, t1, t2); - } else { - return set_mode_pattern(false, false, (function (param) { - var snap = snapshot(undefined); - try { - return unify(env, t1, t2); - } - catch (raw_exn){ - var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.MEL_EXN_ID === Unify) { - backtrack(snap); - reify(env, t1); - return reify(env, t2); - } - throw exn; - } - })); - } - }), inj, Stdlib__List.combine(tl1, tl2)); - } - } - } else { - exit$5 = 6; - } + throw exn; + } +} + +function unify_list(env, tl1, tl2) { + if (Stdlib__List.length(tl1) !== Stdlib__List.length(tl2)) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + Stdlib__List.iter2((function (param, param$1) { + return unify(env, param, param$1); + }), tl1, tl2); +} + +function unify_row(env, row1, row2) { + var row1$1 = row_repr_aux(/* [] */0, row1); + var row2$1 = row_repr_aux(/* [] */0, row2); + var rm1 = row_more(row1$1); + var rm2 = row_more(row2$1); + if (unify_eq(env.contents, rm1, rm2)) { + return ; + } + var match = merge_row_fields(row1$1.row_fields, row2$1.row_fields); + var pairs = match[2]; + var r2 = match[1]; + var r1 = match[0]; + if (Caml_obj.caml_notequal(r1, /* [] */0) && Caml_obj.caml_notequal(r2, /* [] */0)) { + var ht = Stdlib__Hashtbl.create(undefined, Stdlib__List.length(r1)); + Stdlib__List.iter((function (param) { + var l = param[0]; + Stdlib__Hashtbl.add(ht, hash_variant(l), l); + }), r1); + Stdlib__List.iter((function (param) { + var l = param[0]; + try { + throw { + MEL_EXN_ID: Tags, + _1: l, + _2: Stdlib__Hashtbl.find(ht, hash_variant(l)), + Error: new Error() + }; + } + catch (raw_exn){ + var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + if (exn.MEL_EXN_ID === Stdlib.Not_found) { + return ; } - if (exit$5 === 6) { - switch (p1.TAG | 0) { - case /* Pident */0 : - if (d1._1) { - exit$4 = 5; - } else { - var p = p1._0; - var exit$6 = 0; - if (typeof d2 === "number" || d2.TAG !== /* Tconstr */3) { - exit$6 = 7; - } else { - var path$p = d2._0; - switch (path$p.TAG | 0) { - case /* Pident */0 : - if (d2._1 || !(is_newtype(env.contents, p1) && is_newtype(env.contents, path$p) && generate_equations.contents)) { - exit$6 = 7; - } else { - var match$3 = Caml_obj.caml_greaterthan(find_newtype_level(env.contents, p1), find_newtype_level(env.contents, path$p)) ? [ - p, - t2$p - ] : [ - path$p._0, - t1$p - ]; - add_gadt_equation(env, match$3[0], match$3[1]); - } - break; - case /* Pdot */1 : - case /* Papply */2 : - exit$6 = 7; - break; - - } - } - if (exit$6 === 7) { - if (is_newtype(env.contents, p1) && generate_equations.contents) { - reify(env, t2$p); - add_gadt_equation(env, p, t2$p); - } else { - exit$4 = 5; - } - } - + throw exn; + } + }), r2); + } + var fixed1 = row_fixed(row1$1); + var fixed2 = row_fixed(row2$1); + var more = fixed1 ? rm1 : ( + fixed2 ? rm2 : newty2(rm1.level < rm2.level ? rm1.level : rm2.level, { + TAG: /* Tvar */0, + _0: undefined + }) + ); + var fixed = fixed1 || fixed2; + var closed = row1$1.row_closed || row2$1.row_closed; + var keep = function ($$switch) { + return Stdlib__List.for_all((function (param) { + var match = Curry._2($$switch, param[1], param[2]); + if (Caml_obj.caml_equal(row_field_repr_aux(/* [] */0, match[0]), /* Rabsent */0)) { + return true; + } else { + return Caml_obj.caml_notequal(row_field_repr_aux(/* [] */0, match[1]), /* Rabsent */0); + } + }), pairs); + }; + var empty = function (fields) { + return Stdlib__List.for_all((function (param) { + return Caml_obj.caml_equal(row_field_repr_aux(/* [] */0, param[1]), /* Rabsent */0); + }), fields); + }; + if (closed && (empty(r1) || row2$1.row_closed) && (empty(r2) || row1$1.row_closed) && Stdlib__List.for_all((function (param) { + if (Caml_obj.caml_equal(row_field_repr_aux(/* [] */0, param[1]), /* Rabsent */0)) { + return true; + } else { + return Caml_obj.caml_equal(row_field_repr_aux(/* [] */0, param[2]), /* Rabsent */0); + } + }), pairs)) { + throw { + MEL_EXN_ID: Unify, + _1: { + hd: [ + mkvariant(/* [] */0, true), + mkvariant(/* [] */0, true) + ], + tl: /* [] */0 + }, + Error: new Error() + }; + } + var name = row1$1.row_name !== undefined && (row1$1.row_closed || empty(r2)) && (!row2$1.row_closed || keep(function (f1, f2) { + return [ + f1, + f2 + ]; + }) && empty(r1)) ? row1$1.row_name : ( + row2$1.row_name !== undefined && (row2$1.row_closed || empty(r1)) && (!row1$1.row_closed || keep(function (f1, f2) { + return [ + f2, + f1 + ]; + }) && empty(r2)) ? row2$1.row_name : undefined + ); + var set_more = function (row, rest) { + var rest$1 = closed ? filter_row_fields(row.row_closed, rest) : rest; + if (Caml_obj.caml_notequal(rest$1, /* [] */0) && (row.row_closed || row_fixed(row)) || closed && row_fixed(row) && !row.row_closed) { + var t1 = mkvariant(/* [] */0, true); + var t2 = mkvariant(rest$1, false); + throw { + MEL_EXN_ID: Unify, + _1: { + hd: row === row1$1 ? [ + t1, + t2 + ] : [ + t2, + t1 + ], + tl: /* [] */0 + }, + Error: new Error() + }; + } + var rm = row_more(row); + if (trace_gadt_instances.contents && Caml_obj.caml_equal(rm.desc, /* Tnil */0) || !trace_gadt_instances.contents) { + + } else { + update_level(env.contents, rm.level, newty2(100000000, { + TAG: /* Tvariant */8, + _0: row + })); + } + if (row_fixed(row)) { + if (more === rm) { + return ; + } else if (is_Tvar(rm)) { + return link_type(rm, more); + } else { + return unify(env, rm, more); + } + } + var ty = newty2(100000000, { + TAG: /* Tvariant */8, + _0: { + row_fields: rest$1, + row_more: more, + row_bound: undefined, + row_closed: closed, + row_fixed: fixed, + row_name: name + } + }); + update_level(env.contents, rm.level, ty); + link_type(rm, ty); + }; + var md1 = rm1.desc; + var md2 = rm2.desc; + try { + set_more(row2$1, r1); + set_more(row1$1, r2); + return Stdlib__List.iter((function (param) { + var f2 = param[2]; + var f1 = param[1]; + var l = param[0]; + try { + var _f1 = f1; + var _f2 = f2; + while(true) { + var f2$1 = _f2; + var f1$1 = _f1; + var f1$2 = row_field_repr_aux(/* [] */0, f1$1); + var f2$2 = row_field_repr_aux(/* [] */0, f2$1); + if (f1$2 === f2$2) { + return ; } - break; - case /* Pdot */1 : - case /* Papply */2 : - exit$4 = 5; - break; - - } - } - break; - case /* Tobject */4 : - if (typeof d2 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - switch (d2.TAG | 0) { - case /* Tconstr */3 : - exit$4 = 5; - break; - case /* Tobject */4 : - unify_fields(env, d1._0, d2._0); - var match$4 = repr(t2$p).desc; - if (typeof match$4 !== "number" && match$4.TAG === /* Tobject */4) { - var exit$7 = 0; - var match$5 = match$4._1.contents; - if (match$5 !== undefined) { - var match$6 = match$5[1]; - if (match$6) { - var match$7 = repr(match$6.hd).desc; - var tmp$1; - if (typeof match$7 === "number") { - tmp$1 = true; - } else { - switch (match$7.TAG | 0) { - case /* Tvar */0 : - case /* Tunivar */9 : - tmp$1 = true; - break; - default: - tmp$1 = false; + if (typeof f1$2 === "number") { + if (typeof f2$2 === "number") { + return ; + } + if (f2$2.TAG === /* Rpresent */0) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (f2$2._2) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (!fixed2) { + return set_row_field(f2$2._3, f1$2); + } + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } else if (f1$2.TAG === /* Rpresent */0) { + var t1 = f1$2._0; + if (t1 !== undefined) { + if (typeof f2$2 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (f2$2.TAG === /* Rpresent */0) { + var t2 = f2$2._0; + if (t2 !== undefined) { + return unify(env, t1, t2); } + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; } - if (!tmp$1) { - exit$7 = 6; + if (f2$2._0) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; } - - } else { - exit$7 = 6; - } - } else { - exit$7 = 6; - } - if (exit$7 === 6) { - set_name(match$4._1, d1._1.contents); - } - - } - break; - default: - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - break; - case /* Tfield */5 : - if (typeof d2 === "number") { - f = d1._0; - kind = d1._1; - rem = d1._3; - exit$2 = 3; - } else if (d2.TAG === /* Tconstr */3) { - exit$4 = 5; - } else { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - break; - case /* Tvariant */8 : - var row1 = d1._0; - if (typeof d2 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - switch (d2.TAG | 0) { - case /* Tconstr */3 : - exit$4 = 5; - break; - case /* Tvariant */8 : - var row2 = d2._0; - if (umode.contents === /* Expression */0) { - unify_row(env, row1, row2); - } else { - var snap = snapshot(undefined); - try { - unify_row(env, row1, row2); - } - catch (raw_exn$1){ - var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - if (exn$1.MEL_EXN_ID === Unify) { - backtrack(snap); - reify(env, t1$p); - reify(env, t2$p); - if (generate_equations.contents) { - mcomp$1(env.contents, t1$p, t2$p); + if (fixed2) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + var e2 = f2$2._3; + set_row_field(e2, f1$2); + update_level(env.contents, repr(more).level, t1); + try { + return Stdlib__List.iter((function(t1){ + return function (param) { + return unify(env, t1, param); + } + }(t1)), f2$2._1); + } + catch (exn){ + e2.contents = undefined; + throw exn; } - } else { - throw exn$1; - } - } - } - break; - default: - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - break; - case /* Tpoly */10 : - var tl1$1 = d1._1; - var t1$1 = d1._0; - var exit$8 = 0; - if (tl1$1) { - exit$8 = 6; - } else { - if (typeof d2 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - switch (d2.TAG | 0) { - case /* Tconstr */3 : - exit$4 = 5; - break; - case /* Tpoly */10 : - if (d2._1) { - exit$8 = 6; - } else { - unify(env, t1$1, d2._0); - } - break; - default: - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - } - if (exit$8 === 6) { - if (typeof d2 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - switch (d2.TAG | 0) { - case /* Tconstr */3 : - exit$4 = 5; - break; - case /* Tpoly */10 : - enter_poly(env.contents, univar_pairs, t1$1, tl1$1, d2._0, d2._1, (function (param, param$1) { - return unify(env, param, param$1); - })); - break; - default: - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - } - break; - case /* Tpackage */11 : - var tl1$2 = d1._2; - if (typeof d2 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - switch (d2.TAG | 0) { - case /* Tconstr */3 : - exit$4 = 5; - break; - case /* Tpackage */11 : - var tl2$1 = d2._2; - try { - unify_package(env.contents, (function (param, param$1) { - return unify_list(env, param, param$1); - }), t1.level, d1._0, d1._1, tl1$2, t2.level, d2._0, d2._1, tl2$1); - } - catch (raw_exn$2){ - var exn$2 = Caml_js_exceptions.internalToOCamlException(raw_exn$2); - if (exn$2.MEL_EXN_ID === Stdlib.Not_found) { - if (umode.contents === /* Expression */0) { + if (typeof f2$2 === "number") { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (f2$2.TAG === /* Rpresent */0) { + if (f2$2._0 === undefined) { + return ; + } + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (f2$2._0) { + if (f2$2._1) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (!fixed2) { + return set_row_field(f2$2._3, f1$2); + } + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } throw { MEL_EXN_ID: Unify, _1: /* [] */0, Error: new Error() }; } - Stdlib__List.iter((function (param) { - return reify(env, param); - }), Stdlib.$at(tl1$2, tl2$1)); } else { - throw exn$2; - } - } - break; - default: - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - break; - default: - exit$4 = 5; - } - } - if (exit$4 === 5) { - if (typeof d2 === "number" || d2.TAG !== /* Tconstr */3) { - exit$3 = 4; - } else { - var path = d2._0; - switch (path.TAG | 0) { - case /* Pident */0 : - if (d2._1 || !(is_newtype(env.contents, path) && generate_equations.contents)) { - exit$2 = 2; - } else { - reify(env, t1$p); - add_gadt_equation(env, path._0, t1$p); - } - break; - case /* Pdot */1 : - case /* Papply */2 : - exit$2 = 2; - break; - - } - } - } - if (exit$3 === 4) { - if (typeof d1 === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (d1.TAG === /* Tconstr */3) { - exit$2 = 2; - } else { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - } - switch (exit$2) { - case 2 : - if (umode.contents === /* Pattern */1) { - reify(env, t1$p); - reify(env, t2$p); - if (generate_equations.contents) { - mcomp$1(env.contents, t1$p, t2$p); - } - - } else { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - break; - case 3 : - var r = field_kind_repr(kind); - if (typeof r === "number") { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - if (f !== dummy_method) { - set_kind(r._0, /* Fabsent */1); - if (Caml_obj.caml_equal(d2, /* Tnil */0)) { - unify(env, rem, t2$p); - } else { - unify(env, newty2(rem.level, /* Tnil */0), rem); - } - } else { - throw { - MEL_EXN_ID: Unify, - _1: /* [] */0, - Error: new Error() - }; - } - break; - - } - if (!create_recursion) { - return ; - } - var match$8 = t2.desc; - if (typeof match$8 === "number") { - return ; - } - if (match$8.TAG !== /* Tconstr */3) { - return ; - } - forget_abbrev(match$8._2, match$8._0); - var t2$p$p = expand_head_unif(env.contents, t2); - if (!closed_parameterized_type(match$8._1, t2$p$p)) { - return link_type(repr(t2), repr(t2$p)); - } else { - return ; - } - } - catch (raw_exn$3){ - var exn$3 = Caml_js_exceptions.internalToOCamlException(raw_exn$3); - if (exn$3.MEL_EXN_ID === Unify) { - t1$p.desc = d1; - throw { - MEL_EXN_ID: Unify, - _1: exn$3._1, - Error: new Error() - }; - } - throw exn$3; - } + var c1 = f1$2._0; + var m1 = f1$2._2; + var tl1 = f1$2._1; + var e1 = f1$2._3; + if (typeof f2$2 === "number") { + if (m1) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (!fixed1) { + return set_row_field(f1$2._3, f2$2); + } + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (f2$2.TAG === /* Rpresent */0) { + if (c1) { + if (f1$2._1) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (f2$2._0 !== undefined) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + if (!fixed1) { + return set_row_field(f1$2._3, f2$2); + } + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + var t2$1 = f2$2._0; + if (t2$1 !== undefined) { + if (fixed1) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + var e1$1 = f1$2._3; + set_row_field(e1$1, f2$2); + update_level(env.contents, repr(more).level, t2$1); + try { + return Stdlib__List.iter((function(t2$1){ + return function (t1) { + unify(env, t1, t2$1); + } + }(t2$1)), f1$2._1); + } + catch (exn$1){ + e1$1.contents = undefined; + throw exn$1; + } + } else { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + } else { + var e2$1 = f2$2._3; + if (e1 === e2$1) { + return ; + } + var m2 = f2$2._2; + var tl2 = f2$2._1; + var c2 = f2$2._0; + var redo = false; + if (m1 || m2 || fixed1 || fixed2 || rigid_variants.contents && (Stdlib__List.length(tl1) === 1 || Stdlib__List.length(tl2) === 1)) { + var match = Stdlib.$at(tl1, tl2); + var tmp; + if (match) { + var t1$1 = match.hd; + if (c1 || c2) { + throw { + MEL_EXN_ID: Unify, + _1: /* [] */0, + Error: new Error() + }; + } + Stdlib__List.iter((function(t1$1){ + return function (param) { + return unify(env, t1$1, param); + } + }(t1$1)), match.tl); + tmp = e1.contents !== undefined || e2$1.contents !== undefined; + } else { + tmp = false; + } + redo = tmp; + } + if (redo) { + _f2 = f2$2; + _f1 = f1$2; + continue ; + } + var tl1$1 = Stdlib__List.map(repr, tl1); + var tl2$1 = Stdlib__List.map(repr, tl2); + var remq = function (tl, _param) { + while(true) { + var param = _param; + if (!param) { + return /* [] */0; + } + var tl$p = param.tl; + var ty = param.hd; + if (!Stdlib__List.memq(ty, tl)) { + return { + hd: ty, + tl: remq(tl, tl$p) + }; + } + _param = tl$p; + continue ; + }; + }; + var tl2$p = remq(tl2$1, tl1$1); + var tl1$p = remq(tl1$1, tl2$1); + var partial_arg = repr(more).level; + var partial_arg$1 = env.contents; + Stdlib__List.iter((function(partial_arg,partial_arg$1){ + return function (param) { + return update_level(partial_arg$1, partial_arg, param); + } + }(partial_arg,partial_arg$1)), Stdlib.$at(tl1$p, tl2$p)); + var e = { + contents: undefined + }; + var f1$p_0 = c1 || c2; + var f1$p_2 = m1 || m2; + var f1$p = { + TAG: /* Reither */1, + _0: f1$p_0, + _1: tl1$p, + _2: f1$p_2, + _3: e + }; + var f2$p_0 = c1 || c2; + var f2$p_2 = m1 || m2; + var f2$p = { + TAG: /* Reither */1, + _0: f2$p_0, + _1: tl2$p, + _2: f2$p_2, + _3: e + }; + set_row_field(e1, f1$p); + return set_row_field(e2$1, f2$p); + } + } + }; + } + catch (raw_exn){ + var exn$2 = Caml_js_exceptions.internalToOCamlException(raw_exn); + if (exn$2.MEL_EXN_ID === Unify) { + throw { + MEL_EXN_ID: Unify, + _1: { + hd: [ + mkvariant({ + hd: [ + l, + f1 + ], + tl: /* [] */0 + }, true), + mkvariant({ + hd: [ + l, + f2 + ], + tl: /* [] */0 + }, true) + ], + tl: exn$2._1 + }, + Error: new Error() + }; + } + throw exn$2; + } + }), pairs); + } + catch (exn){ + log_type(rm1); + rm1.desc = md1; + log_type(rm2); + rm2.desc = md2; + throw exn; } - } -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); - } +function unify_fields(env, ty1, ty2) { + var match = flatten_fields(ty1); + var rest1 = match[1]; + var match$1 = flatten_fields(ty2); + var rest2 = match$1[1]; + var match$2 = associate_fields(match[0], match$1[0]); + var miss2 = match$2[2]; + var miss1 = match$2[1]; + var l1 = repr(ty1).level; + var l2 = repr(ty2).level; + var va = make_rowvar(l1 < l2 ? l1 : l2, Caml_obj.caml_equal(miss2, /* [] */0), rest1, Caml_obj.caml_equal(miss1, /* [] */0), rest2); + var d1 = rest1.desc; + var d2 = rest2.desc; try { - return unify3(env, t2$2, t2$p, t1$2, t1$p); + unify(env, build_fields(l1)(miss1, va), rest2); + unify(env, rest1, build_fields(l2)(miss2, va)); + return Stdlib__List.iter((function (param) { + var t2 = param[4]; + var k2 = param[3]; + var t1 = param[2]; + var k1 = param[1]; + var n = param[0]; + unify_kind(k1, k2); + try { + if (trace_gadt_instances.contents) { + update_level(env.contents, va.level, t1); + } + return unify(env, t1, t2); + } + catch (raw_exn){ + var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + if (exn.MEL_EXN_ID === Unify) { + var desc_3 = newty2(current_level.contents, /* Tnil */0); + var desc = { + TAG: /* Tfield */5, + _0: n, + _1: k1, + _2: t1, + _3: desc_3 + }; + var desc_3$1 = newty2(current_level.contents, /* Tnil */0); + var desc$1 = { + TAG: /* Tfield */5, + _0: n, + _1: k2, + _2: t2, + _3: desc_3$1 + }; + throw { + 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 (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() - }; - } + catch (exn){ + log_type(rest1); + rest1.desc = d1; + log_type(rest2); + rest2.desc = d2; throw exn; } } @@ -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/exception_repr_test.ml b/jscomp/test/exception_repr_test.ml index 60dd60831c..f60449c103 100644 --- a/jscomp/test/exception_repr_test.ml +++ b/jscomp/test/exception_repr_test.ml @@ -1,18 +1,18 @@ let suites : Mt.pair_suites ref = ref [] let test_id = ref 0 -let eq loc x y = - incr test_id ; - suites := +let eq loc x y = + incr test_id ; + suites := (loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites -exception Hi +exception Hi exception Hello -exception A of int -exception AAA = Exception_def.A +exception A of int +exception AAA = Exception_def.A -;; Printexc.register_printer (function +;; Printexc.register_printer (function | Hi -> Some "hey" | A s -> Some (Format.asprintf "A(%d)" s ) | _ -> None @@ -20,12 +20,10 @@ exception AAA = Exception_def.A -let () = +let () = eq __LOC__ "hey" (Printexc.to_string Hi); eq __LOC__ "A(1)" (Printexc.to_string (A 1)); - eq __LOC__ (Js.String2.startsWith (Printexc.to_string Hello) "Exception_repr_test.Hello") true; + eq __LOC__ (Js.String.startsWith (Printexc.to_string Hello) ~prefix:"Exception_repr_test.Hello") true; eq __LOC__ "A" (Printexc.to_string @@ AAA 3) ;; Mt.from_pair_suites __MODULE__ !suites - - diff --git a/jscomp/test/js_string_test.ml b/jscomp/test/js_string_test.ml index 190b7d75ee..1b5c616b57 100644 --- a/jscomp/test/js_string_test.ml +++ b/jscomp/test/js_string_test.ml @@ -1,216 +1,224 @@ let suites = Mt.[ "make", (fun _ -> - Eq("null", Js.String2.make Js.null |. Js.String2.concat "") + Eq("null", Js.String.make Js.null |. Js.String.concat ~other:"") ); "fromCharCode", (fun _ -> - Eq("a", Js.String2.fromCharCode 97) + Eq("a", Js.String.fromCharCode 97) ); "fromCharCodeMany", (fun _ -> - Eq("az", Js.String2.fromCharCodeMany [| 97; 122 |]) + Eq("az", Js.String.fromCharCodeMany [| 97; 122 |]) ); (* es2015 *) "fromCodePoint", (fun _ -> - Eq("a", Js.String2.fromCodePoint 0x61) + Eq("a", Js.String.fromCodePoint 0x61) ); "fromCodePointMany", (fun _ -> - Eq("az", Js.String2.fromCodePointMany [| 0x61; 0x7a |]) + Eq("az", Js.String.fromCodePointMany [| 0x61; 0x7a |]) ); "length", (fun _ -> - Eq(3, "foo" |. Js.String2.length) + Eq(3, "foo" |. Js.String.length) ); "get", (fun _ -> - Eq("a", Js.String2.get "foobar" 4) + Eq("a", Js.String.get "foobar" 4) ); "charAt", (fun _ -> - Eq("a", "foobar" |. Js.String2.charAt 4) + Eq("a", "foobar" |. Js.String.charAt ~pos:4) ); "charCodeAt", (fun _ -> - Eq(97., "foobar" |. Js.String2.charCodeAt 4) + Eq(97., "foobar" |. Js.String.charCodeAt ~pos:4) ); (* es2015 *) "codePointAt", (fun _ -> - Eq(Some 0x61, "foobar" |. Js.String2.codePointAt 4) + Eq(Some 0x61, "foobar" |. Js.String.codePointAt ~pos:4) ); "codePointAt - out of bounds", (fun _ -> - Eq(None, "foobar" |. Js.String2.codePointAt 98) + Eq(None, "foobar" |. Js.String.codePointAt ~pos:98) ); "concat", (fun _ -> - Eq("foobar", "foo" |. Js.String2.concat "bar") + Eq("foobar", "foo" |. Js.String.concat ~other:"bar") ); "concatMany", (fun _ -> - Eq("foobarbaz", "foo" |. Js.String2.concatMany [| "bar"; "baz" |]) + Eq("foobarbaz", "foo" |. Js.String.concatMany ~strings:[| "bar"; "baz" |]) ); (* es2015 *) "endsWith", (fun _ -> - Eq(true, "foobar" |. Js.String2.endsWith "bar") + Eq(true, "foobar" |. Js.String.endsWith ~suffix:"bar") ); "endsWithFrom", (fun _ -> - Eq(false, "foobar" |. Js.String2.endsWithFrom "bar" 1) + Eq(false, "foobar" |. Js.String.endsWithFrom ~suffix:"bar" ~len:1) ); (* es2015 *) "includes", (fun _ -> - Eq(true, "foobarbaz" |. Js.String2.includes "bar") + Eq(true, "foobarbaz" |. Js.String.includes ~sub:"bar") ); "includesFrom", (fun _ -> - Eq(false, "foobarbaz" |. Js.String2.includesFrom "bar" 4) + Eq(false, "foobarbaz" |. Js.String.includesFrom ~sub:"bar" ~pos:4) ); "indexOf", (fun _ -> - Eq(3, "foobarbaz" |. Js.String2.indexOf "bar") + Eq(3, "foobarbaz" |. Js.String.indexOf ~sub:"bar") ); "indexOfFrom", (fun _ -> - Eq((-1), "foobarbaz" |. Js.String2.indexOfFrom "bar" 4) + Eq((-1), "foobarbaz" |. Js.String.indexOfFrom ~sub:"bar" ~pos:4) ); "lastIndexOf", (fun _ -> - Eq(3, "foobarbaz" |. Js.String2.lastIndexOf "bar") + Eq(3, "foobarbaz" |. Js.String.lastIndexOf ~sub:"bar") ); "lastIndexOfFrom", (fun _ -> - Eq(3, "foobarbaz" |. Js.String2.lastIndexOfFrom "bar" 4) + Eq(3, "foobarbaz" |. Js.String.lastIndexOfFrom ~sub:"bar" ~pos:4) ); "localeCompare", (fun _ -> - Eq(0., "foo" |. Js.String2.localeCompare "foo") + Eq(0., "foo" |. Js.String.localeCompare ~other:"foo") ); "match", (fun _ -> - Eq(Some [| Some "na"; Some "na" |], "banana" |. Js.String2.match_ [%re "/na+/g"]) + Eq(Some [| Some "na"; Some "na" |], "banana" |. Js.String.match_ ~regexp:[%re "/na+/g"]) ); "match - no match", (fun _ -> - Eq(None, "banana" |. Js.String2.match_ [%re "/nanana+/g"]) + Eq(None, "banana" |. Js.String.match_ ~regexp:[%re "/nanana+/g"]) ); "match - not found capture groups", (fun _ -> - Eq(Some [| Some "hello "; None |], "hello word" |. Js.String2.match_ [%re "/hello (world)?/"] |. Belt.Option.map Js.Array.copy ) + Eq( + Some [| Some "hello "; None |], + "hello word" + |. Js.String.match_ ~regexp:[%re "/hello (world)?/"] + |. Belt.Option.map Js.Array.copy ) ); (* es2015 *) "normalize", (fun _ -> - Eq("foo", "foo" |. Js.String2.normalize) + Eq("foo", "foo" |. Js.String.normalize) ); "normalizeByForm", (fun _ -> - Eq("foo", "foo" |. Js.String2.normalizeByForm "NFKD") + Eq("foo", "foo" |. Js.String.normalizeByForm ~form:`NFKD) ); (* es2015 *) "repeat", (fun _ -> - Eq("foofoofoo", "foo" |. Js.String2.repeat 3) + Eq("foofoofoo", "foo" |. Js.String.repeat ~n:3) ); "replace", (fun _ -> - Eq("fooBORKbaz", "foobarbaz" |. Js.String2.replace "bar" "BORK") + Eq("fooBORKbaz", "foobarbaz" |. Js.String.replace ~sub:"bar" ~replacement:"BORK") ); "replaceByRe", (fun _ -> - Eq("fooBORKBORK", "foobarbaz" |. Js.String2.replaceByRe [%re "/ba./g"] "BORK") + Eq("fooBORKBORK", "foobarbaz" |. Js.String.replaceByRe ~regexp:[%re "/ba./g"] ~replacement:"BORK") ); "unsafeReplaceBy0", (fun _ -> let replace = fun whole offset s -> if whole = "bar" then "BORK" else "DORK" in - Eq("fooBORKDORK", "foobarbaz" |. Js.String2.unsafeReplaceBy0 [%re "/ba./g"] replace) + Eq("fooBORKDORK", "foobarbaz" |. Js.String.unsafeReplaceBy0 ~regexp:[%re "/ba./g"] ~f:replace) ); "unsafeReplaceBy1", (fun _ -> let replace = fun whole p1 offset s -> if whole = "bar" then "BORK" else "DORK" in - Eq("fooBORKDORK", "foobarbaz" |. Js.String2.unsafeReplaceBy1 [%re "/ba./g"] replace) + Eq("fooBORKDORK", "foobarbaz" |. Js.String.unsafeReplaceBy1 ~regexp:[%re "/ba./g"] ~f:replace) ); "unsafeReplaceBy2", (fun _ -> let replace = fun whole p1 p2 offset s -> if whole = "bar" then "BORK" else "DORK" in - Eq("fooBORKDORK", "foobarbaz" |. Js.String2.unsafeReplaceBy2 [%re "/ba./g"] replace) + Eq("fooBORKDORK", "foobarbaz" |. Js.String.unsafeReplaceBy2 ~regexp:[%re "/ba./g"] ~f:replace) ); "unsafeReplaceBy3", (fun _ -> let replace = fun whole p1 p2 p3 offset s -> if whole = "bar" then "BORK" else "DORK" in - Eq("fooBORKDORK", "foobarbaz" |. Js.String2.unsafeReplaceBy3 [%re "/ba./g"] replace) + Eq("fooBORKDORK", "foobarbaz" |. Js.String.unsafeReplaceBy3 ~regexp:[%re "/ba./g"] ~f:replace) ); "search", (fun _ -> - Eq(3, "foobarbaz" |. Js.String2.search [%re "/ba./g"]) + Eq(3, "foobarbaz" |. Js.String.search ~regexp:[%re "/ba./g"]) ); "slice", (fun _ -> - Eq("bar", "foobarbaz" |. Js.String2.slice ~from:3 ~to_:6) + Eq("bar", "foobarbaz" |. Js.String.slice ~from:3 ~to_:6) ); "sliceToEnd", (fun _ -> - Eq("barbaz", "foobarbaz" |. Js.String2.sliceToEnd ~from:3) + Eq("barbaz", "foobarbaz" |. Js.String.sliceToEnd ~from:3) ); "split", (fun _ -> - Eq([| "foo"; "bar"; "baz" |], "foo bar baz" |. Js.String2.split " ") + Eq([| "foo"; "bar"; "baz" |], "foo bar baz" |. Js.String.split ~sep:" ") ); "splitAtMost", (fun _ -> - Eq([| "foo"; "bar" |], "foo bar baz" |. Js.String2.splitAtMost " " ~limit:2) + Eq([| "foo"; "bar" |], "foo bar baz" |. Js.String.splitAtMost ~sep:" " ~limit:2) ); "splitByRe", (fun _ -> - Eq([| Some "a"; Some "#"; None; Some "b"; Some "#"; Some ":"; Some "c" |], "a#b#:c" |> Js.String.splitByRe [%re "/(#)(:)?/"]) + Eq( + [| Some "a"; Some "#"; None; Some "b"; Some "#"; Some ":"; Some "c" |], + "a#b#:c" |> Js.String.splitByRe ~regexp:[%re "/(#)(:)?/"]) ); "splitByReAtMost", (fun _ -> - Eq([| Some "a"; Some "#"; None |], "a#b#:c" |> Js.String.splitByReAtMost [%re "/(#)(:)?/"] ~limit:3) + Eq( + [| Some "a"; Some "#"; None |], + "a#b#:c" |> Js.String.splitByReAtMost ~regexp:[%re "/(#)(:)?/"] ~limit:3) ); (* es2015 *) "startsWith", (fun _ -> - Eq(true, "foobarbaz" |. Js.String2.startsWith "foo") + Eq(true, "foobarbaz" |. Js.String.startsWith ~prefix:"foo") ); "startsWithFrom", (fun _ -> - Eq(false, "foobarbaz" |. Js.String2.startsWithFrom "foo" 1) + Eq(false, "foobarbaz" |. Js.String.startsWithFrom ~prefix:"foo" ~pos:1) ); "substr", (fun _ -> - Eq("barbaz", "foobarbaz" |. Js.String2.substr ~from:3) + Eq("barbaz", "foobarbaz" |. Js.String.substr ~from:3) ); "substrAtMost", (fun _ -> - Eq("bar", "foobarbaz" |. Js.String2.substrAtMost ~from:3 ~length:3) + Eq("bar", "foobarbaz" |. Js.String.substrAtMost ~from:3 ~length:3) ); "substring", (fun _ -> - Eq("bar", "foobarbaz" |. Js.String2.substring ~from:3 ~to_:6) + Eq("bar", "foobarbaz" |. Js.String.substring ~from:3 ~to_:6) ); "substringToEnd", (fun _ -> - Eq("barbaz", "foobarbaz" |. Js.String2.substringToEnd ~from:3) + Eq("barbaz", "foobarbaz" |. Js.String.substringToEnd ~from:3) ); "toLowerCase", (fun _ -> - Eq("bork", "BORK" |. Js.String2.toLowerCase) + Eq("bork", "BORK" |. Js.String.toLowerCase) ); "toLocaleLowerCase", (fun _ -> - Eq("bork", "BORK" |. Js.String2.toLocaleLowerCase) + Eq("bork", "BORK" |. Js.String.toLocaleLowerCase) ); "toUpperCase", (fun _ -> - Eq("FUBAR", "fubar" |. Js.String2.toUpperCase) + Eq("FUBAR", "fubar" |. Js.String.toUpperCase) ); "toLocaleUpperCase", (fun _ -> - Eq("FUBAR", "fubar" |. Js.String2.toLocaleUpperCase) + Eq("FUBAR", "fubar" |. Js.String.toLocaleUpperCase) ); "trim", (fun _ -> - Eq("foo", " foo " |. Js.String2.trim) + Eq("foo", " foo " |. Js.String.trim) ); (* es2015 *) "anchor", (fun _ -> - Eq("foo", "foo" |. Js.String2.anchor "bar") + Eq("foo", "foo" |. Js.String.anchor ~name:"bar") ); "link", (fun _ -> - Eq("foo", "foo" |. Js.String2.link "https://reason.ml") + Eq("foo", "foo" |. Js.String.link ~href:"https://reason.ml") ); - __LOC__ , (fun _ -> Ok (Js.String2.includes "ab" "a")) + __LOC__ , (fun _ -> Ok (Js.String.includes "ab" ~sub:"a")) ] ;; Mt.from_pair_suites __MODULE__ suites diff --git a/jscomp/test/re_or_res/reactTestUtils.re b/jscomp/test/re_or_res/reactTestUtils.re index 733171bf7a..bb558691fd 100644 --- a/jscomp/test/re_or_res/reactTestUtils.re +++ b/jscomp/test/re_or_res/reactTestUtils.re @@ -82,7 +82,7 @@ module Simulate = { external focus: Dom.element => unit = "focus"; }; - external document: Dom.document = "document"; +external document: Dom.document = "document"; [@mel.send] external querySelector: (Dom.element, string) => option(Dom.element) = @@ -125,7 +125,9 @@ module DOM = { let findBySelectorAndPartialTextContent = (element, selector, content) => querySelectorAll(element, selector) - ->Array.getBy(node => node->textContent->Js.String2.includes(content)); + ->Array.getBy(node => + node->textContent->Js.String.includes(~sub=content) + ); }; let prepareContainer = (container: ref(option(Dom.element)), ()) => { diff --git a/jscomp/test/re_or_res/reasonReactRouter.re b/jscomp/test/re_or_res/reasonReactRouter.re index a23a26a02f..5664b5e00e 100644 --- a/jscomp/test/re_or_res/reasonReactRouter.re +++ b/jscomp/test/re_or_res/reasonReactRouter.re @@ -30,11 +30,11 @@ external replaceState: unit = "replaceState"; - external event: 'a = "Event"; +external event: 'a = "Event"; [@mel.new] external makeEventIE11Compatible: string => Dom.event = "Event"; - [@mel.scope "document"] +[@mel.scope "document"] external createEventNonIEBrowsers: string => Dom.event = "createEvent"; [@mel.send] @@ -70,7 +70,7 @@ let arrayToList = a => { let path = () => switch ([%external window]) { | None => [] - | Some((window: Dom.window)) => + | Some(window: Dom.window) => switch (window |> location |> pathname) { | "" | "/" => [] @@ -83,13 +83,13 @@ let path = () => | "/" => Js.String.slice(~from=0, ~to_=-1, raw) | _ => raw }; - raw |> Js.String.split("/") |> arrayToList; + raw |> Js.String.split(~sep="/") |> arrayToList; } }; let hash = () => switch ([%external window]) { | None => "" - | Some((window: Dom.window)) => + | Some(window: Dom.window) => switch (window |> location |> hash) { | "" | "#" => "" @@ -102,7 +102,7 @@ let hash = () => let search = () => switch ([%external window]) { | None => "" - | Some((window: Dom.window)) => + | Some(window: Dom.window) => switch (window |> location |> search) { | "" | "?" => "" @@ -115,7 +115,7 @@ let push = path => switch ([%external history], [%external window]) { | (None, _) | (_, None) => () - | (Some((history: Dom.history)), Some((window: Dom.window))) => + | (Some(history: Dom.history), Some(window: Dom.window)) => pushState(history, ~href=path); dispatchEvent(window, safeMakeEvent("popstate")); }; @@ -123,7 +123,7 @@ let replace = path => switch ([%external history], [%external window]) { | (None, _) | (_, None) => () - | (Some((history: Dom.history)), Some((window: Dom.window))) => + | (Some(history: Dom.history), Some(window: Dom.window)) => replaceState(history, ~href=path); dispatchEvent(window, safeMakeEvent("popstate")); }; @@ -155,7 +155,7 @@ let dangerouslyGetInitialUrl = url; let watchUrl = callback => switch ([%external window]) { | None => (() => ()) - | Some((window: Dom.window)) => + | Some(window: Dom.window) => let watcherID = () => callback(url()); addEventListener(window, "popstate", watcherID); watcherID; @@ -163,7 +163,7 @@ let watchUrl = callback => let unwatchUrl = watcherID => switch ([%external window]) { | None => () - | Some((window: Dom.window)) => + | Some(window: Dom.window) => removeEventListener(window, "popstate", watcherID) }; diff --git a/jscomp/test/sexpm_test.ml b/jscomp/test/sexpm_test.ml index 8a3098a983..b0232219c6 100644 --- a/jscomp/test/sexpm_test.ml +++ b/jscomp/test/sexpm_test.ml @@ -19,7 +19,7 @@ let () = `Ok (`List [`Atom "x"; `Atom "x"; `Atom "gh"; `Atom "3"; `Atom "3"]) , a ); eq __LOC__ - (Js.String2.trim (Format.asprintf "%a" print_or_error a) , Js.String2.trim "Ok:(x x gh 3 3)\n") + (Js.String.trim (Format.asprintf "%a" print_or_error a) , Js.String.trim "Ok:(x x gh 3 3)\n") end From 62162d4f7ecd9325ea91ddfaec2f65fc0435ef6e Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Tue, 14 Nov 2023 21:41:16 -0800 Subject: [PATCH 2/5] chore: add changelog entry for #893 and #895 --- Changes.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Changes.md b/Changes.md index f61455570b..7775bdca87 100644 --- a/Changes.md +++ b/Changes.md @@ -25,6 +25,14 @@ Unreleased 1. Exception ID `RE_EXN_ID` to `MEL_EXN_ID` 2. `BS_PRIVATE_NESTED_SOME_NONE` option marker to `MEL_PRIVATE_NESTED_SOME_NONE` +- BREAKING(runtime): unify pipe-first / pipe-last libraries in `Js` modules + ([#731](https://github.com/melange-re/melange/issues/731), + [#893](https://github.com/melange-re/melange/pull/893), + [#895](https://github.com/melange-re/melange/pull/895)) + - Modules ending with `2` (e.g. `Js.String2`, `Js.Array2`) are no longer + available in Melange + - The functions in their corresponding modules now take labeled arguments, + allowing them to be used with both `|.` and `|>`. - Consistently handle empty payloads in externals: ([#852](https://github.com/melange-re/melange/pull/852)) - Fix crash when pattern matching in the presence of complex constant inlining From d1d5d0d3d19967265b9ada9c7f99e00e7978eb30 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 16 Nov 2023 13:15:33 -0800 Subject: [PATCH 3/5] code review, fix tests --- jscomp/runtime/js_string.ml | 275 +++++------------- jscomp/test/bs_string_test.ml | 2 +- jscomp/test/chn_test.ml | 2 +- .../test/dist/jscomp/test/bs_string_test.js | 2 +- .../dist/jscomp/test/exception_repr_test.js | 2 +- .../test/dist/jscomp/test/js_string_test.js | 20 +- .../jscomp/test/re_or_res/reactTestUtils.js | 2 +- .../test/re_or_res/reasonReactRouter.js | 8 +- jscomp/test/exception_repr_test.ml | 2 +- jscomp/test/js_string_test.ml | 38 +-- jscomp/test/re_or_res/reactTestUtils.re | 2 +- jscomp/test/re_or_res/reasonReactRouter.re | 10 +- 12 files changed, 113 insertions(+), 252 deletions(-) diff --git a/jscomp/runtime/js_string.ml b/jscomp/runtime/js_string.ml index 40a19a3b1e..4260d76aef 100644 --- a/jscomp/runtime/js_string.ml +++ b/jscomp/runtime/js_string.ml @@ -139,8 +139,8 @@ external codePointAt : t -> pos:int -> int option = "codePointAt" function returns [None]. {[ - codePointAt {js|¿😺?|js} 1 = Some 0x1f63a - codePointAt "abc" 5 = None + codePointAt {js|¿😺?|js} ~pos:1 = Some 0x1f63a + codePointAt "abc" ~pos:5 = None ]} *) @@ -166,10 +166,11 @@ external concatMany : t -> strings:t array -> t = "concat" ]} *) -external endsWith : t -> suffix:t -> bool = "endsWith" +external endsWith : t -> suffix:t -> ?len:int -> unit -> bool = "endsWith" [@@mel.send] -(** [endsWith str ~suffix] returns [true] if the [str] ends with [suffix], - [false] otherwise. +(** [endsWith str ~suffix ?len ()] returns [true] if the [str] ends with + [suffix], [false] otherwise. If [len] is specified, `endsWith` only takes + into account the first [len] characters. {[ endsWith "Hello, World!" ~suffix:"World!" = true;; @@ -178,93 +179,36 @@ external endsWith : t -> suffix:t -> bool = "endsWith" ]} *) -external endsWithFrom : t -> suffix:t -> len:int -> bool = "endsWith" -[@@mel.send] -(** [endsWithFrom str ~len ~suffix] returns [true] if the first [len] - characters of [str] end with [ending], [false] otherwise. If [len] is - greater than or equal to the length of [str], then it works like - [endsWith]. - -{[ - endsWithFrom "abcd" ~suffix:"cd" ~len:4 = true;; - endsWithFrom "abcde" ~suffix:"cd" ~len:3 = false;; - endsWithFrom "abcde" ~suffix:"cde" ~len:99 = true;; - endsWithFrom "example.dat" ~suffix:"ple" ~len:7 = true;; -]} -*) - -external includes : t -> sub:t -> bool = "includes" -[@@mel.send] -(** [includes s ~sub:searchValue] returns [true] if [searchValue] is found - anywhere within [s], [false] otherwise. - -{[ - includes "programmer" ~sub:"gram" = true;; - includes "programmer" ~sub:"er" = true;; - includes "programmer" ~sub:"pro" = true;; - includes "programmer" ~sub:"xyz" = false;; -]} -*) - -external includesFrom : t -> sub:t -> pos:int -> bool = "includes" -[@@mel.send] -(** - [includes s ~sub:searchValue ~start] returns [true] if [searchValue] is found - anywhere within [s] starting at character number [start] (where 0 is the - first character), [false] otherwise. - -{[ - includesFrom "programmer" ~sub:"gram" ~pos:1 = true;; - includesFrom "programmer" ~sub:"gram" ~pos:4 = false;; - includesFrom {js|대한민국|js} ~sub:{js|한|js} ~pos:1 = true;; -]} -*) - -external indexOf : t -> sub:t -> int = "indexOf" +external includes : t -> sub:t -> ?start:int -> unit -> bool = "includes" [@@mel.send] (** - [indexOf s ~sub:searchValue ] returns the position at which [searchValue] was - first found within [s], or [-1] if [searchValue] is not in [s]. + [includes s ~sub:searchValue ?start ()] returns [true] if [searchValue] is + found anywhere within [s] starting at character number [start] (where 0 is + the first character), [false] otherwise. {[ - indexOf "bookseller" ~sub:"ok" = 2;; - indexOf "bookseller" ~sub:"sell" = 4;; - indexOf "beekeeper" ~sub:"ee" = 1;; - indexOf "bookseller" ~sub:"xyz" = -1;; + includesFrom "programmer" ~sub:"gram" ~start:1 () = true;; + includesFrom "programmer" ~sub:"gram" ~start:4 () = false;; + includesFrom {js|대한민국|js} ~sub:{js|한|js} ~start:1 () = true;; ]} *) -external indexOfFrom : t -> sub:t -> pos:int -> int = "indexOf" +external indexOf : t -> sub:t -> ?start:int -> unit -> int = "indexOf" [@@mel.send] -(** [indexOfFrom s ~sub:searchValue ~start] returns the position at which +(** [indexOfFrom s ~sub:searchValue ?start ()] returns the position at which [searchValue] was found within [s] starting at character position [start], or [-1] if [searchValue] is not found in that portion of [s]. The return value is relative to the beginning of the string, no matter where the search started from. {[ - indexOfFrom "bookseller" ~sub:"ok" ~pos:1 = 2;; - indexOfFrom "bookseller" ~sub:"sell" ~pos:2 = 4;; - indexOfFrom "bookseller" ~sub:"sell" ~pos:5 = -1;; -]} -*) - -external lastIndexOf : t -> sub:t -> int = "lastIndexOf" -[@@mel.send] -(** - [lastIndexOf s ~sub:searchValue ] returns the position of the {i last} - occurrence of [searchValue] within [s], searching backwards from the end of - the string. Returns [-1] if [searchValue] is not in [s]. The return value is - always relative to the beginning of the string. - -{[ - lastIndexOf "bookseller" ~sub:"ok" = 2;; - lastIndexOf "beekeeper" ~sub:"ee" = 4;; - lastIndexOf "abcdefg" ~sub:"xyz" = -1;; + indexOfFrom "bookseller" ~sub:"ok" ~start:1 () = 2;; + indexOfFrom "bookseller" ~sub:"sell" ~start:2 () = 4;; + indexOfFrom "bookseller" ~sub:"sell" ~start:5 () = -1;; ]} *) -external lastIndexOfFrom : t -> sub:t -> pos:int -> int = "lastIndexOf" +external lastIndexOf : t -> sub:t -> ?start:int -> unit -> int = "lastIndexOf" [@@mel.send] (** [lastIndexOfFrom s ~sub:searchValue ~start] returns the position of the {i @@ -273,10 +217,10 @@ external lastIndexOfFrom : t -> sub:t -> pos:int -> int = "lastIndexOf" return value is always relative to the beginning of the string. {[ - lastIndexOfFrom "bookseller" ~sub:"ok" ~pos:6 = 2;; - lastIndexOfFrom "beekeeper" ~sub:"ee" ~pos:8 = 4;; - lastIndexOfFrom "beekeeper" ~sub:"ee" ~pos:3 = 1;; - lastIndexOfFrom "abcdefg" ~sub:"xyz" ~pos:4 = -1;; + lastIndexOfFrom "bookseller" ~sub:"ok" ~start:6 () = 2;; + lastIndexOfFrom "beekeeper" ~sub:"ee" ~start:8 () = 4;; + lastIndexOfFrom "beekeeper" ~sub:"ee" ~start:3 () = 1;; + lastIndexOfFrom "abcdefg" ~sub:"xyz" ~start:4 () = -1;; ]} *) @@ -491,69 +435,38 @@ search "no numbers" [%re "/\\d+/"] = -1;; ]} *) -external slice : t -> from:int -> to_:int -> t = "slice" +external slice : t -> ?start:int -> ?end_:int -> unit -> t = "slice" [@@mel.send] -(** [slice from:n1 to_:n2 str] returns the substring of [str] starting at - character [n1] up to but not including [n2] +(** [slice ?start ?end str ()] returns the substring of [str] starting at + character [start] up to but not including [end] - If either [n1] or [n2] is negative, then it is evaluated as [length str - - n1] (or [length str - n2]). + If either [start] or [end] is negative, then it is evaluated as [length str + - start] (or [length str - end]). - If [n2] is greater than the length of [str], then it is treated as [length + If [end] is greater than the length of [str], then it is treated as [length str]. - If [n1] is greater than [n2], [slice] returns the empty string. - -{[ - slice "abcdefg" ~from:2 ~to_:5 == "cde";; - slice "abcdefg" ~from:2 ~to_:9 == "cdefg";; - slice "abcdefg" ~from:(-4) ~to_:(-2) == "de";; - slice "abcdefg" ~from:5 ~to_:1 == "";; -]} -*) - -external sliceToEnd : t -> from:int -> t = "slice" -[@@mel.send] -(** [sliceToEnd from: n str] returns the substring of [str] starting at - character [n] to the end of the string - - If [n] is negative, then it is evaluated as [length str - n]. - - If [n] is greater than the length of [str], then [sliceToEnd] returns the - empty string. + If [start] is greater than [end], [slice] returns the empty string. {[ - sliceToEnd "abcdefg" ~from: 4 == "efg";; - sliceToEnd "abcdefg" ~from: (-2) == "fg";; - sliceToEnd "abcdefg" ~from: 7 == "";; + slice "abcdefg" ~start:2 ~end_:5 () == "cde";; + slice "abcdefg" ~start:2 ~end_:9 () == "cdefg";; + slice "abcdefg" ~start:(-4) ~end_:(-2) () == "de";; + slice "abcdefg" ~start:5 ~end_:1 () == "";; ]} *) -external split : t -> sep:t -> t array = "split" +external split : t -> ?sep:t -> ?limit:int -> unit -> t array = "split" [@@mel.send] -(** - [split str ~sep:delimiter] splits the given [str] at every occurrence of - [delimiter] and returns an array of the resulting substrings. +(** [splitAtMost ?sep ?limit str ()] splits the given [str] at every + occurrence of [sep] and returns an array of the first [limit] resulting + substrings. If [limit] is negative or greater than the number of + substrings, the array will contain all the substrings. {[ - split "2018-01-02" "-" = [|"2018"; "01"; "02"|];; - split "a,b,,c" "," = [|"a"; "b"; ""; "c"|];; - split "good::bad as great::awful" "::" = [|"good"; "bad as great"; "awful"|];; - split "has-no-delimiter" ";" = [|"has-no-delimiter"|];; -]}; -*) - -external splitAtMost : t -> sep:t -> limit:int -> t array = "split" -[@@mel.send] -(** [splitAtMost delimiter ~limit: n str] splits the given [str] at every - occurrence of [delimiter] and returns an array of the first [n] resulting - substrings. If [n] is negative or greater than the number of substrings, - the array will contain all the substrings. - -{[ - splitAtMost "ant/bee/cat/dog/elk" ~sep:"/" ~limit: 3 = [|"ant"; "bee"; "cat"|];; - splitAtMost "ant/bee/cat/dog/elk" ~sep:"/" ~limit: 0 = [| |];; - splitAtMost "ant/bee/cat/dog/elk" ~sep:"/" ~limit: 9 = [|"ant"; "bee"; "cat"; "dog"; "elk"|];; + splitAtMost "ant/bee/cat/dog/elk" ~sep:"/" ~limit: 3 () = [|"ant"; "bee"; "cat"|];; + splitAtMost "ant/bee/cat/dog/elk" ~sep:"/" ~limit: 0 () = [| |];; + splitAtMost "ant/bee/cat/dog/elk" ~sep:"/" ~limit: 9 () = [|"ant"; "bee"; "cat"; "dog"; "elk"|];; ]} *) @@ -583,102 +496,54 @@ external splitByReAtMost : t -> regexp:Js_re.t -> limit:int -> t option array ]}; *) -external startsWith : t -> prefix:t -> bool = "startsWith" -[@@mel.send] -(** [startsWith str ~prefix] returns [true] if the [str] starts with [prefix], - [false] otherwise. - -{[ - startsWith "Hello, World!" ~prefix:"Hello" = true;; - startsWith "Hello, World!" ~prefix:"hello" = false;; (* case-sensitive *) - startsWith "Hello, World!" ~prefix:"World" = false;; (* exact match *) -]} -*) - -external startsWithFrom : t -> prefix:t -> pos:int -> bool = "startsWith" +external startsWith : t -> prefix:t -> ?start:int -> unit -> bool = "startsWith" [@@mel.send] -(** [startsWithFrom str ~prefix ~start] returns [true] if the [str] starts with - [prefix] starting at position [start], [false] otherwise. If [n] is +(** [startsWith str ~prefix ?start ()] returns [true] if the [str] starts with + [prefix] starting at position [start], [false] otherwise. If [start] is negative, the search starts at the beginning of [str]. {[ - startsWithFrom "Hello, World!" "Hello" 0 = true;; - startsWithFrom "Hello, World!" "World" 7 = true;; - startsWithFrom "Hello, World!" "World" 8 = false;; -]} -*) - -external substr : t -> from:int -> t = "substr" -[@@mel.send] -(** [substr ~from:n str] returns the substring of [str] from position [n] to - the end of the string. - - If [n] is less than zero, the starting position is the length of [str] - - [n]. - - If [n] is greater than or equal to the length of [str], returns the empty - string. - -{[ - substr "abcdefghij" ~from: 3 = "defghij" - substr "abcdefghij" ~from: (-3) = "hij" - substr "abcdefghij" ~from: 12 = "" + startsWithFrom "Hello, World!" "Hello" ~start:0 () = true;; + startsWithFrom "Hello, World!" "World" ~start:7 () = true;; + startsWithFrom "Hello, World!" "World" ~start:8 () = false;; ]} *) -external substrAtMost : t -> from:int -> length:int -> t = "substr" +external substr : t -> ?start:int -> ?len:int -> unit -> t = "substr" [@@mel.send] -(** [substrAtMost ~from:pos ~length:n str] returns the substring of [str] of - length [n] starting at position [pos]. +(** [substr ?start ?len str ()] returns the substring of [str] of + length [len] starting at position [start]. - If [pos] is less than zero, the starting position is the length of [str] - - [pos]. + If [start] is less than zero, the starting position is the length of [str] + - [start]. - If [pos] is greater than or equal to the length of [str], returns the empty - string. + If [start] is greater than or equal to the length of [str], returns the + empty string. - If [n] is less than or equal to zero, returns the empty string. + If [len] is less than or equal to zero, returns the empty string. {[ - substrAtMost "abcdefghij" ~from: 3 ~length: 4 = "defghij" - substrAtMost "abcdefghij" ~from: (-3) ~length: 4 = "hij" - substrAtMost "abcdefghij" ~from: 12 ~ length: 2 = "" + substrAtMost "abcdefghij" ~start:3 ~len:4 () = "defghij" + substrAtMost "abcdefghij" ~start:(-3) ~le:4 () = "hij" + substrAtMost "abcdefghij" ~start:12 ~ len:2 () = "" ]} *) -external substring : t -> from:int -> to_:int -> t = "substring" +external substring : t -> ?start:int -> ?end_:int -> unit -> t = "substring" [@@mel.send] -(** [substring ~from: start ~to_: finish str] returns characters [start] up to - but not including [finish] from [str]. +(** [substring ~start ~end_ str] returns characters [start] up to + but not including [end_] from [str]. If [start] is less than zero, it is treated as zero. - If [finish] is zero or negative, the empty string is returned. + If [end_] is zero or negative, the empty string is returned. - If [start] is greater than [finish], the start and finish points are - swapped. + If [start] is greater than [end_], the start and finish points are swapped. {[ - substring "playground" ~from: 3 ~to_: 6 = "ygr";; - substring "playground" ~from: 6 ~to_: 3 = "ygr";; - substring "playground" ~from: 4 ~to_: 12 = "ground";; -]} -*) - -external substringToEnd : t -> from:int -> t = "substring" -[@@mel.send] -(** [substringToEnd ~from: start str] returns the substring of [str] from - position [start] to the end. - - If [start] is less than or equal to zero, the entire string is returned. - - If [start] is greater than or equal to the length of [str], the empty - string is returned. - -{[ - substringToEnd "playground" ~from: 4 = "ground";; - substringToEnd "playground" ~from: (-3) = "playground";; - substringToEnd "playground" ~from: 12 = ""; + substring "playground" ~start:3 ~end_:6 = "ygr";; + substring "playground" ~start:6 ~end_:3 = "ygr";; + substring "playground" ~start:4 ~end_:12 = "ground";; ]} *) @@ -758,8 +623,4 @@ external link : t -> href:t -> t = "link" ]} *) -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 -*) +external unsafeToArrayLike : t -> t Js_array.array_like = "%identity" diff --git a/jscomp/test/bs_string_test.ml b/jscomp/test/bs_string_test.ml index 062814df72..bb670deaa1 100644 --- a/jscomp/test/bs_string_test.ml +++ b/jscomp/test/bs_string_test.ml @@ -10,7 +10,7 @@ let eq loc x y = let () = eq __LOC__ ("ghso ghso g" - |. Js.String.split ~sep:" " + |. Js.String.split ~sep:" " () |. Js.Array2.reduce (fun x y -> x ^ "-" ^ y) "" ) "-ghso-ghso-g" diff --git a/jscomp/test/chn_test.ml b/jscomp/test/chn_test.ml index 942219b0a5..e200099673 100644 --- a/jscomp/test/chn_test.ml +++ b/jscomp/test/chn_test.ml @@ -14,7 +14,7 @@ Js.log {js|\x3f\u003f\b\t\n\v\f\r\0"'|js} ;; let convert (s : string) : int list = Js.Array2.fromMap - (Js.String.castToArrayLike s) + (Js.String.unsafeToArrayLike s) (fun x -> match Js.String.codePointAt ~pos:0 x with | None -> assert false diff --git a/jscomp/test/dist/jscomp/test/bs_string_test.js b/jscomp/test/dist/jscomp/test/bs_string_test.js index 9a412d426e..f32fa2537f 100644 --- a/jscomp/test/dist/jscomp/test/bs_string_test.js +++ b/jscomp/test/dist/jscomp/test/bs_string_test.js @@ -28,7 +28,7 @@ function eq(loc, x, y) { }; } -eq("File \"jscomp/test/bs_string_test.ml\", line 11, characters 5-12", "ghso ghso g".split(" ").reduce((function (x, y) { +eq("File \"jscomp/test/bs_string_test.ml\", line 11, characters 5-12", "ghso ghso g".split(" ", undefined).reduce((function (x, y) { return x + ("-" + y); }), ""), "-ghso-ghso-g"); diff --git a/jscomp/test/dist/jscomp/test/exception_repr_test.js b/jscomp/test/dist/jscomp/test/exception_repr_test.js index 4040ff6f2d..ccdf4ea02e 100644 --- a/jscomp/test/dist/jscomp/test/exception_repr_test.js +++ b/jscomp/test/dist/jscomp/test/exception_repr_test.js @@ -77,7 +77,7 @@ eq("File \"jscomp/test/exception_repr_test.ml\", line 25, characters 7-14", "A(1 eq("File \"jscomp/test/exception_repr_test.ml\", line 26, characters 7-14", Stdlib__Printexc.to_string({ MEL_EXN_ID: Hello - }).startsWith("Exception_repr_test.Hello"), true); + }).startsWith("Exception_repr_test.Hello", undefined), true); eq("File \"jscomp/test/exception_repr_test.ml\", line 27, characters 7-14", "A", Stdlib__Printexc.to_string({ MEL_EXN_ID: Exception_def.A, diff --git a/jscomp/test/dist/jscomp/test/js_string_test.js b/jscomp/test/dist/jscomp/test/js_string_test.js index 0ea63b6a5f..2dbd6456d0 100644 --- a/jscomp/test/dist/jscomp/test/js_string_test.js +++ b/jscomp/test/dist/jscomp/test/js_string_test.js @@ -155,7 +155,7 @@ var suites_1 = { return { TAG: /* Eq */0, _0: true, - _1: "foobar".endsWith("bar") + _1: "foobar".endsWith("bar", undefined) }; }) ], @@ -177,7 +177,7 @@ var suites_1 = { return { TAG: /* Eq */0, _0: true, - _1: "foobarbaz".includes("bar") + _1: "foobarbaz".includes("bar", undefined) }; }) ], @@ -199,7 +199,7 @@ var suites_1 = { return { TAG: /* Eq */0, _0: 3, - _1: "foobarbaz".indexOf("bar") + _1: "foobarbaz".indexOf("bar", undefined) }; }) ], @@ -221,7 +221,7 @@ var suites_1 = { return { TAG: /* Eq */0, _0: 3, - _1: "foobarbaz".lastIndexOf("bar") + _1: "foobarbaz".lastIndexOf("bar", undefined) }; }) ], @@ -444,7 +444,7 @@ var suites_1 = { return { TAG: /* Eq */0, _0: "barbaz", - _1: "foobarbaz".slice(3) + _1: "foobarbaz".slice(3, undefined) }; }) ], @@ -459,7 +459,7 @@ var suites_1 = { "bar", "baz" ], - _1: "foo bar baz".split(" ") + _1: "foo bar baz".split(" ", undefined) }; }) ], @@ -524,7 +524,7 @@ var suites_1 = { return { TAG: /* Eq */0, _0: true, - _1: "foobarbaz".startsWith("foo") + _1: "foobarbaz".startsWith("foo", undefined) }; }) ], @@ -546,7 +546,7 @@ var suites_1 = { return { TAG: /* Eq */0, _0: "barbaz", - _1: "foobarbaz".substr(3) + _1: "foobarbaz".substr(3, undefined) }; }) ], @@ -579,7 +579,7 @@ var suites_1 = { return { TAG: /* Eq */0, _0: "barbaz", - _1: "foobarbaz".substring(3) + _1: "foobarbaz".substring(3, undefined) }; }) ], @@ -666,7 +666,7 @@ var suites_1 = { (function (param) { return { TAG: /* Ok */4, - _0: "ab".includes("a") + _0: "ab".includes("a", undefined) }; }) ], diff --git a/jscomp/test/dist/jscomp/test/re_or_res/reactTestUtils.js b/jscomp/test/dist/jscomp/test/re_or_res/reactTestUtils.js index 1c4e7acd00..c3f8af7d38 100644 --- a/jscomp/test/dist/jscomp/test/re_or_res/reactTestUtils.js +++ b/jscomp/test/dist/jscomp/test/re_or_res/reactTestUtils.js @@ -59,7 +59,7 @@ function findBySelectorAndTextContent(element, selector, content) { function findBySelectorAndPartialTextContent(element, selector, content) { return Belt__Belt_Array.getBy(Array.from(element.querySelectorAll(selector)), (function (node) { - return node.textContent.includes(content); + return node.textContent.includes(content, undefined); })); } diff --git a/jscomp/test/dist/jscomp/test/re_or_res/reasonReactRouter.js b/jscomp/test/dist/jscomp/test/re_or_res/reasonReactRouter.js index dc8aa35f41..b2252a818a 100644 --- a/jscomp/test/dist/jscomp/test/re_or_res/reasonReactRouter.js +++ b/jscomp/test/dist/jscomp/test/re_or_res/reasonReactRouter.js @@ -24,10 +24,10 @@ function path(param) { case "/" : return /* [] */0; default: - var raw$1 = raw.slice(1); + var raw$1 = raw.slice(1, undefined); var match = raw$1[raw$1.length - 1 | 0]; var raw$2 = match === "/" ? raw$1.slice(0, -1) : raw$1; - var a = raw$2.split("/"); + var a = raw$2.split("/", undefined); var _i = a.length - 1 | 0; var _res = /* [] */0; while(true) { @@ -57,7 +57,7 @@ function hash(param) { case "#" : return ""; default: - return raw.slice(1); + return raw.slice(1, undefined); } } @@ -72,7 +72,7 @@ function search(param) { case "?" : return ""; default: - return raw.slice(1); + return raw.slice(1, undefined); } } diff --git a/jscomp/test/exception_repr_test.ml b/jscomp/test/exception_repr_test.ml index f60449c103..6492984285 100644 --- a/jscomp/test/exception_repr_test.ml +++ b/jscomp/test/exception_repr_test.ml @@ -23,7 +23,7 @@ exception AAA = Exception_def.A let () = eq __LOC__ "hey" (Printexc.to_string Hi); eq __LOC__ "A(1)" (Printexc.to_string (A 1)); - eq __LOC__ (Js.String.startsWith (Printexc.to_string Hello) ~prefix:"Exception_repr_test.Hello") true; + eq __LOC__ (Js.String.startsWith (Printexc.to_string Hello) ~prefix:"Exception_repr_test.Hello" ()) true; eq __LOC__ "A" (Printexc.to_string @@ AAA 3) ;; Mt.from_pair_suites __MODULE__ !suites diff --git a/jscomp/test/js_string_test.ml b/jscomp/test/js_string_test.ml index 1b5c616b57..983d6ad71c 100644 --- a/jscomp/test/js_string_test.ml +++ b/jscomp/test/js_string_test.ml @@ -51,32 +51,32 @@ let suites = Mt.[ (* es2015 *) "endsWith", (fun _ -> - Eq(true, "foobar" |. Js.String.endsWith ~suffix:"bar") + Eq(true, "foobar" |. Js.String.endsWith ~suffix:"bar" ()) ); "endsWithFrom", (fun _ -> - Eq(false, "foobar" |. Js.String.endsWithFrom ~suffix:"bar" ~len:1) + Eq(false, "foobar" |. Js.String.endsWith ~suffix:"bar" ~len:1 ()) ); (* es2015 *) "includes", (fun _ -> - Eq(true, "foobarbaz" |. Js.String.includes ~sub:"bar") + Eq(true, "foobarbaz" |. Js.String.includes ~sub:"bar" ()) ); "includesFrom", (fun _ -> - Eq(false, "foobarbaz" |. Js.String.includesFrom ~sub:"bar" ~pos:4) + Eq(false, "foobarbaz" |. Js.String.includes ~sub:"bar" ~start:4 ()) ); "indexOf", (fun _ -> - Eq(3, "foobarbaz" |. Js.String.indexOf ~sub:"bar") + Eq(3, "foobarbaz" |. Js.String.indexOf ~sub:"bar" ()) ); "indexOfFrom", (fun _ -> - Eq((-1), "foobarbaz" |. Js.String.indexOfFrom ~sub:"bar" ~pos:4) + Eq((-1), "foobarbaz" |. Js.String.indexOf ~sub:"bar" ~start:4 ()) ); "lastIndexOf", (fun _ -> - Eq(3, "foobarbaz" |. Js.String.lastIndexOf ~sub:"bar") + Eq(3, "foobarbaz" |. Js.String.lastIndexOf ~sub:"bar" ()) ); "lastIndexOfFrom", (fun _ -> - Eq(3, "foobarbaz" |. Js.String.lastIndexOfFrom ~sub:"bar" ~pos:4) + Eq(3, "foobarbaz" |. Js.String.lastIndexOf ~sub:"bar" ~start:4 ()) ); "localeCompare", (fun _ -> @@ -150,17 +150,17 @@ let suites = Mt.[ ); "slice", (fun _ -> - Eq("bar", "foobarbaz" |. Js.String.slice ~from:3 ~to_:6) + Eq("bar", "foobarbaz" |. Js.String.slice ~start:3 ~end_:6 ()) ); "sliceToEnd", (fun _ -> - Eq("barbaz", "foobarbaz" |. Js.String.sliceToEnd ~from:3) + Eq("barbaz", "foobarbaz" |. Js.String.slice ~start:3 ()) ); "split", (fun _ -> - Eq([| "foo"; "bar"; "baz" |], "foo bar baz" |. Js.String.split ~sep:" ") + Eq([| "foo"; "bar"; "baz" |], "foo bar baz" |. Js.String.split ~sep:" " ()) ); "splitAtMost", (fun _ -> - Eq([| "foo"; "bar" |], "foo bar baz" |. Js.String.splitAtMost ~sep:" " ~limit:2) + Eq([| "foo"; "bar" |], "foo bar baz" |. Js.String.split ~sep:" " ~limit:2 ()) ); "splitByRe", (fun _ -> Eq( @@ -175,24 +175,24 @@ let suites = Mt.[ (* es2015 *) "startsWith", (fun _ -> - Eq(true, "foobarbaz" |. Js.String.startsWith ~prefix:"foo") + Eq(true, "foobarbaz" |. Js.String.startsWith ~prefix:"foo" ()) ); "startsWithFrom", (fun _ -> - Eq(false, "foobarbaz" |. Js.String.startsWithFrom ~prefix:"foo" ~pos:1) + Eq(false, "foobarbaz" |. Js.String.startsWith ~prefix:"foo" ~start:1 ()) ); "substr", (fun _ -> - Eq("barbaz", "foobarbaz" |. Js.String.substr ~from:3) + Eq("barbaz", "foobarbaz" |. Js.String.substr ~start:3 ()) ); "substrAtMost", (fun _ -> - Eq("bar", "foobarbaz" |. Js.String.substrAtMost ~from:3 ~length:3) + Eq("bar", "foobarbaz" |. Js.String.substr ~start:3 ~len:3 ()) ); "substring", (fun _ -> - Eq("bar", "foobarbaz" |. Js.String.substring ~from:3 ~to_:6) + Eq("bar", "foobarbaz" |. Js.String.substring ~start:3 ~end_:6 ()) ); "substringToEnd", (fun _ -> - Eq("barbaz", "foobarbaz" |. Js.String.substringToEnd ~from:3) + Eq("barbaz", "foobarbaz" |. Js.String.substring ~start:3 ()) ); "toLowerCase", (fun _ -> @@ -219,6 +219,6 @@ let suites = Mt.[ "link", (fun _ -> Eq("foo", "foo" |. Js.String.link ~href:"https://reason.ml") ); - __LOC__ , (fun _ -> Ok (Js.String.includes "ab" ~sub:"a")) + __LOC__ , (fun _ -> Ok (Js.String.includes "ab" ~sub:"a" ())) ] ;; Mt.from_pair_suites __MODULE__ suites diff --git a/jscomp/test/re_or_res/reactTestUtils.re b/jscomp/test/re_or_res/reactTestUtils.re index bb558691fd..c400f76566 100644 --- a/jscomp/test/re_or_res/reactTestUtils.re +++ b/jscomp/test/re_or_res/reactTestUtils.re @@ -126,7 +126,7 @@ module DOM = { let findBySelectorAndPartialTextContent = (element, selector, content) => querySelectorAll(element, selector) ->Array.getBy(node => - node->textContent->Js.String.includes(~sub=content) + node->textContent->Js.String.includes(~sub=content, ()) ); }; diff --git a/jscomp/test/re_or_res/reasonReactRouter.re b/jscomp/test/re_or_res/reasonReactRouter.re index 5664b5e00e..40f6ca23e3 100644 --- a/jscomp/test/re_or_res/reasonReactRouter.re +++ b/jscomp/test/re_or_res/reasonReactRouter.re @@ -76,14 +76,14 @@ let path = () => | "/" => [] | raw => /* remove the preceeding /, which every pathname seems to have */ - let raw = Js.String.sliceToEnd(~from=1, raw); + let raw = Js.String.slice(~start=1, raw, ()); /* remove the trailing /, which some pathnames might have. Ugh */ let raw = switch (Js.String.get(raw, Js.String.length(raw) - 1)) { - | "/" => Js.String.slice(~from=0, ~to_=-1, raw) + | "/" => Js.String.slice(~start=0, ~end_=-1, raw, ()) | _ => raw }; - raw |> Js.String.split(~sep="/") |> arrayToList; + raw->(Js.String.split(~sep="/", ())) |> arrayToList; } }; let hash = () => @@ -96,7 +96,7 @@ let hash = () => | raw => /* remove the preceeding #, which every hash seems to have. Why is this even included in location.hash?? */ - raw |> Js.String.sliceToEnd(~from=1) + raw->(Js.String.slice(~start=1, ())) } }; let search = () => @@ -108,7 +108,7 @@ let search = () => | "?" => "" | raw => /* remove the preceeding ?, which every search seems to have. */ - raw |> Js.String.sliceToEnd(~from=1) + raw->Js.String.slice(~start=1, ()) } }; let push = path => From 34846d559b31c5e7e358df6fd3f0ee4879f06e54 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 16 Nov 2023 14:17:24 -0800 Subject: [PATCH 4/5] fix: ci --- .github/workflows/opam-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/opam-build.yml b/.github/workflows/opam-build.yml index 496d08a75f..f8f1fb09ef 100644 --- a/.github/workflows/opam-build.yml +++ b/.github/workflows/opam-build.yml @@ -65,8 +65,8 @@ jobs: - name: Install all deps working-directory: melange-opam-template run: | - opam pin add reason-react-ppx.dev --dev-repo - opam pin add reason-react.dev --dev-repo + opam pin add reason-react-ppx.dev git+https://github.com/reasonml/reason-react#anmonteiro/melange-v3 + opam pin add reason-react.dev git+https://github.com/reasonml/reason-react#anmonteiro/melange-v3 npm install - name: Build basic template From f8ea2f04525c1ceb3006e87501a8f4c8ef2bd0e4 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 16 Nov 2023 14:44:25 -0800 Subject: [PATCH 5/5] more code review fixes --- jscomp/runtime/js_string.ml | 31 ++++++------------- .../test/dist/jscomp/test/js_string_test.js | 10 ++---- jscomp/test/js_string_test.ml | 6 ++-- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/jscomp/runtime/js_string.ml b/jscomp/runtime/js_string.ml index 4260d76aef..13083c63f6 100644 --- a/jscomp/runtime/js_string.ml +++ b/jscomp/runtime/js_string.ml @@ -299,14 +299,14 @@ external normalizeByForm : t -> form:[ `NFC | `NFD | `NFKC | `NFKD ] -> t report for details *) -external repeat : t -> n:int -> t = "repeat" +external repeat : t -> count:int -> t = "repeat" [@@mel.send] -(** [repeat s n] returns a string that consists of [n] repetitions of [s]. - Raises [RangeError] if [n] is negative. +(** [repeat s ~count] returns a string that consists of [count] repetitions of + [s]. Raises [RangeError] if [n] is negative. {[ - repeat "ha" ~n:3 = "hahaha" - repeat "empty" ~n:0 = "" + repeat "ha" ~count:3 = "hahaha" + repeat "empty" ~count:0 = "" ]} *) @@ -470,29 +470,18 @@ external split : t -> ?sep:t -> ?limit:int -> unit -> t array = "split" ]} *) -external splitByRe : t -> regexp:Js_re.t -> t option array = "split" -[@@mel.send] -(** [splitByRe str ~regexp] splits the given [str] at every occurrence of - [regexp] and returns an array of the resulting substrings. - -{[ - splitByRe "art; bed , cog ;dad" ~regexp:[%re "/\\s*[,;]\\s*/"] = [|"art"; "bed"; "cog"; "dad"|];; - splitByRe "has:no:match" ~regexp:[%re "/[,;]/"] = [|"has:no:match"|];; -]}; -*) - -external splitByReAtMost : t -> regexp:Js_re.t -> limit:int -> t option array +external splitByRe : t -> regexp:Js_re.t -> ?limit:int -> unit -> t option array = "split" [@@mel.send] -(** [splitByReAtMost ~regexp ~limit:n str] splits the given [str] at every +(** [splitByRe str ~regexp ?limit ()] splits the given [str] at every occurrence of [regexp] and returns an array of the first [n] resulting substrings. If [n] is negative or greater than the number of substrings, the array will contain all the substrings. {[ - splitByReAtMost "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit: 3 = [|"one"; "two"; "three"|];; - splitByReAtMost "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit: 0 = [| |];; - splitByReAtMost "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit: 8 = [|"one"; "two"; "three"; "four"|];; + splitByRe "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit:3 () = [|"one"; "two"; "three"|];; + splitByRe "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit:0 () = [| |];; + splitByRe "one: two: three: four" [%re "/\\s*:\\s*/"] ~limit:8 () = [|"one"; "two"; "three"; "four"|];; ]}; *) diff --git a/jscomp/test/dist/jscomp/test/js_string_test.js b/jscomp/test/dist/jscomp/test/js_string_test.js index 2dbd6456d0..f25853dd92 100644 --- a/jscomp/test/dist/jscomp/test/js_string_test.js +++ b/jscomp/test/dist/jscomp/test/js_string_test.js @@ -481,7 +481,6 @@ var suites_1 = { hd: [ "splitByRe", (function (param) { - var arg = /(#)(:)?/; return { TAG: /* Eq */0, _0: [ @@ -493,9 +492,7 @@ var suites_1 = { ":", "c" ], - _1: (function (param) { - return param.split(arg); - })("a#b#:c") + _1: "a#b#:c".split(/(#)(:)?/, undefined) }; }) ], @@ -503,7 +500,6 @@ var suites_1 = { hd: [ "splitByReAtMost", (function (param) { - var arg = /(#)(:)?/; return { TAG: /* Eq */0, _0: [ @@ -511,9 +507,7 @@ var suites_1 = { "#", undefined ], - _1: (function (param) { - return param.split(arg, 3); - })("a#b#:c") + _1: "a#b#:c".split(/(#)(:)?/, 3) }; }) ], diff --git a/jscomp/test/js_string_test.ml b/jscomp/test/js_string_test.ml index 983d6ad71c..91137fbeff 100644 --- a/jscomp/test/js_string_test.ml +++ b/jscomp/test/js_string_test.ml @@ -107,7 +107,7 @@ let suites = Mt.[ (* es2015 *) "repeat", (fun _ -> - Eq("foofoofoo", "foo" |. Js.String.repeat ~n:3) + Eq("foofoofoo", "foo" |. Js.String.repeat ~count:3) ); "replace", (fun _ -> @@ -165,12 +165,12 @@ let suites = Mt.[ "splitByRe", (fun _ -> Eq( [| Some "a"; Some "#"; None; Some "b"; Some "#"; Some ":"; Some "c" |], - "a#b#:c" |> Js.String.splitByRe ~regexp:[%re "/(#)(:)?/"]) + "a#b#:c" |. Js.String.splitByRe ~regexp:[%re "/(#)(:)?/"] ()) ); "splitByReAtMost", (fun _ -> Eq( [| Some "a"; Some "#"; None |], - "a#b#:c" |> Js.String.splitByReAtMost ~regexp:[%re "/(#)(:)?/"] ~limit:3) + "a#b#:c" |. Js.String.splitByRe ~regexp:[%re "/(#)(:)?/"] ~limit:3 ()) ); (* es2015 *)