diff --git a/CHANGELOG.md b/CHANGELOG.md index e095ff088d..bd61c9a21c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ These are only breaking changes for unformatted code. - Treat `@meth` annotation as making the type uncurried for backwards compatibitly with some examples https://github.com/rescript-lang/rescript-compiler/pull/5845 - Process `@set` annotation for field update as generating an uncurried function https://github.com/rescript-lang/rescript-compiler/pull/5846 - Treat uncurried application of primitives like curried application, which produces better output https://github.com/rescript-lang/rescript-compiler/pull/5851 +- New internal representation for uncurried functions using built-in type `function$` this avoids having to declare all the possible arities ahead of time https://github.com/rescript-lang/rescript-compiler/pull/5870 # 10.1.1 diff --git a/Makefile b/Makefile index 28edb6e1f0..db4efdf98a 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ test-syntax-roundtrip: build bash ./scripts/testok.sh test-gentype: build - make -C jscomp/gentype_tests/typescript-react-example test + make -C jscomp/gentype_tests/typescript-react-example clean test test-all: test test-gentype diff --git a/jscomp/build_tests/cycle1/input.js b/jscomp/build_tests/cycle1/input.js index 2ea147791d..9c9b0a8dbc 100644 --- a/jscomp/build_tests/cycle1/input.js +++ b/jscomp/build_tests/cycle1/input.js @@ -5,6 +5,8 @@ const fs = require('fs') const path = require('path') var rescript_exe = require("../../../scripts/bin_path").rescript_exe +cp.execSync(`${rescript_exe} clean -with-deps`, { cwd: __dirname, }); + var output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); assert(/is dangling/.test(output.stdout)); diff --git a/jscomp/frontend/ast_core_type.ml b/jscomp/frontend/ast_core_type.ml index ed83c627fc..bdb1924b3e 100644 --- a/jscomp/frontend/ast_core_type.ml +++ b/jscomp/frontend/ast_core_type.ml @@ -132,7 +132,7 @@ let get_uncurry_arity (ty : t) = let get_curry_arity (ty : t) = match ty.ptyp_desc with - | Ptyp_constr ({ txt = Ldot (Ldot (Lident "Js", "Fn"), _) }, [ t ]) -> + | Ptyp_constr ({ txt = Lident "function$" }, [ t; _ ]) -> get_uncurry_arity_aux t 0 | _ -> get_uncurry_arity_aux ty 0 diff --git a/jscomp/frontend/ast_core_type_class_type.ml b/jscomp/frontend/ast_core_type_class_type.ml index 01b862d653..9d2ddf6f58 100644 --- a/jscomp/frontend/ast_core_type_class_type.ml +++ b/jscomp/frontend/ast_core_type_class_type.ml @@ -71,9 +71,9 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) = ptyp_desc = ( Ptyp_arrow (label, args, body) | Ptyp_constr - (* Js.Fn.xx is re-wrapped around only in case Nothing below *) - ( { txt = Ldot (Ldot (Lident "Js", "Fn"), _) }, - [ { ptyp_desc = Ptyp_arrow (label, args, body) } ] ) ); + (* function$<...> is re-wrapped around only in case Nothing below *) + ( { txt = Lident "function$" }, + [ { ptyp_desc = Ptyp_arrow (label, args, body) }; _ ] ) ); (* let it go without regard label names, it will report error later when the label is not empty *) diff --git a/jscomp/frontend/ast_external_process.ml b/jscomp/frontend/ast_external_process.ml index 202735f6e9..ddb74a2f30 100644 --- a/jscomp/frontend/ast_external_process.ml +++ b/jscomp/frontend/ast_external_process.ml @@ -868,15 +868,19 @@ let handle_attributes (loc : Bs_loc.t) (type_annotation : Parsetree.core_type) Location.raise_errorf ~loc "%@uncurry can not be applied to the whole definition"; let prim_name_with_source = { name = prim_name; source = External } in - let type_annotation, build_uncurried_type = match type_annotation.ptyp_desc with - | Ptyp_constr ({txt = Ldot(Ldot(Lident "Js", "Fn"), arity_);_} as lid, [t]) -> - t, fun ~arity x -> - let arity = match arity with - | Some arity -> "arity" ^ string_of_int arity - | None -> arity_ in - let lid = {lid with txt = Longident.Ldot(Ldot(Lident "Js", "Fn"), arity)} in - {x with Parsetree.ptyp_desc = Ptyp_constr (lid, [x])} - | _ -> type_annotation, fun ~arity:_ x -> x in + let type_annotation, build_uncurried_type = + match type_annotation.ptyp_desc with + | Ptyp_constr (({ txt = Lident "function$"; _ } as lid), [ t; arity_ ]) -> + ( t, + fun ~arity x -> + let tArity = + match arity with + | Some arity -> Ast_uncurried.arityType ~loc arity + | None -> arity_ + in + { x with Parsetree.ptyp_desc = Ptyp_constr (lid, [ x; tArity ]) } ) + | _ -> (type_annotation, fun ~arity:_ x -> x) + in let result_type, arg_types_ty = (* Note this assumes external type is syntatic (no abstraction)*) Ast_core_type.list_of_arrow type_annotation diff --git a/jscomp/frontend/ast_literal.ml b/jscomp/frontend/ast_literal.ml index 824c1f6467..1085246c2d 100644 --- a/jscomp/frontend/ast_literal.ml +++ b/jscomp/frontend/ast_literal.ml @@ -55,8 +55,6 @@ module Lid = struct let opaque : t = Ldot (js_internal, "opaque") - let js_fn : t = Ldot (Lident "Js", "Fn") - let js_oo : t = Lident "Js_OO" let js_meth_callback : t = Ldot (js_oo, "Callback") diff --git a/jscomp/frontend/ast_literal.mli b/jscomp/frontend/ast_literal.mli index 2a56339095..ca51dbc4f7 100644 --- a/jscomp/frontend/ast_literal.mli +++ b/jscomp/frontend/ast_literal.mli @@ -39,8 +39,6 @@ module Lid : sig val type_int : t - val js_fn : t - val js_internal_full_apply : t val opaque : t diff --git a/jscomp/frontend/ast_typ_uncurry.ml b/jscomp/frontend/ast_typ_uncurry.ml index d210f40995..7f725a644c 100644 --- a/jscomp/frontend/ast_typ_uncurry.ml +++ b/jscomp/frontend/ast_typ_uncurry.ml @@ -23,9 +23,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) type typ = Parsetree.core_type - type 'a cxt = Ast_helper.loc -> Bs_ast_mapper.mapper -> 'a - type uncurry_type_gen = (Asttypes.arg_label -> typ -> typ -> typ) cxt module Typ = Ast_helper.Typ @@ -63,10 +61,5 @@ let to_uncurry_type loc (mapper : Bs_ast_mapper.mapper) let fn_type = Typ.arrow ~loc label first_arg typ in let arity = Ast_core_type.get_uncurry_arity fn_type in match arity with - | Some 0 -> - Typ.constr { txt = Ldot (Ast_literal.Lid.js_fn, "arity0"); loc } [ typ ] - | Some n -> - Typ.constr - { txt = Ldot (Ast_literal.Lid.js_fn, "arity" ^ string_of_int n); loc } - [ fn_type ] + | Some arity -> Ast_uncurried.uncurriedType ~loc ~arity fn_type | None -> assert false diff --git a/jscomp/frontend/ast_uncurry_gen.ml b/jscomp/frontend/ast_uncurry_gen.ml index 610b716e1f..71ebc172ed 100644 --- a/jscomp/frontend/ast_uncurry_gen.ml +++ b/jscomp/frontend/ast_uncurry_gen.ml @@ -67,8 +67,9 @@ let to_method_callback loc (self : Bs_ast_mapper.mapper) label [ Typ.any ~loc () ]) ); ] ) -let to_uncurry_fn loc (self : Bs_ast_mapper.mapper) (label : Asttypes.arg_label) - pat body async : Parsetree.expression_desc = +let to_uncurry_fn (e : Parsetree.expression) (self : Bs_ast_mapper.mapper) + (label : Asttypes.arg_label) pat body async : Parsetree.expression = + let loc = e.pexp_loc in Bs_syntaxerr.optional_err loc label; let rec aux acc (body : Parsetree.expression) = match Ast_attributes.process_attributes_rev body.pexp_attributes with @@ -97,7 +98,9 @@ let to_uncurry_fn loc (self : Bs_ast_mapper.mapper) (label : Asttypes.arg_label) | _ -> len in Bs_syntaxerr.err_large_arity loc arity; - let arity_s = string_of_int arity in - Pexp_record - ( [ ({ txt = Ldot (Ast_literal.Lid.js_fn, "I" ^ arity_s); loc }, body) ], - None ) + let fun_exp = Ast_uncurried.uncurriedFun ~loc ~arity body in + { + e with + pexp_desc = fun_exp.pexp_desc; + pexp_attributes = fun_exp.pexp_attributes @ e.pexp_attributes; + } diff --git a/jscomp/frontend/ast_uncurry_gen.mli b/jscomp/frontend/ast_uncurry_gen.mli index 12b074c5b9..3367c78914 100644 --- a/jscomp/frontend/ast_uncurry_gen.mli +++ b/jscomp/frontend/ast_uncurry_gen.mli @@ -23,13 +23,13 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) val to_uncurry_fn : - Location.t -> + Parsetree.expression -> Bs_ast_mapper.mapper -> Asttypes.arg_label -> Parsetree.pattern -> Parsetree.expression -> bool -> (* async *) - Parsetree.expression_desc + Parsetree.expression (** [function] can only take one argument, that is the reason we did not adopt it syntax: diff --git a/jscomp/frontend/bs_builtin_ppx.ml b/jscomp/frontend/bs_builtin_ppx.ml index a4dc72630c..17a4487dec 100644 --- a/jscomp/frontend/bs_builtin_ppx.ml +++ b/jscomp/frontend/bs_builtin_ppx.ml @@ -115,17 +115,18 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) | true, pexp_attributes -> Ast_bs_open.convertBsErrorFunction e.pexp_loc self pexp_attributes cases) - | Pexp_record - ( [ - ( { txt = Ldot (Ldot (Lident "Js", "Fn"), _) }, - ({ pexp_desc = Pexp_fun _; pexp_attributes } as inner_exp) ); - ], - None ) - when match Ast_attributes.process_attributes_rev pexp_attributes with + | _ + when Ast_uncurried.exprIsUncurriedFun e + && + match + Ast_attributes.process_attributes_rev + (Ast_uncurried.exprExtractUncurriedFun e).pexp_attributes + with | Meth_callback _, _ -> true | _ -> false -> (* Treat @this (. x, y, z) => ... just like @this (x, y, z) => ... *) - self.expr self inner_exp + let fun_expr = Ast_uncurried.exprExtractUncurriedFun e in + self.expr self fun_expr | Pexp_fun (label, _, pat, body) -> ( let async = Ast_attributes.has_async_payload e.pexp_attributes <> None in match Ast_attributes.process_attributes_rev e.pexp_attributes with @@ -136,12 +137,8 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) Ast_async.make_function_async ~async (default_expr_mapper self e) | Uncurry _, pexp_attributes -> async_context := async; - { - e with - pexp_desc = - Ast_uncurry_gen.to_uncurry_fn e.pexp_loc self label pat body async; - pexp_attributes; - } + Ast_uncurry_gen.to_uncurry_fn { e with pexp_attributes } self label + pat body async | Method _, _ -> Location.raise_errorf ~loc:e.pexp_loc "%@meth is not supported in function expression" diff --git a/jscomp/gentype/TranslateStructure.ml b/jscomp/gentype/TranslateStructure.ml index 406334e465..b8ba8652d0 100644 --- a/jscomp/gentype/TranslateStructure.ml +++ b/jscomp/gentype/TranslateStructure.ml @@ -14,15 +14,9 @@ let rec addAnnotationsToTypes_ ~config ~(expr : Typedtree.expression) in let aName = Ident.name param in { aName; aType } :: nextTypes1 - | ( Texp_record - { fields = [| ({ lbl_name = "I" }, Overridden (_, exprRecord)) |] }, - Tconstr (path, _, _), - _ ) - when match path |> TranslateTypeExprFromTypes.pathToList |> List.rev with - | [ "Js"; "Fn"; _arity ] -> true - | _ -> false -> - (* let uncurried1: Js.Fn.arity1(_) = {I: x => x |> string_of_int} *) - addAnnotationsToTypes_ ~config ~expr:exprRecord argTypes + | ( Texp_construct ({txt = Lident "Function$"}, _, [funExpr]), _, _) -> + (* let uncurried1: function$<_, _> = Function$(x => x |> string_of_int, [`Has_arity1]) *) + addAnnotationsToTypes_ ~config ~expr:funExpr argTypes | ( Texp_apply ({ exp_desc = Texp_ident (path, _, _) }, [ (_, Some expr1) ]), _, _ ) -> ( diff --git a/jscomp/gentype/TranslateTypeExprFromTypes.ml b/jscomp/gentype/TranslateTypeExprFromTypes.ml index 58db8cfc07..36918fac52 100644 --- a/jscomp/gentype/TranslateTypeExprFromTypes.ml +++ b/jscomp/gentype/TranslateTypeExprFromTypes.ml @@ -205,63 +205,7 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = { paramTranslation with type_ = Nullable paramTranslation.type_ } | ([ "Js"; "Promise"; "t" ] | ["promise"]), [ paramTranslation ] -> { paramTranslation with type_ = Promise paramTranslation.type_ } - | ( [ "Js"; "Internal"; "fn" ], - [ { dependencies = argsDependencies; type_ = Tuple ts }; ret ] ) -> - { - dependencies = argsDependencies @ ret.dependencies; - type_ = - Function - { - argTypes = - ts |> List.map (fun type_ -> { aName = ""; aType = type_ }); - componentName = None; - retType = ret.type_; - typeVars = []; - uncurried = true; - }; - } - | ( [ "Js"; "Internal"; "fn" ], - [ - { - dependencies = argsDependencies; - type_ = Variant { noPayloads = [ { label = "Arity_0" } ] }; - }; - ret; - ] ) -> - { - dependencies = argsDependencies @ ret.dependencies; - type_ = - Function - { - argTypes = []; - componentName = None; - retType = ret.type_; - typeVars = []; - uncurried = true; - }; - } - | [ "Js"; "Fn"; "arity0" ], [ ret ] -> - { - dependencies = ret.dependencies; - type_ = - Function - { - argTypes = []; - componentName = None; - retType = ret.type_; - typeVars = []; - uncurried = true; - }; - } - | ( [ - ("Js" | "Js_OO"); - ("Fn" | "Meth"); - ( "arity1" | "arity2" | "arity3" | "arity4" | "arity5" | "arity6" - | "arity7" | "arity8" | "arity9" | "arity10" | "arity11" | "arity12" - | "arity13" | "arity14" | "arity15" | "arity16" | "arity17" | "arity18" - | "arity19" | "arity20" | "arity21" | "arity22" ); - ], - [ arg ] ) -> + | ( [ "function$"], [ arg; _arity ] ) -> { dependencies = arg.dependencies; type_ = @@ -269,70 +213,6 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv = | Function function_ -> Function { function_ with uncurried = true } | _ -> arg.type_); } - | ( [ "Js"; "Internal"; "fn" ], - [ { dependencies = argsDependencies; type_ = singleT }; ret ] ) -> - let argTypes = - (match singleT with - | Variant { payloads = [ { t = Tuple argTypes } ] } -> argTypes - | Variant { payloads = [ { t = type_ } ] } -> [ type_ ] - | _ -> [ singleT ]) - |> List.map (fun type_ -> { aName = ""; aType = type_ }) - in - { - dependencies = argsDependencies @ ret.dependencies; - type_ = - Function - { - argTypes; - componentName = None; - retType = ret.type_; - typeVars = []; - uncurried = true; - }; - } - | ( ([ "Js"; "Internal"; "meth" ] | [ "Js_internalOO"; "meth" ]), - [ - { - dependencies = argsDependencies; - type_ = - Variant - { payloads = [ { case = { label = "Arity_1" }; t = type_ } ] }; - }; - ret; - ] ) -> - { - dependencies = argsDependencies @ ret.dependencies; - type_ = - Function - { - argTypes = [ { aName = ""; aType = type_ } ]; - componentName = None; - retType = ret.type_; - typeVars = []; - uncurried = true; - }; - } - | ( ([ "Js"; "Internal"; "meth" ] | [ "Js_internalOO"; "meth" ]), - [ - { - dependencies = argsDependencies; - type_ = Variant { payloads = [ { t = Tuple ts } ] }; - }; - ret; - ] ) -> - { - dependencies = argsDependencies @ ret.dependencies; - type_ = - Function - { - argTypes = - ts |> List.map (fun type_ -> { aName = ""; aType = type_ }); - componentName = None; - retType = ret.type_; - typeVars = []; - uncurried = true; - }; - } | _ -> defaultCase () type processVariant = { diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json index c0a1dc9ac1..32e24bbf6e 100644 --- a/jscomp/gentype_tests/typescript-react-example/package-lock.json +++ b/jscomp/gentype_tests/typescript-react-example/package-lock.json @@ -21,7 +21,7 @@ }, "../../..": { "name": "rescript", - "version": "10.1.0-rc.3", + "version": "11.0.0-alpha.1", "dev": true, "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", @@ -33,7 +33,8 @@ "devDependencies": { "mocha": "^7.2.0", "nyc": "^15.0.0", - "prettier": "^2.7.1" + "prettier": "^2.7.1", + "rollup": "^0.49.2" } }, "node_modules/@rescript/react": { @@ -294,7 +295,8 @@ "requires": { "mocha": "^7.2.0", "nyc": "^15.0.0", - "prettier": "^2.7.1" + "prettier": "^2.7.1", + "rollup": "^0.49.2" } }, "scheduler": { diff --git a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.bs.js index e17241f3cc..234fe8b1ef 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.bs.js @@ -61,7 +61,7 @@ function unitArgWithoutConversion(param) { return "abc"; } -function unitArgWithoutConversionU() { +function unitArgWithoutConversionU(param) { return "abc"; } @@ -69,7 +69,7 @@ function unitArgWithConversion(param) { return /* A */0; } -function unitArgWithConversionU() { +function unitArgWithConversionU(param) { return /* A */0; } diff --git a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx index f162afffcb..646ed8d367 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.gen.tsx @@ -19,7 +19,7 @@ export type t = "A" | "B"; export const flat: number = DocstringsBS.flat; /** \n * Sign a message with a key.\n *\n * @param message - A message to be signed\n * @param key - The key with which to sign the message\n * @returns A signed message\n */ -export const signMessage: (_1:string, _2:number) => string = DocstringsBS.signMessage; +export const signMessage: (message:string, key:number) => string = DocstringsBS.signMessage; export const one: (a:number) => number = DocstringsBS.one; @@ -33,26 +33,26 @@ export const tree: (a:number, b:number, c:number) => number = function (Arg1: an return result }; -export const oneU: (_1:number) => number = DocstringsBS.oneU; +export const oneU: (a:number) => number = DocstringsBS.oneU; -export const twoU: (_1:number, _2:number) => number = DocstringsBS.twoU; +export const twoU: (a:number, b:number) => number = DocstringsBS.twoU; -export const treeU: (_1:number, _2:number, _3:number) => number = DocstringsBS.treeU; +export const treeU: (a:number, b:number, c:number) => number = DocstringsBS.treeU; export const useParam: (param:number) => number = DocstringsBS.useParam; -export const useParamU: (_1:number) => number = DocstringsBS.useParamU; +export const useParamU: (param:number) => number = DocstringsBS.useParamU; export const unnamed1: (param:number) => number = DocstringsBS.unnamed1; -export const unnamed1U: (_1:number) => number = DocstringsBS.unnamed1U; +export const unnamed1U: (param:number) => number = DocstringsBS.unnamed1U; export const unnamed2: (param_0:number, param_1:number) => number = function (Arg1: any, Arg2: any) { const result = Curry._2(DocstringsBS.unnamed2, Arg1, Arg2); return result }; -export const unnamed2U: (_1:number, _2:number) => number = DocstringsBS.unnamed2U; +export const unnamed2U: (param_0:number, param_1:number) => number = DocstringsBS.unnamed2U; export const grouped: (_1:{ readonly x: number; readonly y: number }, a:number, b:number, c:number, _5:{ readonly z: number }) => number = function (Arg1: any, Arg2: any, Arg3: any, Arg4: any, Arg5: any) { const result = Curry._6(DocstringsBS.grouped, Arg1.x, Arg1.y, Arg2, Arg3, Arg4, Arg5.z); diff --git a/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.bs.js b/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.bs.js index 02086f500b..115577b57c 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.bs.js @@ -23,7 +23,8 @@ var areaValue = ImportJsValueGen$1.area({ }); function getAbs(x) { - return x.getAbs(); + var getAbs$1 = x.getAbs; + return getAbs$1(undefined); } var AbsoluteValue = { @@ -35,7 +36,7 @@ function useGetProp(x) { } function useGetAbs(x) { - return x.getAbs() + 1 | 0; + return getAbs(x) + 1 | 0; } function useColor(prim) { diff --git a/jscomp/gentype_tests/typescript-react-example/src/Uncurried.bs.js b/jscomp/gentype_tests/typescript-react-example/src/Uncurried.bs.js index 5878196f58..14d140416b 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Uncurried.bs.js +++ b/jscomp/gentype_tests/typescript-react-example/src/Uncurried.bs.js @@ -2,7 +2,7 @@ import * as Curry from "rescript/lib/es6/curry.js"; -function uncurried0() { +function uncurried0(param) { return ""; } @@ -31,7 +31,7 @@ function callback2(auth) { } function callback2U(auth) { - return auth.loginU(); + return auth.loginU(undefined); } function sumU(n, m) { diff --git a/jscomp/gentype_tests/typescript-react-example/src/Uncurried.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/Uncurried.gen.tsx index c848ac672d..27fe26be62 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Uncurried.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/Uncurried.gen.tsx @@ -30,11 +30,11 @@ export type authU = { readonly loginU: () => string }; export const uncurried0: () => string = UncurriedBS.uncurried0; -export const uncurried1: (_1:number) => string = UncurriedBS.uncurried1; +export const uncurried1: (x:number) => string = UncurriedBS.uncurried1; -export const uncurried2: (_1:number, _2:string) => string = UncurriedBS.uncurried2; +export const uncurried2: (x:number, y:string) => string = UncurriedBS.uncurried2; -export const uncurried3: (_1:number, _2:string, _3:number) => string = UncurriedBS.uncurried3; +export const uncurried3: (x:number, y:string, z:number) => string = UncurriedBS.uncurried3; export const curried3: (x:number, y:string, z:number) => string = function (Arg1: any, Arg2: any, Arg3: any) { const result = Curry._3(UncurriedBS.curried3, Arg1, Arg2, Arg3); @@ -47,9 +47,9 @@ export const callback2: (auth:auth) => string = UncurriedBS.callback2; export const callback2U: (auth:authU) => string = UncurriedBS.callback2U; -export const sumU: (_1:number, _2:number) => void = UncurriedBS.sumU; +export const sumU: (n:number, m:number) => void = UncurriedBS.sumU; -export const sumU2: (_1:number) => (_1:number) => void = UncurriedBS.sumU2; +export const sumU2: (n:number) => (_1:number) => void = UncurriedBS.sumU2; export const sumCurried: (n:number, _2:number) => void = function (Arg1: any, Arg2: any) { const result = Curry._2(UncurriedBS.sumCurried, Arg1, Arg2); diff --git a/jscomp/ml/ast_uncurried.ml b/jscomp/ml/ast_uncurried.ml new file mode 100644 index 0000000000..2d3838385f --- /dev/null +++ b/jscomp/ml/ast_uncurried.ml @@ -0,0 +1,108 @@ +(* Untyped AST *) + + +let encode_arity_string arity = "Has_arity" ^ string_of_int arity +let decode_arity_string arity_s = int_of_string ((String.sub [@doesNotRaise]) arity_s 9 (String.length arity_s - 9)) + +let arityType ~loc arity = + Ast_helper.Typ.variant ~loc + [ Rtag ({ txt = encode_arity_string arity; loc }, [], true, []) ] + Closed None + +let arityFromType (typ : Parsetree.core_type) = + match typ.ptyp_desc with + | Ptyp_variant ([Rtag ({txt}, _, _, _)], _, _) -> decode_arity_string txt + | _ -> assert false + +let uncurriedType ~loc ~arity tArg = + let tArity = arityType ~loc arity in + Ast_helper.Typ.constr ~loc + { txt = Lident "function$"; loc } + [ tArg; tArity ] + +let arity_to_attributes arity = + [ + ( Location.mknoloc "res.arity", + Parsetree.PStr + [ + Ast_helper.Str.eval + (Ast_helper.Exp.constant + (Pconst_integer (string_of_int arity, None))); + ] ); + ] + +let rec attributes_to_arity (attrs : Parsetree.attributes) = + match attrs with + | ( { txt = "res.arity" }, + PStr + [ + { + pstr_desc = + Pstr_eval + ({ pexp_desc = Pexp_constant (Pconst_integer (arity, _)) }, _); + }; + ] ) + :: _ -> + int_of_string arity + | _ :: rest -> attributes_to_arity rest + | _ -> assert false + +let uncurriedFun ~loc ~arity funExpr = + Ast_helper.Exp.construct ~loc + ~attrs:(arity_to_attributes arity) + { txt = Lident "Function$"; loc } + (Some funExpr) + +let exprIsUncurriedFun (expr : Parsetree.expression) = + match expr.pexp_desc with + | Pexp_construct ({ txt = Lident "Function$" }, Some _) -> true + | _ -> false + +let exprExtractUncurriedFun (expr : Parsetree.expression) = + match expr.pexp_desc with + | Pexp_construct ({ txt = Lident "Function$" }, Some e) -> e + | _ -> assert false + +let typeIsUncurriedFun (typ : Parsetree.core_type) = + match typ.ptyp_desc with + | Ptyp_constr ({txt = Lident "function$"}, [{ptyp_desc = Ptyp_arrow _}; _]) -> + true + | _ -> false + +let typeExtractUncurriedFun (typ : Parsetree.core_type) = + match typ.ptyp_desc with + | Ptyp_constr ({txt = Lident "function$"}, [tArg; tArity]) -> + (arityFromType tArity, tArg) + | _ -> assert false + +(* Typed AST *) + +let arity_to_type arity = + let arity_s = encode_arity_string arity in + Ctype.newty + (Tvariant + { + row_fields = [ (arity_s, Rpresent None) ]; + row_more = Ctype.newty Tnil; + row_bound = (); + row_closed = true; + row_fixed = false; + row_name = None; + }) + +let type_to_arity (tArity : Types.type_expr) = + match tArity.desc with + | Tvariant { row_fields = [ (label, _) ] } -> decode_arity_string label + | _ -> assert false + +let mk_js_fn ~env ~arity t = + let typ_arity = arity_to_type arity in + let lid : Longident.t = Lident "function$" in + let path = Env.lookup_type lid env in + Ctype.newconstr path [ t; typ_arity ] + +let uncurried_type_get_arity ~env typ = + match (Ctype.expand_head env typ).desc with + | Tconstr (Pident { name = "function$" }, [ _t; tArity ], _) -> + type_to_arity tArity + | _ -> assert false diff --git a/jscomp/ml/predef.ml b/jscomp/ml/predef.ml index fec66b1c79..c9516c19de 100644 --- a/jscomp/ml/predef.ml +++ b/jscomp/ml/predef.ml @@ -49,6 +49,7 @@ and ident_floatarray = ident_create "floatarray" and ident_unknown = ident_create "unknown" and ident_promise = ident_create "promise" +and ident_uncurried = ident_create "function$" type test = | For_sure_yes @@ -176,8 +177,9 @@ and ident_nil = ident_create "[]" and ident_cons = ident_create "::" and ident_none = ident_create "None" and ident_some = ident_create "Some" - and ident_ctor_unknown = ident_create "Unknown" +and ident_ctor_uncurried = ident_create "Function$" + let common_initial_env add_type add_extension empty_env = let decl_bool = {decl_abstr with @@ -211,6 +213,15 @@ let common_initial_env add_type add_extension empty_env = type_arity = 1; type_kind = Type_variant([cstr ident_none []; cstr ident_some [tvar]]); type_variance = [Variance.covariant]} + and decl_uncurried = + let tvar1, tvar2 = newgenvar(), newgenvar() in + {decl_abstr with + type_params = [tvar1; tvar2]; + type_arity = 2; + type_kind = Type_variant([cstr ident_ctor_uncurried [tvar1]]); + type_variance = [Variance.covariant; Variance.covariant]; + type_unboxed = Types.unboxed_true_default_false; + } and decl_unknown = let tvar = newgenvar () in {decl_abstr with @@ -273,13 +284,14 @@ let common_initial_env add_type add_extension empty_env = add_type ident_unit decl_unit ( add_type ident_bool decl_bool ( add_type ident_float decl_abstr ( - add_type ident_unknown decl_unknown( + add_type ident_unknown decl_unknown ( + add_type ident_uncurried decl_uncurried ( add_type ident_string decl_abstr ( add_type ident_int decl_abstr_imm ( add_type ident_extension_constructor decl_abstr ( add_type ident_floatarray decl_abstr ( add_type ident_promise decl_promise ( - empty_env)))))))))))))))))))))))) + empty_env))))))))))))))))))))))))) let build_initial_env add_type add_exception empty_env = let common = common_initial_env add_type add_exception empty_env in diff --git a/jscomp/ml/translcore.ml b/jscomp/ml/translcore.ml index c138c0c137..21f3021552 100644 --- a/jscomp/ml/translcore.ml +++ b/jscomp/ml/translcore.ml @@ -775,6 +775,21 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda = with Not_constant -> Lprim (Pmakeblock Blk_tuple, ll, e.exp_loc)) | Texp_construct ({ txt = Lident "false" }, _, []) -> Lconst Const_false | Texp_construct ({ txt = Lident "true" }, _, []) -> Lconst Const_true + | Texp_construct ({ txt = Lident "Function$"}, _, [expr]) -> + (* ReScript uncurried encoding *) + let loc = expr.exp_loc in + let lambda = transl_exp expr in + let arity_s = Ast_uncurried.uncurried_type_get_arity ~env:e.exp_env e.exp_type |> string_of_int in + let prim = + Primitive.make ~name:"#fn_mk" ~alloc:true ~native_name:arity_s + ~native_repr_args:[ Same_as_ocaml_repr ] + ~native_repr_res:Same_as_ocaml_repr + in + Lprim + ( Pccall prim + (* could be replaced with Opaque in the future except arity 0*), + [ lambda ], + loc ) | Texp_construct (lid, cstr, args) -> ( let ll = transl_list args in if cstr.cstr_inlined <> None then diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index e4f6e55b8d..ff6858b6d3 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -2104,6 +2104,12 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = exp_attributes = sexp.pexp_attributes; exp_env = env } | Pexp_construct(lid, sarg) -> + (match lid.txt with + | Lident "Function$" -> + let arity = Ast_uncurried.attributes_to_arity sexp.pexp_attributes in + let uncurried_typ = Ast_uncurried.mk_js_fn ~env ~arity (newvar()) in + unify_exp_types loc env ty_expected uncurried_typ + | _ -> ()); type_construct env loc lid sarg ty_expected sexp.pexp_attributes | Pexp_variant(l, sarg) -> (* Keep sharing *) @@ -2976,25 +2982,17 @@ and type_application uncurried env funct (sargs : sargs) : targs * Types.type_ex tvar || List.mem l ls in let ignored = ref [] in - let mk_js_fn arity t = - let a = "arity" ^ string_of_int arity in - let lid:Longident.t = Ldot (Ldot (Lident "Js", "Fn"), a) in - let path = Env.lookup_type lid env in - newconstr path [t] in let has_uncurried_type t = match (expand_head env t).desc with - | Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),a,_),[t],_) -> - let arity = - if String.sub a 0 5 = "arity" - then int_of_string (String.sub a 5 (String.length a - 5)) - else 0 in - Some (arity, t) + | Tconstr (Pident {name = "function$"},[t; tArity],_) -> + let arity = Ast_uncurried.type_to_arity tArity in + Some (arity, t) | _ -> None in let force_uncurried_type funct = match has_uncurried_type funct.exp_type with | None -> let arity = List.length sargs in - let js_fn = mk_js_fn arity (newvar()) in + let js_fn = Ast_uncurried.mk_js_fn ~env ~arity (newvar()) in unify_exp env funct js_fn | Some _ -> () in let extract_uncurried_type t = @@ -3013,7 +3011,7 @@ and type_application uncurried env funct (sargs : sargs) : targs * Types.type_ex if uncurried && not fully_applied then raise(Error(funct.exp_loc, env, Uncurried_arity_mismatch (t, arity, List.length sargs))); - let newT = if fully_applied then newT else mk_js_fn newarity newT in + let newT = if fully_applied then newT else Ast_uncurried.mk_js_fn ~env ~arity:newarity newT in (fully_applied, newT) | _ -> (false, newT) in @@ -3654,16 +3652,6 @@ let report_error env ppf = function fprintf ppf "Variable %s must occur on both sides of this | pattern" (Ident.name id); spellcheck_idents ppf id valid_idents - | Expr_type_clash ( - (_, {desc = Tarrow _}) :: - (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),_,_)}) :: _ - ) -> - fprintf ppf "This function is a curried function where an uncurried function is expected" - | Expr_type_clash ( - (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),a,_),_,_)}) :: - (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),b,_),_,_)}) :: _ - ) when a <> b -> - fprintf ppf "This function has %s but was expected %s" a b | Expr_type_clash ( (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js_OO"},"Meth",_),a,_),_,_)}) :: (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js_OO"},"Meth",_),b,_),_,_)}) :: _ diff --git a/jscomp/ml/typedecl.ml b/jscomp/ml/typedecl.ml index 145d7c7a67..36097256f8 100644 --- a/jscomp/ml/typedecl.ml +++ b/jscomp/ml/typedecl.ml @@ -1593,8 +1593,8 @@ let rec parse_native_repr_attributes env core_type ty = let parse_native_repr_attributes env core_type ty = match core_type.ptyp_desc, (Ctype.repr ty).desc with - | Ptyp_constr ({txt = Ldot(Ldot(Lident "Js", "Fn"),_)}, [{ptyp_desc = Ptyp_arrow (_, _, ct2)}]), - Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[{desc = Tarrow (_, _, t2, _)}],_) -> + | Ptyp_constr ({txt = Lident "function$"}, [{ptyp_desc = Ptyp_arrow (_, _, ct2)}; _]), + Tconstr (Pident {name = "function$"},[{desc = Tarrow (_, _, t2, _)}; _],_) -> let repr_args, repr_res = parse_native_repr_attributes env ct2 t2 in let native_repr_args = Same_as_ocaml_repr :: repr_args in (native_repr_args, repr_res) diff --git a/jscomp/others/js.ml b/jscomp/others/js.ml index 7abe52f719..c8203dad14 100644 --- a/jscomp/others/js.ml +++ b/jscomp/others/js.ml @@ -74,49 +74,13 @@ type 'a t = < .. > as 'a (** JS object type *) -(**/**) - -(* internal types for FFI, these types are not used by normal users - Absent cmi file when looking up module alias. -*) - -module Fn = struct - type 'a arity0 = { i0 : unit -> 'a [@internal] } - type 'a arity1 = { i1 : 'a [@internal] } - type 'a arity2 = { i2 : 'a [@internal] } - type 'a arity3 = { i3 : 'a [@internal] } - type 'a arity4 = { i4 : 'a [@internal] } - type 'a arity5 = { i5 : 'a [@internal] } - type 'a arity6 = { i6 : 'a [@internal] } - type 'a arity7 = { i7 : 'a [@internal] } - type 'a arity8 = { i8 : 'a [@internal] } - type 'a arity9 = { i9 : 'a [@internal] } - type 'a arity10 = { i10 : 'a [@internal] } - type 'a arity11 = { i11 : 'a [@internal] } - type 'a arity12 = { i12 : 'a [@internal] } - type 'a arity13 = { i13 : 'a [@internal] } - type 'a arity14 = { i14 : 'a [@internal] } - type 'a arity15 = { i15 : 'a [@internal] } - type 'a arity16 = { i16 : 'a [@internal] } - type 'a arity17 = { i17 : 'a [@internal] } - type 'a arity18 = { i18 : 'a [@internal] } - type 'a arity19 = { i19 : 'a [@internal] } - type 'a arity20 = { i20 : 'a [@internal] } - type 'a arity21 = { i21 : 'a [@internal] } - type 'a arity22 = { i22 : 'a [@internal] } -end - -(**/**) - module MapperRt = Js_mapperRt module Internal = struct - open Fn - external opaqueFullApply : 'a -> 'a = "%uncurried_apply" (* Use opaque instead of [._n] to prevent some optimizations happening *) - external run : 'a arity0 -> 'a = "#run" + external run : (unit -> 'a [@bs]) -> 'a = "#run" external opaque : 'a -> 'a = "%opaque" end diff --git a/jscomp/others/release.ninja b/jscomp/others/release.ninja index fc6df3fc9c..aa597b742f 100644 --- a/jscomp/others/release.ninja +++ b/jscomp/others/release.ninja @@ -47,7 +47,7 @@ o others/js_obj.cmi others/js_obj.cmj : cc others/js_obj.ml | others/belt_intern o others/js_option.cmj : cc_cmi others/js_option.ml | others/belt_internals.cmi others/js.cmi others/js_exn.cmj others/js_option.cmi $bsc o others/js_option.cmi : cc others/js_option.mli | others/belt_internals.cmi others/js.cmi $bsc o others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.ml | others/belt_internals.cmi others/js.cmi others/js_promise2.cmj $bsc -o others/js_promise2.cmi others/js_promise2.cmj : cc others/js_promise2.res | others/belt_internals.cmi others/js.cmi others/js.cmj $bsc +o others/js_promise2.cmi others/js_promise2.cmj : cc others/js_promise2.res | others/belt_internals.cmi others/js.cmi $bsc o others/js_re.cmi others/js_re.cmj : cc others/js_re.ml | others/belt_internals.cmi others/js.cmi others/js.cmj $bsc o others/js_result.cmj : cc_cmi others/js_result.ml | others/belt_internals.cmi others/js.cmi others/js_result.cmi $bsc o others/js_result.cmi : cc others/js_result.mli | others/belt_internals.cmi others/js.cmi $bsc diff --git a/jscomp/runtime/js.ml b/jscomp/runtime/js.ml index 212e84155a..7ed38a6058 100644 --- a/jscomp/runtime/js.ml +++ b/jscomp/runtime/js.ml @@ -44,91 +44,13 @@ (**/**) (** Types for JS objects *) type 'a t = < .. > as 'a -(**/**) - -(* internal types for FFI, these types are not used by normal users - Absent cmi file when looking up module alias. -*) -module Fn = struct - type 'a arity0 = { - i0 : unit -> 'a [@internal] - } - type 'a arity1 = { - i1 : 'a [@internal] - } - type 'a arity2 = { - i2 : 'a [@internal] - } - type 'a arity3 = { - i3 : 'a [@internal] - } - type 'a arity4 = { - i4 : 'a [@internal] - } - type 'a arity5 = { - i5 : 'a [@internal] - } - type 'a arity6 = { - i6 : 'a [@internal] - } - type 'a arity7 = { - i7 : 'a [@internal] - } - type 'a arity8 = { - i8 : 'a [@internal] - } - type 'a arity9 = { - i9 : 'a [@internal] - } - type 'a arity10 = { - i10 : 'a [@internal] - } - type 'a arity11 = { - i11 : 'a [@internal] - } - type 'a arity12 = { - i12 : 'a [@internal] - } - type 'a arity13 = { - i13 : 'a [@internal] - } - type 'a arity14 = { - i14 : 'a [@internal] - } - type 'a arity15 = { - i15 : 'a [@internal] - } - type 'a arity16 = { - i16 : 'a [@internal] - } - type 'a arity17 = { - i17 : 'a [@internal] - } - type 'a arity18 = { - i18 : 'a [@internal] - } - type 'a arity19 = { - i19 : 'a [@internal] - } - type 'a arity20 = { - i20 : 'a [@internal] - } - type 'a arity21 = { - i21 : 'a [@internal] - } - type 'a arity22 = { - i22 : 'a [@internal] - } -end -(**/**) module MapperRt = Js_mapperRt module Internal = struct - open Fn external opaqueFullApply : 'a -> 'a = "%uncurried_apply" (* Use opaque instead of [._n] to prevent some optimizations happening *) - external run : 'a arity0 -> 'a = "#run" + external run : (unit -> 'a [@bs]) -> 'a = "#run" external opaque : 'a -> 'a = "%opaque" end diff --git a/jscomp/super_errors/super_typecore.ml b/jscomp/super_errors/super_typecore.ml index c212ac61c4..1e524203b4 100644 --- a/jscomp/super_errors/super_typecore.ml +++ b/jscomp/super_errors/super_typecore.ml @@ -119,21 +119,11 @@ let print_expr_type_clash env trace ppf = begin show_extra_help ppf env trace; end -let reportJsFnArityMismatch ~arityA ~arityB ppf = - let extractArity s = - if Ext_string.starts_with s "arity" then - (* get the number part of e.g. arity12 *) - (* assumption: the module Js.Fn only contains types from arity0 to arity22 *) - String.sub s 5 ((String.length s) - 5) - else - raise (Invalid_argument "Unrecognized arity type name.") - in - let firstNumber = extractArity arityA in +let reportArityMismatch ~arityA ~arityB ppf = fprintf ppf "This function expected @{%s@} %s, but got @{%s@}" - firstNumber - (if firstNumber = "1" then "argument" else "arguments") - (extractArity arityB) - + arityA + (if arityA = "1" then "argument" else "arguments") + arityB (* Pasted from typecore.ml. Needed for some cases in report_error below *) (* Records *) @@ -174,16 +164,18 @@ let report_error env ppf = function fprintf ppf "The variable %s on the left-hand side of this or-pattern has type" (Ident.name id)) (function ppf -> fprintf ppf "but on the right-hand side it has type") - | Expr_type_clash ( - (_, {desc = Tarrow _}) :: - (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),_,_)}) :: _ - ) -> + | Expr_type_clash ( + (_, {desc = Tarrow _}) :: + (_, {desc = Tconstr (Pident {name = "function$"},_,_)}) :: _ + ) -> fprintf ppf "This function is a curried function where an uncurried function is expected" | Expr_type_clash ( - (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),arityA,_),_,_)}) :: - (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),arityB,_),_,_)}) :: _ - ) when arityA <> arityB -> - reportJsFnArityMismatch ~arityA ~arityB ppf + (_, {desc = Tconstr (Pident {name = "function$"},[_; tA],_)}) :: + (_, {desc = Tconstr (Pident {name = "function$"},[_; tB],_)}) :: _ + ) when Ast_uncurried.type_to_arity tA <> Ast_uncurried.type_to_arity tB -> + let arityA = Ast_uncurried.type_to_arity tA |> string_of_int in + let arityB = Ast_uncurried.type_to_arity tB |> string_of_int in + reportArityMismatch ~arityA ~arityB ppf | Expr_type_clash ( (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js_OO"},"Meth",_),a,_),_,_)}) :: (_, {desc = Tconstr (Pdot (Pdot(Pident {name = "Js_OO"},"Meth",_),b,_),_,_)}) :: _ @@ -287,20 +279,6 @@ let report_error env ppf = function name (*kind*) Printtyp.path p; end; spellcheck ppf name valid_names; - | Name_type_mismatch ( - "record", - Ldot (Ldot ((Lident "Js"), "Fn"), _arityFieldName), - ( - _, - (Pdot (Pdot ((Pident {name = "Js"}), "Fn", _), arityA, _)) - ), - [( - _, - (Pdot (Pdot ((Pident {name = "Js"}), "Fn", _), arityB, _)) - )] - ) -> - (* modified *) - reportJsFnArityMismatch ~arityA ~arityB ppf | anythingElse -> Typecore.super_report_error_no_wrap_printing_env env ppf anythingElse diff --git a/jscomp/test/flow_parser_reg_test.js b/jscomp/test/flow_parser_reg_test.js index e7401b5319..69602d9c49 100644 --- a/jscomp/test/flow_parser_reg_test.js +++ b/jscomp/test/flow_parser_reg_test.js @@ -15477,51 +15477,67 @@ function parse(content, options) { } } }; - var type_param = function (param) { - var tp = param[1]; - var variance = function (param) { - if (param) { - return string("minus"); - } else { - return string("plus"); - } - }; - return node("TypeParameter", param[0], [ + var 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], [ [ - "name", - string(tp.name) + "object", + _object ], [ - "bound", - option(type_annotation, tp.bound) - ], + "property", + jsx_identifier(member_expression.property) + ] + ]); + }; + var jsx_namespaced_name = function (param) { + var namespaced_name = param[1]; + return node("JSXNamespacedName", param[0], [ [ - "variance", - option(variance, tp.variance) + "namespace", + jsx_identifier(namespaced_name.namespace) ], [ - "default", - option(_type, tp.default) + "name", + jsx_identifier(namespaced_name.name) ] ]); }; - var type_alias = function (param) { - var alias = param[1]; - return node("TypeAlias", param[0], [ + var jsx_identifier = function (param) { + return node("JSXIdentifier", param[0], [[ + "name", + string(param[1].name) + ]]); + }; + var jsx_element = function (param) { + var element = param[1]; + return node("JSXElement", param[0], [ [ - "id", - identifier(alias.id) + "openingElement", + jsx_opening(element.openingElement) ], [ - "typeParameters", - option(type_parameter_declaration, alias.typeParameters) + "closingElement", + option(jsx_closing, element.closingElement) ], [ - "right", - _type(alias.right) + "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 identifier = function (param) { var id = param[1]; return node("Identifier", param[0], [ @@ -15539,782 +15555,585 @@ function parse(content, options) { ] ]); }; - var declare_function = function (param) { - return node("DeclareFunction", param[0], [[ - "id", - identifier(param[1].id) - ]]); - }; - var $$catch = function (param) { - var c = param[1]; - return node("CatchClause", param[0], [ - [ - "param", - pattern(c.param) - ], - [ - "guard", - option(expression, c.guard) - ], - [ - "body", - block(c.body) - ] - ]); - }; - var variable_declaration = function (param) { - var $$var = param[1]; - var match = $$var.kind; - var kind; - switch (match) { - case /* Var */0 : - kind = "var"; - break; - case /* Let */1 : - kind = "let"; - break; - case /* Const */2 : - kind = "const"; - break; - - } - return node("VariableDeclaration", param[0], [ - [ - "declarations", - array_of_list(variable_declarator, $$var.declarations) - ], - [ - "kind", - string(kind) - ] - ]); - }; - var type_annotation = function (param) { - return node("TypeAnnotation", param[0], [[ - "typeAnnotation", - _type(param[1]) - ]]); - }; - var statement = function (param) { - var b = param[1]; + var expression = function (param) { + var arr = param[1]; var loc = param[0]; - if (typeof b === "number") { - if (b === /* Empty */0) { - return node("EmptyStatement", loc, []); - } else { - return node("DebuggerStatement", loc, []); - } + if (typeof arr === "number") { + return node("ThisExpression", loc, []); } - switch (b.TAG | 0) { - case /* Block */0 : - return block([ + switch (arr.TAG | 0) { + case /* Array */0 : + return node("ArrayExpression", loc, [[ + "elements", + array_of_list((function (param) { + return option(expression_or_spread, param); + }), arr._0.elements) + ]]); + case /* Object */1 : + return node("ObjectExpression", loc, [[ + "properties", + array_of_list(object_property, arr._0.properties) + ]]); + case /* Function */2 : + return function_expression([ loc, - b._0 + arr._0 ]); - case /* Expression */1 : - return node("ExpressionStatement", loc, [[ - "expression", - expression(b._0.expression) - ]]); - case /* If */2 : - var _if = b._0; - return node("IfStatement", loc, [ + case /* ArrowFunction */3 : + var arrow = arr._0; + var b = arrow.body; + var body; + body = b.TAG === /* BodyBlock */0 ? block(b._0) : expression(b._0); + return node("ArrowFunctionExpression", loc, [ [ - "test", - expression(_if.test) + "id", + option(identifier, arrow.id) ], [ - "consequent", - statement(_if.consequent) + "params", + array_of_list(pattern, arrow.params) ], [ - "alternate", - option(statement, _if.alternate) - ] - ]); - case /* Labeled */3 : - var labeled = b._0; - return node("LabeledStatement", loc, [ + "defaults", + array_of_list((function (param) { + return option(expression, param); + }), arrow.defaults) + ], [ - "label", - identifier(labeled.label) + "rest", + option(identifier, arrow.rest) ], [ "body", - statement(labeled.body) - ] - ]); - case /* Break */4 : - return node("BreakStatement", loc, [[ - "label", - option(identifier, b._0.label) - ]]); - case /* Continue */5 : - return node("ContinueStatement", loc, [[ - "label", - option(identifier, b._0.label) - ]]); - case /* With */6 : - var _with = b._0; - return node("WithStatement", loc, [ + body + ], [ - "object", - expression(_with._object) + "async", + bool(arrow.async) ], [ - "body", - statement(_with.body) - ] - ]); - case /* TypeAlias */7 : - return type_alias([ - loc, - b._0 - ]); - case /* Switch */8 : - var $$switch = b._0; - return node("SwitchStatement", loc, [ + "generator", + bool(arrow.generator) + ], [ - "discriminant", - expression($$switch.discriminant) + "expression", + bool(arrow.expression) ], [ - "cases", - array_of_list($$case, $$switch.cases) + "returnType", + option(type_annotation, arrow.returnType) ], [ - "lexical", - bool($$switch.lexical) + "typeParameters", + option(type_parameter_declaration, arrow.typeParameters) ] ]); - case /* Return */9 : - return node("ReturnStatement", loc, [[ - "argument", - option(expression, b._0.argument) + case /* Sequence */4 : + return node("SequenceExpression", loc, [[ + "expressions", + array_of_list(expression, arr._0.expressions) ]]); - case /* Throw */10 : - return node("ThrowStatement", loc, [[ - "argument", - expression(b._0.argument) - ]]); - case /* Try */11 : - var _try = b._0; - return node("TryStatement", loc, [ - [ - "block", - block(_try.block) - ], - [ - "handler", - option($$catch, _try.handler) - ], - [ - "guardedHandlers", - array_of_list($$catch, _try.guardedHandlers) - ], - [ - "finalizer", - option(block, _try.finalizer) - ] - ]); - case /* While */12 : - var _while = b._0; - return node("WhileStatement", loc, [ - [ - "test", - expression(_while.test) - ], - [ - "body", - statement(_while.body) - ] - ]); - case /* DoWhile */13 : - var dowhile = b._0; - return node("DoWhileStatement", loc, [ - [ - "body", - statement(dowhile.body) - ], - [ - "test", - expression(dowhile.test) - ] - ]); - case /* For */14 : - var _for = b._0; - var init = function (init$1) { - if (init$1.TAG === /* InitDeclaration */0) { - return variable_declaration(init$1._0); - } else { - return expression(init$1._0); - } - }; - return node("ForStatement", loc, [ - [ - "init", - option(init, _for.init) - ], + case /* Unary */5 : + var unary = arr._0; + var match = unary.operator; + if (match >= 7) { + return node("AwaitExpression", loc, [[ + "argument", + expression(unary.argument) + ]]); + } + var match$1 = unary.operator; + var operator; + switch (match$1) { + case /* Minus */0 : + operator = "-"; + break; + case /* Plus */1 : + operator = "+"; + break; + case /* Not */2 : + operator = "!"; + break; + case /* BitNot */3 : + operator = "~"; + break; + case /* Typeof */4 : + operator = "typeof"; + break; + case /* Void */5 : + operator = "void"; + break; + case /* Delete */6 : + operator = "delete"; + break; + case /* Await */7 : + throw { + RE_EXN_ID: "Failure", + _1: "matched above", + Error: new Error() + }; + + } + return node("UnaryExpression", loc, [ [ - "test", - option(expression, _for.test) + "operator", + string(operator) ], [ - "update", - option(expression, _for.update) + "prefix", + bool(unary.prefix) ], [ - "body", - statement(_for.body) + "argument", + expression(unary.argument) ] ]); - case /* ForIn */15 : - var forin = b._0; - var left = forin.left; - var left$1; - left$1 = left.TAG === /* LeftDeclaration */0 ? variable_declaration(left._0) : expression(left._0); - return node("ForInStatement", loc, [ - [ - "left", - left$1 - ], - [ - "right", - expression(forin.right) - ], + case /* Binary */6 : + var binary = arr._0; + var match$2 = binary.operator; + var operator$1; + switch (match$2) { + case /* Equal */0 : + operator$1 = "=="; + break; + case /* NotEqual */1 : + operator$1 = "!="; + break; + case /* StrictEqual */2 : + operator$1 = "==="; + break; + case /* StrictNotEqual */3 : + operator$1 = "!=="; + break; + case /* LessThan */4 : + operator$1 = "<"; + break; + case /* LessThanEqual */5 : + operator$1 = "<="; + break; + case /* GreaterThan */6 : + operator$1 = ">"; + break; + case /* GreaterThanEqual */7 : + operator$1 = ">="; + break; + case /* LShift */8 : + operator$1 = "<<"; + break; + case /* RShift */9 : + operator$1 = ">>"; + break; + case /* RShift3 */10 : + operator$1 = ">>>"; + break; + case /* Plus */11 : + operator$1 = "+"; + break; + case /* Minus */12 : + operator$1 = "-"; + break; + case /* Mult */13 : + operator$1 = "*"; + break; + case /* Exp */14 : + operator$1 = "**"; + break; + case /* Div */15 : + operator$1 = "/"; + break; + case /* Mod */16 : + operator$1 = "%"; + break; + case /* BitOr */17 : + operator$1 = "|"; + break; + case /* Xor */18 : + operator$1 = "^"; + break; + case /* BitAnd */19 : + operator$1 = "&"; + break; + case /* In */20 : + operator$1 = "in"; + break; + case /* Instanceof */21 : + operator$1 = "instanceof"; + break; + + } + return node("BinaryExpression", loc, [ [ - "body", - statement(forin.body) + "operator", + string(operator$1) ], - [ - "each", - bool(forin.each) - ] - ]); - case /* ForOf */16 : - var forof = b._0; - var left$2 = forof.left; - var left$3; - left$3 = left$2.TAG === /* LeftDeclaration */0 ? variable_declaration(left$2._0) : expression(left$2._0); - return node("ForOfStatement", loc, [ [ "left", - left$3 + expression(binary.left) ], [ "right", - expression(forof.right) - ], - [ - "body", - statement(forof.body) - ] - ]); - case /* Let */17 : - var _let = b._0; - return node("LetStatement", loc, [ - [ - "head", - array_of_list(let_assignment, _let.head) - ], - [ - "body", - statement(_let.body) - ] - ]); - case /* FunctionDeclaration */18 : - var fn = b._0; - var id = fn.id; - var match = id !== undefined ? [ - "FunctionDeclaration", - identifier(id) - ] : [ - "FunctionExpression", - $$null - ]; - var b$1 = fn.body; - var body; - body = b$1.TAG === /* BodyBlock */0 ? block(b$1._0) : expression(b$1._0); - return node(match[0], loc, [ - [ - "id", - match[1] - ], - [ - "params", - array_of_list(pattern, fn.params) - ], - [ - "defaults", - array_of_list((function (param) { - return option(expression, param); - }), fn.defaults) - ], - [ - "rest", - option(identifier, fn.rest) - ], - [ - "body", - body - ], - [ - "async", - bool(fn.async) - ], - [ - "generator", - bool(fn.generator) - ], - [ - "expression", - bool(fn.expression) - ], - [ - "returnType", - option(type_annotation, fn.returnType) - ], - [ - "typeParameters", - option(type_parameter_declaration, fn.typeParameters) + expression(binary.right) ] ]); - case /* VariableDeclaration */19 : - return variable_declaration([ - loc, - b._0 - ]); - case /* ClassDeclaration */20 : - var param$1 = [ - loc, - b._0 - ]; - var c = param$1[1]; - var id$1 = c.id; - var match$1 = id$1 !== undefined ? [ - "ClassDeclaration", - identifier(id$1) - ] : [ - "ClassExpression", - $$null - ]; - return node(match$1[0], param$1[0], [ + case /* Assignment */7 : + var assignment = arr._0; + var match$3 = assignment.operator; + var operator$2; + switch (match$3) { + case /* Assign */0 : + operator$2 = "="; + break; + case /* PlusAssign */1 : + operator$2 = "+="; + break; + case /* MinusAssign */2 : + operator$2 = "-="; + break; + case /* MultAssign */3 : + operator$2 = "*="; + break; + case /* ExpAssign */4 : + operator$2 = "**="; + break; + case /* DivAssign */5 : + operator$2 = "/="; + break; + case /* ModAssign */6 : + operator$2 = "%="; + break; + case /* LShiftAssign */7 : + operator$2 = "<<="; + break; + case /* RShiftAssign */8 : + operator$2 = ">>="; + break; + case /* RShift3Assign */9 : + operator$2 = ">>>="; + break; + case /* BitOrAssign */10 : + operator$2 = "|="; + break; + case /* BitXorAssign */11 : + operator$2 = "^="; + break; + case /* BitAndAssign */12 : + operator$2 = "&="; + break; + + } + return node("AssignmentExpression", loc, [ [ - "id", - match$1[1] + "operator", + string(operator$2) ], [ - "body", - class_body(c.body) + "left", + pattern(assignment.left) ], [ - "superClass", - option(expression, c.superClass) + "right", + expression(assignment.right) + ] + ]); + case /* Update */8 : + var update = arr._0; + var match$4 = update.operator; + var operator$3 = match$4 ? "--" : "++"; + return node("UpdateExpression", loc, [ + [ + "operator", + string(operator$3) ], [ - "typeParameters", - option(type_parameter_declaration, c.typeParameters) + "argument", + expression(update.argument) ], [ - "superTypeParameters", - option(type_parameter_instantiation, c.superTypeParameters) + "prefix", + bool(update.prefix) + ] + ]); + case /* Logical */9 : + var logical = arr._0; + var match$5 = logical.operator; + var operator$4 = match$5 ? "&&" : "||"; + return node("LogicalExpression", loc, [ + [ + "operator", + string(operator$4) ], [ - "implements", - array_of_list(class_implements, c.implements) + "left", + expression(logical.left) ], [ - "decorators", - array_of_list(expression, c.classDecorators) + "right", + expression(logical.right) ] ]); - case /* InterfaceDeclaration */21 : - return interface_declaration([ - loc, - b._0 - ]); - case /* DeclareVariable */22 : - return declare_variable([ - loc, - b._0 - ]); - case /* DeclareFunction */23 : - return declare_function([ - loc, - b._0 - ]); - case /* DeclareClass */24 : - return declare_class([ - loc, - b._0 - ]); - case /* DeclareModule */25 : - var m = b._0; - var lit = m.id; - var id$2; - id$2 = lit.TAG === /* Identifier */0 ? identifier(lit._0) : literal(lit._0); - var match$2 = m.kind; - var tmp; - tmp = match$2.TAG === /* CommonJS */0 ? string("CommonJS") : string("ES"); - return node("DeclareModule", loc, [ + case /* Conditional */10 : + var conditional = arr._0; + return node("ConditionalExpression", loc, [ [ - "id", - id$2 + "test", + expression(conditional.test) ], [ - "body", - block(m.body) + "consequent", + expression(conditional.consequent) ], [ - "kind", - tmp + "alternate", + expression(conditional.alternate) ] ]); - case /* DeclareModuleExports */26 : - return node("DeclareModuleExports", loc, [[ - "typeAnnotation", - type_annotation(b._0) - ]]); - case /* DeclareExportDeclaration */27 : - var $$export = b._0; - var match$3 = $$export.declaration; - var declaration; - if (match$3 !== undefined) { - switch (match$3.TAG | 0) { - case /* Variable */0 : - declaration = declare_variable(match$3._0); - break; - case /* Function */1 : - declaration = declare_function(match$3._0); - break; - case /* Class */2 : - declaration = declare_class(match$3._0); - break; - case /* DefaultType */3 : - declaration = _type(match$3._0); - break; - case /* NamedType */4 : - declaration = type_alias(match$3._0); - break; - case /* Interface */5 : - declaration = interface_declaration(match$3._0); - break; - - } - } else { - declaration = $$null; - } - return node("DeclareExportDeclaration", loc, [ + case /* New */11 : + var _new = arr._0; + return node("NewExpression", loc, [ [ - "default", - bool($$export.default) + "callee", + expression(_new.callee) ], [ - "declaration", - declaration - ], + "arguments", + array_of_list(expression_or_spread, _new.arguments) + ] + ]); + case /* Call */12 : + var call = arr._0; + return node("CallExpression", loc, [ [ - "specifiers", - export_specifiers($$export.specifiers) + "callee", + expression(call.callee) ], [ - "source", - option(literal, $$export.source) + "arguments", + array_of_list(expression_or_spread, call.arguments) ] ]); - case /* ExportDeclaration */28 : - var $$export$1 = b._0; - var match$4 = $$export$1.declaration; - var declaration$1 = match$4 !== undefined ? ( - match$4.TAG === /* Declaration */0 ? statement(match$4._0) : expression(match$4._0) - ) : $$null; - return node("ExportDeclaration", loc, [ + case /* Member */13 : + var member = arr._0; + var id = member.property; + var property; + property = id.TAG === /* PropertyIdentifier */0 ? identifier(id._0) : expression(id._0); + return node("MemberExpression", loc, [ [ - "default", - bool($$export$1.default) + "object", + expression(member._object) ], [ - "declaration", - declaration$1 + "property", + property ], [ - "specifiers", - export_specifiers($$export$1.specifiers) - ], + "computed", + bool(member.computed) + ] + ]); + case /* Yield */14 : + var $$yield = arr._0; + return node("YieldExpression", loc, [ [ - "source", - option(literal, $$export$1.source) + "argument", + option(expression, $$yield.argument) ], [ - "exportKind", - string($$export$1.exportKind ? "value" : "type") + "delegate", + bool($$yield.delegate) ] ]); - case /* ImportDeclaration */29 : - var $$import = b._0; - var specifiers = List.map((function (id) { - switch (id.TAG | 0) { - case /* ImportNamedSpecifier */0 : - var match = id._0; - var local_id = match.local; - var remote_id = match.remote; - var span_loc = local_id !== undefined ? btwn(remote_id[0], local_id[0]) : remote_id[0]; - return node("ImportSpecifier", span_loc, [ - [ - "id", - identifier(remote_id) - ], - [ - "name", - option(identifier, local_id) - ] - ]); - case /* ImportDefaultSpecifier */1 : - var id$1 = id._0; - return node("ImportDefaultSpecifier", id$1[0], [[ - "id", - identifier(id$1) - ]]); - case /* ImportNamespaceSpecifier */2 : - var param = id._0; - return node("ImportNamespaceSpecifier", param[0], [[ - "id", - identifier(param[1]) - ]]); - - } - }), $$import.specifiers); - var match$5 = $$import.importKind; - var import_kind; - switch (match$5) { - case /* ImportType */0 : - import_kind = "type"; - break; - case /* ImportTypeof */1 : - import_kind = "typeof"; - break; - case /* ImportValue */2 : - import_kind = "value"; - break; - - } - return node("ImportDeclaration", loc, [ + case /* Comprehension */15 : + var comp = arr._0; + return node("ComprehensionExpression", loc, [ [ - "specifiers", - array($$Array.of_list(specifiers)) + "blocks", + array_of_list(comprehension_block, comp.blocks) ], [ - "source", - literal($$import.source) + "filter", + option(expression, comp.filter) + ] + ]); + case /* Generator */16 : + var gen = arr._0; + return node("GeneratorExpression", loc, [ + [ + "blocks", + array_of_list(comprehension_block, gen.blocks) ], [ - "importKind", - string(import_kind) + "filter", + option(expression, gen.filter) ] ]); - - } - }; - 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, [ + case /* Let */17 : + var _let = arr._0; + return node("LetExpression", loc, [ [ - "properties", - array_of_list(object_pattern_property, obj$1.properties) + "head", + array_of_list(let_assignment, _let.head) ], [ - "typeAnnotation", - option(type_annotation, obj$1.typeAnnotation) + "body", + expression(_let.body) ] ]); - case /* Array */1 : - var arr = obj._0; - return node("ArrayPattern", loc, [ + case /* Identifier */18 : + return identifier(arr._0); + 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], [ [ - "elements", - array_of_list((function (param) { - return option(array_pattern_element, param); - }), arr.elements) + "tag", + expression(tagged.tag) ], [ - "typeAnnotation", - option(type_annotation, arr.typeAnnotation) + "quasi", + template_literal(tagged.quasi) ] ]); - case /* Assignment */2 : - var match = obj._0; - return node("AssignmentPattern", loc, [ + 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], [ [ - "left", - pattern(match.left) + "id", + option(identifier, c.id) ], [ - "right", - expression(match.right) + "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) ] ]); - case /* Identifier */3 : - return identifier(obj._0); - case /* Expression */4 : - return expression(obj._0); } }; - var let_assignment = function (assignment) { - return obj([ - [ - "id", - pattern(assignment.id) - ], - [ - "init", - option(expression, assignment.init) - ] - ]); - }; - 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) - ], + var object_type_call_property = function (param) { + var callProperty = param[1]; + return node("ObjectTypeCallProperty", param[0], [ [ - "body", - object_type(d.body) + "value", + function_type(callProperty.value) ], [ - "extends", - array_of_list(interface_extends, d.extends) + "static", + bool(callProperty.static) ] ]); }; - 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 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) - ] - ]; + 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 { + RE_EXN_ID: "Failure", + _1: "There should not be computed object type property keys", + Error: new Error() + }; + } - return node("Literal", loc, props); + return node("ObjectTypeProperty", param[0], [ + [ + "key", + key + ], + [ + "value", + _type(prop.value) + ], + [ + "optional", + bool(prop.optional) + ], + [ + "static", + bool(prop.static) + ] + ]); }; - var interface_declaration = function (param) { - var i = param[1]; - return node("InterfaceDeclaration", param[0], [ + var object_type_indexer = function (param) { + var indexer = param[1]; + return node("ObjectTypeIndexer", param[0], [ [ "id", - identifier(i.id) + identifier(indexer.id) ], [ - "typeParameters", - option(type_parameter_declaration, i.typeParameters) + "key", + _type(indexer.key) ], [ - "body", - object_type(i.body) + "value", + _type(indexer.value) ], [ - "extends", - array_of_list(interface_extends, i.extends) + "static", + bool(indexer.static) ] ]); }; - var export_specifiers = function (param) { - if (param !== undefined) { - if (param.TAG === /* ExportSpecifiers */0) { - return array_of_list(export_specifier, param._0); - } else { - return array([node("ExportBatchSpecifier", param._0, [[ - "name", - option(identifier, param._1) - ]])]); - } - } else { - return array([]); - } - }; var $$case = function (param) { var c = param[1]; return node("SwitchCase", param[0], [ @@ -16328,554 +16147,824 @@ function parse(content, options) { ] ]); }; - var expression = function (param) { - var arr = param[1]; + var variable_declaration = function (param) { + var $$var = param[1]; + var match = $$var.kind; + var kind; + switch (match) { + case /* Var */0 : + kind = "var"; + break; + case /* Let */1 : + kind = "let"; + break; + case /* Const */2 : + kind = "const"; + break; + + } + return node("VariableDeclaration", param[0], [ + [ + "declarations", + array_of_list(variable_declarator, $$var.declarations) + ], + [ + "kind", + string(kind) + ] + ]); + }; + var interface_declaration = function (param) { + var i = param[1]; + return node("InterfaceDeclaration", param[0], [ + [ + "id", + identifier(i.id) + ], + [ + "typeParameters", + option(type_parameter_declaration, i.typeParameters) + ], + [ + "body", + object_type(i.body) + ], + [ + "extends", + array_of_list(interface_extends, i.extends) + ] + ]); + }; + var statement = function (param) { + var b = param[1]; var loc = param[0]; - if (typeof arr === "number") { - return node("ThisExpression", loc, []); + if (typeof b === "number") { + if (b === /* Empty */0) { + return node("EmptyStatement", loc, []); + } else { + return node("DebuggerStatement", loc, []); + } } - switch (arr.TAG | 0) { - case /* Array */0 : - return node("ArrayExpression", loc, [[ - "elements", - array_of_list((function (param) { - return option(expression_or_spread, param); - }), arr._0.elements) + switch (b.TAG | 0) { + case /* Block */0 : + return block([ + loc, + b._0 + ]); + case /* Expression */1 : + return node("ExpressionStatement", loc, [[ + "expression", + expression(b._0.expression) ]]); - case /* Object */1 : - return node("ObjectExpression", loc, [[ - "properties", - array_of_list(object_property, arr._0.properties) + case /* If */2 : + var _if = b._0; + return node("IfStatement", loc, [ + [ + "test", + expression(_if.test) + ], + [ + "consequent", + statement(_if.consequent) + ], + [ + "alternate", + option(statement, _if.alternate) + ] + ]); + case /* Labeled */3 : + var labeled = b._0; + return node("LabeledStatement", loc, [ + [ + "label", + identifier(labeled.label) + ], + [ + "body", + statement(labeled.body) + ] + ]); + case /* Break */4 : + return node("BreakStatement", loc, [[ + "label", + option(identifier, b._0.label) ]]); - case /* Function */2 : - return function_expression([ + case /* Continue */5 : + return node("ContinueStatement", loc, [[ + "label", + option(identifier, b._0.label) + ]]); + case /* With */6 : + var _with = b._0; + return node("WithStatement", loc, [ + [ + "object", + expression(_with._object) + ], + [ + "body", + statement(_with.body) + ] + ]); + case /* TypeAlias */7 : + return type_alias([ loc, - arr._0 + b._0 ]); - case /* ArrowFunction */3 : - var arrow = arr._0; - var b = arrow.body; - var body; - body = b.TAG === /* BodyBlock */0 ? block(b._0) : expression(b._0); - return node("ArrowFunctionExpression", loc, [ + case /* Switch */8 : + var $$switch = b._0; + return node("SwitchStatement", loc, [ [ - "id", - option(identifier, arrow.id) + "discriminant", + expression($$switch.discriminant) ], [ - "params", - array_of_list(pattern, arrow.params) + "cases", + array_of_list($$case, $$switch.cases) ], [ - "defaults", - array_of_list((function (param) { - return option(expression, param); - }), arrow.defaults) + "lexical", + bool($$switch.lexical) + ] + ]); + case /* Return */9 : + return node("ReturnStatement", loc, [[ + "argument", + option(expression, b._0.argument) + ]]); + case /* Throw */10 : + return node("ThrowStatement", loc, [[ + "argument", + expression(b._0.argument) + ]]); + case /* Try */11 : + var _try = b._0; + return node("TryStatement", loc, [ + [ + "block", + block(_try.block) ], [ - "rest", - option(identifier, arrow.rest) + "handler", + option($$catch, _try.handler) + ], + [ + "guardedHandlers", + array_of_list($$catch, _try.guardedHandlers) + ], + [ + "finalizer", + option(block, _try.finalizer) + ] + ]); + case /* While */12 : + var _while = b._0; + return node("WhileStatement", loc, [ + [ + "test", + expression(_while.test) ], [ "body", - body - ], + statement(_while.body) + ] + ]); + case /* DoWhile */13 : + var dowhile = b._0; + return node("DoWhileStatement", loc, [ [ - "async", - bool(arrow.async) + "body", + statement(dowhile.body) ], [ - "generator", - bool(arrow.generator) + "test", + expression(dowhile.test) + ] + ]); + case /* For */14 : + var _for = b._0; + var init = function (init$1) { + if (init$1.TAG === /* InitDeclaration */0) { + return variable_declaration(init$1._0); + } else { + return expression(init$1._0); + } + }; + return node("ForStatement", loc, [ + [ + "init", + option(init, _for.init) ], [ - "expression", - bool(arrow.expression) + "test", + option(expression, _for.test) ], [ - "returnType", - option(type_annotation, arrow.returnType) + "update", + option(expression, _for.update) ], [ - "typeParameters", - option(type_parameter_declaration, arrow.typeParameters) + "body", + statement(_for.body) ] ]); - case /* Sequence */4 : - return node("SequenceExpression", loc, [[ - "expressions", - array_of_list(expression, arr._0.expressions) - ]]); - case /* Unary */5 : - var unary = arr._0; - var match = unary.operator; - if (match >= 7) { - return node("AwaitExpression", loc, [[ - "argument", - expression(unary.argument) - ]]); - } - var match$1 = unary.operator; - var operator; - switch (match$1) { - case /* Minus */0 : - operator = "-"; - break; - case /* Plus */1 : - operator = "+"; - break; - case /* Not */2 : - operator = "!"; - break; - case /* BitNot */3 : - operator = "~"; - break; - case /* Typeof */4 : - operator = "typeof"; - break; - case /* Void */5 : - operator = "void"; - break; - case /* Delete */6 : - operator = "delete"; - break; - case /* Await */7 : - throw { - RE_EXN_ID: "Failure", - _1: "matched above", - Error: new Error() - }; - - } - return node("UnaryExpression", loc, [ + case /* ForIn */15 : + var forin = b._0; + var left = forin.left; + var left$1; + left$1 = left.TAG === /* LeftDeclaration */0 ? variable_declaration(left._0) : expression(left._0); + return node("ForInStatement", loc, [ [ - "operator", - string(operator) + "left", + left$1 ], [ - "prefix", - bool(unary.prefix) + "right", + expression(forin.right) ], [ - "argument", - expression(unary.argument) + "body", + statement(forin.body) + ], + [ + "each", + bool(forin.each) ] ]); - case /* Binary */6 : - var binary = arr._0; - var match$2 = binary.operator; - var operator$1; - switch (match$2) { - case /* Equal */0 : - operator$1 = "=="; - break; - case /* NotEqual */1 : - operator$1 = "!="; - break; - case /* StrictEqual */2 : - operator$1 = "==="; - break; - case /* StrictNotEqual */3 : - operator$1 = "!=="; - break; - case /* LessThan */4 : - operator$1 = "<"; - break; - case /* LessThanEqual */5 : - operator$1 = "<="; - break; - case /* GreaterThan */6 : - operator$1 = ">"; - break; - case /* GreaterThanEqual */7 : - operator$1 = ">="; - break; - case /* LShift */8 : - operator$1 = "<<"; - break; - case /* RShift */9 : - operator$1 = ">>"; - break; - case /* RShift3 */10 : - operator$1 = ">>>"; - break; - case /* Plus */11 : - operator$1 = "+"; - break; - case /* Minus */12 : - operator$1 = "-"; - break; - case /* Mult */13 : - operator$1 = "*"; - break; - case /* Exp */14 : - operator$1 = "**"; - break; - case /* Div */15 : - operator$1 = "/"; - break; - case /* Mod */16 : - operator$1 = "%"; - break; - case /* BitOr */17 : - operator$1 = "|"; - break; - case /* Xor */18 : - operator$1 = "^"; - break; - case /* BitAnd */19 : - operator$1 = "&"; - break; - case /* In */20 : - operator$1 = "in"; - break; - case /* Instanceof */21 : - operator$1 = "instanceof"; - break; - - } - return node("BinaryExpression", loc, [ - [ - "operator", - string(operator$1) - ], + case /* ForOf */16 : + var forof = b._0; + var left$2 = forof.left; + var left$3; + left$3 = left$2.TAG === /* LeftDeclaration */0 ? variable_declaration(left$2._0) : expression(left$2._0); + return node("ForOfStatement", loc, [ [ "left", - expression(binary.left) + left$3 ], [ "right", - expression(binary.right) - ] - ]); - case /* Assignment */7 : - var assignment = arr._0; - var match$3 = assignment.operator; - var operator$2; - switch (match$3) { - case /* Assign */0 : - operator$2 = "="; - break; - case /* PlusAssign */1 : - operator$2 = "+="; - break; - case /* MinusAssign */2 : - operator$2 = "-="; - break; - case /* MultAssign */3 : - operator$2 = "*="; - break; - case /* ExpAssign */4 : - operator$2 = "**="; - break; - case /* DivAssign */5 : - operator$2 = "/="; - break; - case /* ModAssign */6 : - operator$2 = "%="; - break; - case /* LShiftAssign */7 : - operator$2 = "<<="; - break; - case /* RShiftAssign */8 : - operator$2 = ">>="; - break; - case /* RShift3Assign */9 : - operator$2 = ">>>="; - break; - case /* BitOrAssign */10 : - operator$2 = "|="; - break; - case /* BitXorAssign */11 : - operator$2 = "^="; - break; - case /* BitAndAssign */12 : - operator$2 = "&="; - break; - - } - return node("AssignmentExpression", loc, [ - [ - "operator", - string(operator$2) + expression(forof.right) ], [ - "left", - pattern(assignment.left) + "body", + statement(forof.body) + ] + ]); + case /* Let */17 : + var _let = b._0; + return node("LetStatement", loc, [ + [ + "head", + array_of_list(let_assignment, _let.head) ], [ - "right", - expression(assignment.right) + "body", + statement(_let.body) ] ]); - case /* Update */8 : - var update = arr._0; - var match$4 = update.operator; - var operator$3 = match$4 ? "--" : "++"; - return node("UpdateExpression", loc, [ + case /* FunctionDeclaration */18 : + var fn = b._0; + var id = fn.id; + var match = id !== undefined ? [ + "FunctionDeclaration", + identifier(id) + ] : [ + "FunctionExpression", + $$null + ]; + var b$1 = fn.body; + var body; + body = b$1.TAG === /* BodyBlock */0 ? block(b$1._0) : expression(b$1._0); + return node(match[0], loc, [ [ - "operator", - string(operator$3) + "id", + match[1] ], [ - "argument", - expression(update.argument) + "params", + array_of_list(pattern, fn.params) ], [ - "prefix", - bool(update.prefix) - ] - ]); - case /* Logical */9 : - var logical = arr._0; - var match$5 = logical.operator; - var operator$4 = match$5 ? "&&" : "||"; - return node("LogicalExpression", loc, [ + "defaults", + array_of_list((function (param) { + return option(expression, param); + }), fn.defaults) + ], [ - "operator", - string(operator$4) + "rest", + option(identifier, fn.rest) ], [ - "left", - expression(logical.left) + "body", + body ], [ - "right", - expression(logical.right) - ] - ]); - case /* Conditional */10 : - var conditional = arr._0; - return node("ConditionalExpression", loc, [ + "async", + bool(fn.async) + ], [ - "test", - expression(conditional.test) + "generator", + bool(fn.generator) ], [ - "consequent", - expression(conditional.consequent) + "expression", + bool(fn.expression) ], [ - "alternate", - expression(conditional.alternate) + "returnType", + option(type_annotation, fn.returnType) + ], + [ + "typeParameters", + option(type_parameter_declaration, fn.typeParameters) ] ]); - case /* New */11 : - var _new = arr._0; - return node("NewExpression", loc, [ + case /* VariableDeclaration */19 : + return variable_declaration([ + loc, + b._0 + ]); + case /* ClassDeclaration */20 : + var param$1 = [ + loc, + b._0 + ]; + var c = param$1[1]; + var id$1 = c.id; + var match$1 = id$1 !== undefined ? [ + "ClassDeclaration", + identifier(id$1) + ] : [ + "ClassExpression", + $$null + ]; + return node(match$1[0], param$1[0], [ [ - "callee", - expression(_new.callee) + "id", + match$1[1] ], [ - "arguments", - array_of_list(expression_or_spread, _new.arguments) - ] - ]); - case /* Call */12 : - var call = arr._0; - return node("CallExpression", loc, [ + "body", + class_body(c.body) + ], [ - "callee", - expression(call.callee) + "superClass", + option(expression, c.superClass) ], [ - "arguments", - array_of_list(expression_or_spread, call.arguments) - ] - ]); - case /* Member */13 : - var member = arr._0; - var id = member.property; - var property; - property = id.TAG === /* PropertyIdentifier */0 ? identifier(id._0) : expression(id._0); - return node("MemberExpression", loc, [ + "typeParameters", + option(type_parameter_declaration, c.typeParameters) + ], [ - "object", - expression(member._object) + "superTypeParameters", + option(type_parameter_instantiation, c.superTypeParameters) ], [ - "property", - property + "implements", + array_of_list(class_implements, c.implements) ], [ - "computed", - bool(member.computed) + "decorators", + array_of_list(expression, c.classDecorators) ] ]); - case /* Yield */14 : - var $$yield = arr._0; - return node("YieldExpression", loc, [ + case /* InterfaceDeclaration */21 : + return interface_declaration([ + loc, + b._0 + ]); + case /* DeclareVariable */22 : + return declare_variable([ + loc, + b._0 + ]); + case /* DeclareFunction */23 : + return declare_function([ + loc, + b._0 + ]); + case /* DeclareClass */24 : + return declare_class([ + loc, + b._0 + ]); + case /* DeclareModule */25 : + var m = b._0; + var lit = m.id; + var id$2; + id$2 = lit.TAG === /* Identifier */0 ? identifier(lit._0) : literal(lit._0); + var match$2 = m.kind; + var tmp; + tmp = match$2.TAG === /* CommonJS */0 ? string("CommonJS") : string("ES"); + return node("DeclareModule", loc, [ [ - "argument", - option(expression, $$yield.argument) + "id", + id$2 ], [ - "delegate", - bool($$yield.delegate) + "body", + block(m.body) + ], + [ + "kind", + tmp ] ]); - case /* Comprehension */15 : - var comp = arr._0; - return node("ComprehensionExpression", loc, [ + case /* DeclareModuleExports */26 : + return node("DeclareModuleExports", loc, [[ + "typeAnnotation", + type_annotation(b._0) + ]]); + case /* DeclareExportDeclaration */27 : + var $$export = b._0; + var match$3 = $$export.declaration; + var declaration; + if (match$3 !== undefined) { + switch (match$3.TAG | 0) { + case /* Variable */0 : + declaration = declare_variable(match$3._0); + break; + case /* Function */1 : + declaration = declare_function(match$3._0); + break; + case /* Class */2 : + declaration = declare_class(match$3._0); + break; + case /* DefaultType */3 : + declaration = _type(match$3._0); + break; + case /* NamedType */4 : + declaration = type_alias(match$3._0); + break; + case /* Interface */5 : + declaration = interface_declaration(match$3._0); + break; + + } + } else { + declaration = $$null; + } + return node("DeclareExportDeclaration", loc, [ [ - "blocks", - array_of_list(comprehension_block, comp.blocks) + "default", + bool($$export.default) ], [ - "filter", - option(expression, comp.filter) - ] - ]); - case /* Generator */16 : - var gen = arr._0; - return node("GeneratorExpression", loc, [ + "declaration", + declaration + ], [ - "blocks", - array_of_list(comprehension_block, gen.blocks) + "specifiers", + export_specifiers($$export.specifiers) ], [ - "filter", - option(expression, gen.filter) + "source", + option(literal, $$export.source) ] ]); - case /* Let */17 : - var _let = arr._0; - return node("LetExpression", loc, [ + case /* ExportDeclaration */28 : + var $$export$1 = b._0; + var match$4 = $$export$1.declaration; + var declaration$1 = match$4 !== undefined ? ( + match$4.TAG === /* Declaration */0 ? statement(match$4._0) : expression(match$4._0) + ) : $$null; + return node("ExportDeclaration", loc, [ [ - "head", - array_of_list(let_assignment, _let.head) + "default", + bool($$export$1.default) ], [ - "body", - expression(_let.body) - ] - ]); - case /* Identifier */18 : - return identifier(arr._0); - 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], [ + "declaration", + declaration$1 + ], [ - "tag", - expression(tagged.tag) + "specifiers", + export_specifiers($$export$1.specifiers) ], [ - "quasi", - template_literal(tagged.quasi) + "source", + option(literal, $$export$1.source) + ], + [ + "exportKind", + string($$export$1.exportKind ? "value" : "type") ] ]); - 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], [ + case /* ImportDeclaration */29 : + var $$import = b._0; + var specifiers = List.map((function (id) { + switch (id.TAG | 0) { + case /* ImportNamedSpecifier */0 : + var match = id._0; + var local_id = match.local; + var remote_id = match.remote; + var span_loc = local_id !== undefined ? btwn(remote_id[0], local_id[0]) : remote_id[0]; + return node("ImportSpecifier", span_loc, [ + [ + "id", + identifier(remote_id) + ], + [ + "name", + option(identifier, local_id) + ] + ]); + case /* ImportDefaultSpecifier */1 : + var id$1 = id._0; + return node("ImportDefaultSpecifier", id$1[0], [[ + "id", + identifier(id$1) + ]]); + case /* ImportNamespaceSpecifier */2 : + var param = id._0; + return node("ImportNamespaceSpecifier", param[0], [[ + "id", + identifier(param[1]) + ]]); + + } + }), $$import.specifiers); + var match$5 = $$import.importKind; + var import_kind; + switch (match$5) { + case /* ImportType */0 : + import_kind = "type"; + break; + case /* ImportTypeof */1 : + import_kind = "typeof"; + break; + case /* ImportValue */2 : + import_kind = "value"; + break; + + } + return node("ImportDeclaration", loc, [ [ - "id", - option(identifier, c.id) + "specifiers", + array($$Array.of_list(specifiers)) ], [ - "body", - class_body(c.body) + "source", + literal($$import.source) ], [ - "superClass", - option(expression, c.superClass) - ], + "importKind", + string(import_kind) + ] + ]); + + } + }; + 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, [ [ - "typeParameters", - option(type_parameter_declaration, c.typeParameters) + "properties", + array_of_list(object_pattern_property, obj$1.properties) ], [ - "superTypeParameters", - option(type_parameter_instantiation, c.superTypeParameters) - ], + "typeAnnotation", + option(type_annotation, obj$1.typeAnnotation) + ] + ]); + case /* Array */1 : + var arr = obj._0; + return node("ArrayPattern", loc, [ [ - "implements", - array_of_list(class_implements, c.implements) + "elements", + array_of_list((function (param) { + return option(array_pattern_element, param); + }), arr.elements) ], [ - "decorators", - array_of_list(expression, c.classDecorators) + "typeAnnotation", + option(type_annotation, arr.typeAnnotation) ] ]); - case /* TypeCast */24 : - var typecast = arr._0; - return node("TypeCastExpression", loc, [ + case /* Assignment */2 : + var match = obj._0; + return node("AssignmentPattern", loc, [ [ - "expression", - expression(typecast.expression) + "left", + pattern(match.left) ], [ - "typeAnnotation", - type_annotation(typecast.typeAnnotation) + "right", + expression(match.right) ] ]); + case /* Identifier */3 : + return identifier(obj._0); + case /* Expression */4 : + return expression(obj._0); } }; + var declare_function = function (param) { + return node("DeclareFunction", param[0], [[ + "id", + identifier(param[1].id) + ]]); + }; + var export_specifiers = function (param) { + if (param !== undefined) { + if (param.TAG === /* ExportSpecifiers */0) { + return array_of_list(export_specifier, param._0); + } else { + return array([node("ExportBatchSpecifier", param._0, [[ + "name", + option(identifier, param._1) + ]])]); + } + } else { + return array([]); + } + }; + var 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 let_assignment = function (assignment) { + return obj([ + [ + "id", + pattern(assignment.id) + ], + [ + "init", + option(expression, assignment.init) + ] + ]); + }; + var block = function (param) { + return node("BlockStatement", param[0], [[ + "body", + array_of_list(statement, param[1].body) + ]]); + }; + 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 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 declare_variable = function (param) { return node("DeclareVariable", param[0], [[ "id", identifier(param[1].id) ]]); }; - var jsx_identifier = function (param) { - return node("JSXIdentifier", param[0], [[ - "name", - string(param[1].name) - ]]); - }; - var jsx_namespaced_name = function (param) { - var namespaced_name = param[1]; - return node("JSXNamespacedName", param[0], [ + var declare_class = function (param) { + var d = param[1]; + return node("DeclareClass", param[0], [ [ - "namespace", - jsx_identifier(namespaced_name.namespace) + "id", + identifier(d.id) ], [ - "name", - jsx_identifier(namespaced_name.name) + "typeParameters", + option(type_parameter_declaration, d.typeParameters) + ], + [ + "body", + object_type(d.body) + ], + [ + "extends", + array_of_list(interface_extends, d.extends) ] ]); }; - 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 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 export_specifier = function (param) { + var specifier = param[1]; + return node("ExportSpecifier", param[0], [ [ - "object", - _object + "id", + identifier(specifier.id) ], [ - "property", - jsx_identifier(member_expression.property) + "name", + option(identifier, specifier.name) ] ]); }; + var type_parameter_instantiation = function (param) { + return node("TypeParameterInstantiation", param[0], [[ + "params", + array_of_list(_type, param[1].params) + ]]); + }; var class_implements = function (param) { var $$implements = param[1]; return node("ClassImplements", param[0], [ @@ -16889,88 +16978,36 @@ function parse(content, options) { ] ]); }; - var type_parameter_instantiation = function (param) { - return node("TypeParameterInstantiation", param[0], [[ - "params", - array_of_list(_type, param[1].params) - ]]); - }; var class_body = function (param) { return node("ClassBody", param[0], [[ "body", array_of_list(class_element, param[1].body) ]]); }; - 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 array_pattern_element = function (p) { - if (p.TAG === /* Element */0) { - return pattern(p._0); - } - var match = p._0; - return node("SpreadElementPattern", match[0], [[ - "argument", - pattern(match[1].argument) - ]]); - }; - var object_pattern_property = function (param) { - if (param.TAG === /* Property */0) { - var match = param._0; - var prop = match[1]; - var lit = prop.key; - var match$1; - switch (lit.TAG | 0) { - case /* Literal */0 : - match$1 = [ - literal(lit._0), - false - ]; - break; - case /* Identifier */1 : - match$1 = [ - identifier(lit._0), - false - ]; - break; - case /* Computed */2 : - match$1 = [ - expression(lit._0), - true - ]; - break; - - } - return node("PropertyPattern", match[0], [ - [ - "key", - match$1[0] - ], - [ - "pattern", - pattern(prop.pattern) - ], + var jsx_opening_attribute = function (attribute) { + if (attribute.TAG === /* Attribute */0) { + var param = attribute._0; + var attribute$1 = param[1]; + var id = attribute$1.name; + var name; + name = id.TAG === /* Identifier */0 ? jsx_identifier(id._0) : jsx_namespaced_name(id._0); + return node("JSXAttribute", param[0], [ [ - "computed", - bool(match$1[1]) + "name", + name ], [ - "shorthand", - bool(prop.shorthand) + "value", + option(jsx_attribute_value, attribute$1.value) ] ]); + } else { + var param$1 = attribute._0; + return node("JSXSpreadAttribute", param$1[0], [[ + "argument", + expression(param$1[1].argument) + ]]); } - var match$2 = param._0; - return node("SpreadPropertyPattern", match$2[0], [[ - "argument", - pattern(match$2[1].argument) - ]]); }; var jsx_name = function (id) { switch (id.TAG | 0) { @@ -16983,18 +17020,61 @@ function parse(content, options) { } }; - var template_literal = function (param) { - var value = param[1]; - return node("TemplateLiteral", param[0], [ - [ - "quasis", - array_of_list(template_element, value.quasis) - ], - [ - "expressions", - array_of_list(expression, value.expressions) - ] - ]); + var jsx_opening = function (param) { + var opening = param[1]; + return node("JSXOpeningElement", param[0], [ + [ + "name", + jsx_name(opening.name) + ], + [ + "attributes", + array_of_list(jsx_opening_attribute, opening.attributes) + ], + [ + "selfClosing", + bool(opening.selfClosing) + ] + ]); + }; + var jsx_child = function (param) { + var element = param[1]; + var loc = param[0]; + switch (element.TAG | 0) { + case /* Element */0 : + return jsx_element([ + loc, + element._0 + ]); + case /* ExpressionContainer */1 : + return jsx_expression_container([ + loc, + element._0 + ]); + case /* Text */2 : + var param$1 = [ + loc, + element._0 + ]; + var text = param$1[1]; + return node("JSXText", param$1[0], [ + [ + "value", + string(text.value) + ], + [ + "raw", + string(text.raw) + ] + ]); + + } + }; + var jsx_closing = function (param) { + return node("JSXClosingElement", param[0], [[ + "name", + jsx_name(param[1].name) + ]]); }; var generic_type_qualified_identifier = function (param) { var q = param[1]; @@ -17012,20 +17092,36 @@ function parse(content, options) { ] ]); }; - var jsx_element = function (param) { - var element = param[1]; - return node("JSXElement", param[0], [ + var object_type = function (param) { + var o = param[1]; + return node("ObjectTypeAnnotation", param[0], [ [ - "openingElement", - jsx_opening(element.openingElement) + "properties", + array_of_list(object_type_property, o.properties) ], [ - "closingElement", - option(jsx_closing, element.closingElement) + "indexers", + array_of_list(object_type_indexer, o.indexers) ], [ - "children", - array_of_list(jsx_child, element.children) + "callProperties", + array_of_list(object_type_call_property, o.callProperties) + ] + ]); + }; + var interface_extends = function (param) { + var g = param[1]; + var id = g.id; + var id$1; + id$1 = id.TAG === /* Unqualified */0 ? identifier(id._0) : generic_type_qualified_identifier(id._0); + return node("InterfaceExtends", param[0], [ + [ + "id", + id$1 + ], + [ + "typeParameters", + option(type_parameter_instantiation, g.typeParameters) ] ]); }; @@ -17052,72 +17148,24 @@ 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]; - switch (element.TAG | 0) { - case /* Element */0 : - return jsx_element([ - loc, - element._0 - ]); - case /* ExpressionContainer */1 : - return jsx_expression_container([ - loc, - element._0 - ]); - case /* Text */2 : - var param$1 = [ - loc, - element._0 - ]; - var text = param$1[1]; - return node("JSXText", param$1[0], [ - [ - "value", - string(text.value) - ], - [ - "raw", - string(text.raw) - ] - ]); - - } - }; - var jsx_opening = function (param) { - var opening = param[1]; - return node("JSXOpeningElement", param[0], [ + var function_type = function (param) { + var fn = param[1]; + return node("FunctionTypeAnnotation", param[0], [ [ - "name", - jsx_name(opening.name) + "params", + array_of_list(function_type_param, fn.params) ], [ - "attributes", - array_of_list(jsx_opening_attribute, opening.attributes) + "returnType", + _type(fn.returnType) ], [ - "selfClosing", - bool(opening.selfClosing) - ] - ]); - }; - var variable_declarator = function (param) { - var declarator = param[1]; - return node("VariableDeclarator", param[0], [ - [ - "id", - pattern(declarator.id) + "rest", + option(function_type_param, fn.rest) ], [ - "init", - option(expression, declarator.init) + "typeParameters", + option(type_parameter_declaration, fn.typeParameters) ] ]); }; @@ -17212,6 +17260,16 @@ function parse(content, options) { ] ]); }; + var expression_or_spread = function (expr) { + if (expr.TAG === /* Expression */0) { + return expression(expr._0); + } + var match = expr._0; + return node("SpreadElement", match[0], [[ + "argument", + expression(match[1].argument) + ]]); + }; var function_expression = function (param) { var _function = param[1]; var b = _function.body; @@ -17242,242 +17300,64 @@ function parse(content, options) { ], [ "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 expression_or_spread = function (expr) { - if (expr.TAG === /* Expression */0) { - return expression(expr._0); - } - var match = expr._0; - return node("SpreadElement", match[0], [[ - "argument", - expression(match[1].argument) - ]]); - }; - 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 { - RE_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 object_type = function (param) { - var o = param[1]; - return node("ObjectTypeAnnotation", param[0], [ - [ - "properties", - array_of_list(object_type_property, o.properties) + bool(_function.async) ], [ - "indexers", - array_of_list(object_type_indexer, o.indexers) + "generator", + bool(_function.generator) ], [ - "callProperties", - array_of_list(object_type_call_property, o.callProperties) - ] - ]); - }; - var interface_extends = function (param) { - var g = param[1]; - var id = g.id; - var id$1; - id$1 = id.TAG === /* Unqualified */0 ? identifier(id._0) : generic_type_qualified_identifier(id._0); - return node("InterfaceExtends", param[0], [ + "expression", + bool(_function.expression) + ], [ - "id", - id$1 + "returnType", + option(type_annotation, _function.returnType) ], [ "typeParameters", - option(type_parameter_instantiation, g.typeParameters) + option(type_parameter_declaration, _function.typeParameters) ] ]); }; - 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 (attribute) { - if (attribute.TAG === /* Attribute */0) { - var param = attribute._0; - var attribute$1 = param[1]; - var id = attribute$1.name; - var name; - name = id.TAG === /* Identifier */0 ? jsx_identifier(id._0) : jsx_namespaced_name(id._0); - return node("JSXAttribute", param[0], [ - [ - "name", - name - ], - [ - "value", - option(jsx_attribute_value, attribute$1.value) - ] - ]); - } else { - var param$1 = attribute._0; - return node("JSXSpreadAttribute", param$1[0], [[ - "argument", - expression(param$1[1].argument) - ]]); - } - }; - var jsx_attribute_value = function (param) { - if (param.TAG === /* Literal */0) { - return literal([ - param._0, - param._1 - ]); - } else { - return jsx_expression_container([ - param._0, - param._1 - ]); - } - }; - var export_specifier = function (param) { - var specifier = param[1]; - return node("ExportSpecifier", param[0], [ + var template_literal = function (param) { + var value = param[1]; + return node("TemplateLiteral", param[0], [ [ - "id", - identifier(specifier.id) + "quasis", + array_of_list(template_element, value.quasis) ], [ - "name", - option(identifier, specifier.name) + "expressions", + array_of_list(expression, value.expressions) ] ]); }; - var function_type_param = function (param) { - var param$1 = param[1]; - return node("FunctionTypeParam", param[0], [ + 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", - identifier(param$1.name) - ], - [ - "typeAnnotation", - _type(param$1.typeAnnotation) - ], - [ - "optional", - bool(param$1.optional) - ] - ]); - }; - var function_type = function (param) { - var fn = param[1]; - return node("FunctionTypeAnnotation", param[0], [ - [ - "params", - array_of_list(function_type_param, fn.params) + 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) ] ]); }; @@ -17600,6 +17480,126 @@ function parse(content, options) { ]); } }; + var comment = function (param) { + var c = param[1]; + var match; + match = c.TAG === /* Block */0 ? [ + "Block", + c._0 + ] : [ + "Line", + c._0 + ]; + return node(match[0], param[0], [[ + "value", + string(match[1]) + ]]); + }; + var function_type_param = function (param) { + var param$1 = param[1]; + return node("FunctionTypeParam", param[0], [ + [ + "name", + identifier(param$1.name) + ], + [ + "typeAnnotation", + _type(param$1.typeAnnotation) + ], + [ + "optional", + bool(param$1.optional) + ] + ]); + }; + var variable_declarator = function (param) { + var declarator = param[1]; + return node("VariableDeclarator", param[0], [ + [ + "id", + pattern(declarator.id) + ], + [ + "init", + option(expression, declarator.init) + ] + ]); + }; + var jsx_attribute_value = function (param) { + if (param.TAG === /* Literal */0) { + return literal([ + param._0, + param._1 + ]); + } else { + return jsx_expression_container([ + param._0, + param._1 + ]); + } + }; + var array_pattern_element = function (p) { + if (p.TAG === /* Element */0) { + return pattern(p._0); + } + var match = p._0; + return node("SpreadElementPattern", match[0], [[ + "argument", + pattern(match[1].argument) + ]]); + }; + var object_pattern_property = function (param) { + if (param.TAG === /* Property */0) { + var match = param._0; + var prop = match[1]; + var lit = prop.key; + var match$1; + switch (lit.TAG | 0) { + case /* Literal */0 : + match$1 = [ + literal(lit._0), + false + ]; + break; + case /* Identifier */1 : + match$1 = [ + identifier(lit._0), + false + ]; + break; + case /* Computed */2 : + match$1 = [ + expression(lit._0), + true + ]; + break; + + } + return node("PropertyPattern", match[0], [ + [ + "key", + match$1[0] + ], + [ + "pattern", + pattern(prop.pattern) + ], + [ + "computed", + bool(match$1[1]) + ], + [ + "shorthand", + bool(prop.shorthand) + ] + ]); + } + var match$2 = param._0; + return node("SpreadPropertyPattern", match$2[0], [[ + "argument", + pattern(match$2[1].argument) + ]]); + }; var program$2 = function (param) { return node("Program", param[0], [ [ diff --git a/jscomp/test/label_uncurry.res b/jscomp/test/label_uncurry.res index fc13f6de93..3e64de08b3 100644 --- a/jscomp/test/label_uncurry.res +++ b/jscomp/test/label_uncurry.res @@ -1,6 +1,6 @@ type t = (. ~x: int, ~y: string) => int -type u = Js.Fn.arity2<(~x: int, ~y: string) => int> +type u = (. ~x: int, ~y: string) => int let f = (x: t): u => x diff --git a/lib/es6/belt_internalBuckets.js b/lib/es6/belt_internalBuckets.js index 302642266a..09cf0a8f55 100644 --- a/lib/es6/belt_internalBuckets.js +++ b/lib/es6/belt_internalBuckets.js @@ -4,19 +4,6 @@ import * as Curry from "./curry.js"; import * as Belt_Array from "./belt_Array.js"; import * as Caml_option from "./caml_option.js"; -function copyBucket(c) { - if (c === undefined) { - return c; - } - var head = { - key: c.key, - value: c.value, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyAuxCont(_c, _prec) { while(true) { var prec = _prec; @@ -36,6 +23,19 @@ function copyAuxCont(_c, _prec) { }; } +function copyBucket(c) { + if (c === undefined) { + return c; + } + var head = { + key: c.key, + value: c.value, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} + function copyBuckets(buckets) { var len = buckets.length; var newBuckets = new Array(len); diff --git a/lib/es6/js.js b/lib/es6/js.js index 58f97c0359..2f068ed1b4 100644 --- a/lib/es6/js.js +++ b/lib/es6/js.js @@ -1,8 +1,6 @@ -var Fn = {}; - var Internal = {}; var MapperRt; @@ -74,7 +72,6 @@ var $$Map; var $$WeakMap; export { - Fn , MapperRt , Internal , Null , diff --git a/lib/js/belt_internalBuckets.js b/lib/js/belt_internalBuckets.js index eabd14bcbc..cad3a978dc 100644 --- a/lib/js/belt_internalBuckets.js +++ b/lib/js/belt_internalBuckets.js @@ -4,19 +4,6 @@ var Curry = require("./curry.js"); var Belt_Array = require("./belt_Array.js"); var Caml_option = require("./caml_option.js"); -function copyBucket(c) { - if (c === undefined) { - return c; - } - var head = { - key: c.key, - value: c.value, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyAuxCont(_c, _prec) { while(true) { var prec = _prec; @@ -36,6 +23,19 @@ function copyAuxCont(_c, _prec) { }; } +function copyBucket(c) { + if (c === undefined) { + return c; + } + var head = { + key: c.key, + value: c.value, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} + function copyBuckets(buckets) { var len = buckets.length; var newBuckets = new Array(len); diff --git a/lib/js/js.js b/lib/js/js.js index 4981e3b5d1..482966e44d 100644 --- a/lib/js/js.js +++ b/lib/js/js.js @@ -1,8 +1,6 @@ 'use strict'; -var Fn = {}; - var Internal = {}; var MapperRt; @@ -73,7 +71,6 @@ var $$Map; var $$WeakMap; -exports.Fn = Fn; exports.MapperRt = MapperRt; exports.Internal = Internal; exports.Null = Null; diff --git a/res_syntax/src/reactjs_jsx_v4.ml b/res_syntax/src/reactjs_jsx_v4.ml index 3492c335f3..ae586bcb61 100644 --- a/res_syntax/src/reactjs_jsx_v4.ml +++ b/res_syntax/src/reactjs_jsx_v4.ml @@ -752,8 +752,8 @@ let transformStructureItem ~config mapper item = check_string_int_attribute_iter.structure_item check_string_int_attribute_iter item; let pval_type = - if Res_uncurried.typeIsUncurriedFun pval_type then - let _arity, t = Res_uncurried.typeExtractUncurriedFun pval_type in + if Ast_uncurried.typeIsUncurriedFun pval_type then + let _arity, t = Ast_uncurried.typeExtractUncurriedFun pval_type in t else pval_type in @@ -825,8 +825,8 @@ let transformStructureItem ~config mapper item = config.hasReactComponent <- true; let rec removeArityRecord expr = match expr.pexp_desc with - | _ when Res_uncurried.exprIsUncurriedFun expr -> - Res_uncurried.exprExtractUncurriedFun expr + | _ when Ast_uncurried.exprIsUncurriedFun expr -> + Ast_uncurried.exprExtractUncurriedFun expr | Pexp_apply (forwardRef, [(label, e)]) -> { expr with @@ -1248,8 +1248,8 @@ let transformSignatureItem ~config _mapper item = React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc else config.hasReactComponent <- true; let pval_type = - if Res_uncurried.typeIsUncurriedFun pval_type then - let _arity, t = Res_uncurried.typeExtractUncurriedFun pval_type in + if Ast_uncurried.typeIsUncurriedFun pval_type then + let _arity, t = Ast_uncurried.typeExtractUncurriedFun pval_type in t else pval_type in diff --git a/res_syntax/src/res_core.ml b/res_syntax/src/res_core.ml index 7826cc8267..6f054d8f3e 100644 --- a/res_syntax/src/res_core.ml +++ b/res_syntax/src/res_core.ml @@ -1599,7 +1599,7 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context && (termParamNum = 1 || not (p.uncurried_config |> Res_uncurried.isDefault)) then - (termParamNum - 1, Res_uncurried.uncurriedFun ~loc ~arity funExpr, 1) + (termParamNum - 1, Ast_uncurried.uncurriedFun ~loc ~arity funExpr, 1) else (termParamNum - 1, funExpr, arity + 1) | TypeParameter {dotted = _; attrs; locs = newtypes; pos = startPos} -> ( termParamNum, @@ -3917,7 +3917,7 @@ and parsePolyTypeExpr p = let loc = mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos in let tFun = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in if p.uncurried_config |> Res_uncurried.isDefault then - Res_uncurried.uncurriedType ~loc ~arity:1 tFun + Ast_uncurried.uncurriedType ~loc ~arity:1 tFun else tFun | _ -> Ast_helper.Typ.var ~loc:var.loc var.txt) | _ -> assert false) @@ -4267,7 +4267,7 @@ and parseEs6ArrowType ~attrs p = then let loc = mkLoc startPos endPos in let tArg = Ast_helper.Typ.arrow ~loc ~attrs argLbl typ t in - (paramNum - 1, Res_uncurried.uncurriedType ~loc ~arity tArg, 1) + (paramNum - 1, Ast_uncurried.uncurriedType ~loc ~arity tArg, 1) else ( paramNum - 1, Ast_helper.Typ.arrow ~loc:(mkLoc startPos endPos) ~attrs argLbl @@ -4330,7 +4330,7 @@ and parseArrowTypeRest ~es6Arrow ~startPos typ p = let loc = mkLoc startPos p.prevEndPos in let arrowTyp = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in if p.uncurried_config |> Res_uncurried.isDefault then - Res_uncurried.uncurriedType ~loc ~arity:1 arrowTyp + Ast_uncurried.uncurriedType ~loc ~arity:1 arrowTyp else arrowTyp | _ -> typ diff --git a/res_syntax/src/res_outcome_printer.ml b/res_syntax/src/res_outcome_printer.ml index 97560bf22a..6cea0b9554 100644 --- a/res_syntax/src/res_outcome_printer.ml +++ b/res_syntax/src/res_outcome_printer.ml @@ -34,12 +34,6 @@ let isValidNumericPolyvarNumber (x : string) = | _ -> false) else a >= 48 -(* checks if ident contains "arity", like in "arity1", "arity2", "arity3" etc. *) -let isArityIdent ident = - if String.length ident >= 6 then - (String.sub [@doesNotRaise]) ident 0 5 = "arity" - else false - type identifierStyle = ExoticIdent | NormalIdent let classifyIdentContent ~allowUident txt = @@ -210,18 +204,18 @@ let rec printOutTypeDoc (outType : Outcometree.out_type) = Doc.text aliasTxt; Doc.rparen; ] - | Otyp_constr - ( Oide_dot (Oide_dot (Oide_ident "Js", "Fn"), "arity0"), - (* Js.Fn.arity0 *) - [typ] ) -> - (* Js.Fn.arity0 -> (.) => t *) + | Otyp_constr (Oide_dot (Oide_dot (Oide_ident "Js", "Fn"), "arity0"), [typ]) + -> + (* Compatibility with compiler up to v10.x *) Doc.concat [Doc.text "(. ()) => "; printOutTypeDoc typ] | Otyp_constr - ( Oide_dot (Oide_dot (Oide_ident "Js", "Fn"), ident), - (* Js.Fn.arity2 *) - [(Otyp_arrow _ as arrowType)] (* (int, int) => int *) ) - when isArityIdent ident -> - (* Js.Fn.arity2<(int, int) => int> -> (. int, int) => int*) + ( Oide_dot (Oide_dot (Oide_ident "Js", "Fn"), _), + [(Otyp_arrow _ as arrowType)] ) -> + (* Compatibility with compiler up to v10.x *) + printOutArrowType ~uncurried:true arrowType + | Otyp_constr (Oide_ident "function$", [(Otyp_arrow _ as arrowType); _arity]) + -> + (* function$<(int, int) => int, [#2]> -> (. int, int) => int *) printOutArrowType ~uncurried:true arrowType | Otyp_constr (outIdent, []) -> printOutIdentDoc ~allowUident:false outIdent | Otyp_manifest (typ1, typ2) -> diff --git a/res_syntax/src/res_parsetree_viewer.ml b/res_syntax/src/res_parsetree_viewer.ml index b4e4e97e65..ee476a9d58 100644 --- a/res_syntax/src/res_parsetree_viewer.ml +++ b/res_syntax/src/res_parsetree_viewer.ml @@ -176,8 +176,8 @@ let funExpr expr = (* If a fun has an attribute, then it stops here and makes currying. i.e attributes outside of (...), uncurried `(.)` and `async` make currying *) | {pexp_desc = Pexp_fun _} -> (uncurried, attrsBefore, List.rev acc, expr) - | expr when nFun = 0 && Res_uncurried.exprIsUncurriedFun expr -> - let expr = Res_uncurried.exprExtractUncurriedFun expr in + | expr when nFun = 0 && Ast_uncurried.exprIsUncurriedFun expr -> + let expr = Ast_uncurried.exprExtractUncurriedFun expr in collect ~uncurried:true ~nFun attrsBefore acc expr | expr -> (uncurried, attrsBefore, List.rev acc, expr) in @@ -185,8 +185,8 @@ let funExpr expr = | {pexp_desc = Pexp_fun _} -> collect ~uncurried:false ~nFun:0 expr.pexp_attributes [] {expr with pexp_attributes = []} - | _ when Res_uncurried.exprIsUncurriedFun expr -> - let expr = Res_uncurried.exprExtractUncurriedFun expr in + | _ when Ast_uncurried.exprIsUncurriedFun expr -> + let expr = Ast_uncurried.exprExtractUncurriedFun expr in collect ~uncurried:true ~nFun:0 expr.pexp_attributes [] {expr with pexp_attributes = []} | _ -> collect ~uncurried:false ~nFun:0 [] [] expr @@ -203,7 +203,7 @@ let filterParsingAttrs attrs = match attr with | ( { Location.txt = - ( "bs" | "res.uapp" | "res.braces" | "res.iflet" + ( "bs" | "res.uapp" | "res.arity" | "res.braces" | "res.iflet" | "res.namedArgLoc" | "res.optional" | "res.ternary" | "res.async" | "res.await" | "res.template" ); }, @@ -352,8 +352,8 @@ let hasAttributes attrs = match attr with | ( { Location.txt = - ( "bs" | "res.uapp" | "res.braces" | "res.iflet" | "res.ternary" - | "res.async" | "res.await" | "res.template" ); + ( "bs" | "res.uapp" | "res.arity" | "res.braces" | "res.iflet" + | "res.ternary" | "res.async" | "res.await" | "res.template" ); }, _ ) -> false @@ -534,8 +534,8 @@ let isPrintableAttribute attr = match attr with | ( { Location.txt = - ( "bs" | "res.uapp" | "res.iflet" | "res.braces" | "JSX" | "res.async" - | "res.await" | "res.template" | "res.ternary" ); + ( "bs" | "res.uapp" | "res.arity" | "res.iflet" | "res.braces" | "JSX" + | "res.async" | "res.await" | "res.template" | "res.ternary" ); }, _ ) -> false @@ -551,7 +551,7 @@ let partitionPrintableAttributes attrs = let isFunNewtype expr = match expr.pexp_desc with | Pexp_fun _ | Pexp_newtype _ -> true - | _ -> Res_uncurried.exprIsUncurriedFun expr + | _ -> Ast_uncurried.exprIsUncurriedFun expr let requiresSpecialCallbackPrintingLastArg args = let rec loop args = diff --git a/res_syntax/src/res_printer.ml b/res_syntax/src/res_printer.ml index 50139b7268..bf7c030cb9 100644 --- a/res_syntax/src/res_printer.ml +++ b/res_syntax/src/res_printer.ml @@ -1583,7 +1583,7 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl = let doc = printTypExpr ~state n cmtTbl in match n.ptyp_desc with | Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc - | _ when Res_uncurried.typeIsUncurriedFun n -> addParens doc + | _ when Ast_uncurried.typeIsUncurriedFun n -> addParens doc | _ -> doc in Doc.group @@ -1655,8 +1655,8 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl = | Ptyp_object (fields, openFlag) -> printObject ~state ~inline:false fields openFlag cmtTbl | Ptyp_arrow _ -> printArrow ~uncurried:false typExpr - | Ptyp_constr _ when Res_uncurried.typeIsUncurriedFun typExpr -> - let arity, tArg = Res_uncurried.typeExtractUncurriedFun typExpr in + | Ptyp_constr _ when Ast_uncurried.typeIsUncurriedFun typExpr -> + let arity, tArg = Ast_uncurried.typeExtractUncurriedFun typExpr in printArrow ~uncurried:true ~arity tArg | Ptyp_constr (longidentLoc, [{ptyp_desc = Ptyp_object (fields, openFlag)}]) -> @@ -2678,7 +2678,7 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl = printExpressionWithComments ~state (ParsetreeViewer.rewriteUnderscoreApply e) cmtTbl - | _ when Res_uncurried.exprIsUncurriedFun e -> printArrow e + | _ when Ast_uncurried.exprIsUncurriedFun e -> printArrow e | Pexp_fun _ | Pexp_newtype _ -> printArrow e | Parsetree.Pexp_constant c -> printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c diff --git a/res_syntax/src/res_uncurried.ml b/res_syntax/src/res_uncurried.ml index 907d4402e0..d3c666c4d2 100644 --- a/res_syntax/src/res_uncurried.ml +++ b/res_syntax/src/res_uncurried.ml @@ -15,52 +15,3 @@ let fromDotted ~dotted = function let getDotted ~uncurried = function | Legacy -> uncurried | Default -> not uncurried - -let uncurriedType ~loc ~arity tArg = - Ast_helper.Typ.constr ~loc - {txt = Ldot (Ldot (Lident "Js", "Fn"), "arity" ^ string_of_int arity); loc} - [tArg] - -let uncurriedFun ~loc ~arity funExpr = - Ast_helper.Exp.record ~loc - [ - ( {txt = Ldot (Ldot (Lident "Js", "Fn"), "I" ^ string_of_int arity); loc}, - funExpr ); - ] - None - -let exprIsUncurriedFun (expr : Parsetree.expression) = - match expr with - | { - pexp_desc = - Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, _e)], None); - } -> - true - | _ -> false - -let exprExtractUncurriedFun (expr : Parsetree.expression) = - match expr with - | { - pexp_desc = - Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None); - } -> - e - | _ -> assert false - -let typeIsUncurriedFun (typ : Parsetree.core_type) = - match typ.ptyp_desc with - | Ptyp_constr - ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [{ptyp_desc = Ptyp_arrow _}]) - -> - true - | _ -> false - -let typeExtractUncurriedFun (typ : Parsetree.core_type) = - match typ.ptyp_desc with - | Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), arity)}, [tArg]) -> - let arity = - (int_of_string [@doesNotRaise]) - ((String.sub [@doesNotRaise]) arity 5 (String.length arity - 5)) - in - (arity, tArg) - | _ -> assert false diff --git a/res_syntax/tests/oprint/expected/oprint.resi.txt b/res_syntax/tests/oprint/expected/oprint.resi.txt index 9958416070..bd3ec2eb28 100644 --- a/res_syntax/tests/oprint/expected/oprint.resi.txt +++ b/res_syntax/tests/oprint/expected/oprint.resi.txt @@ -171,263 +171,14 @@ type \"let" = int type \"type" = [#"Point🗿"(\"let", float)] type t23 = [#1 | #"10space" | #123] type exoticUser = {\"let": string, \"type": float} -module Js: { - type t<'a> = 'a - module Fn: { - type arity0<'a> = {i0: unit => 'a} - type arity1<'a> = {i1: 'a} - type arity2<'a> = {i2: 'a} - type arity3<'a> = {i3: 'a} - type arity4<'a> = {i4: 'a} - type arity5<'a> = {i5: 'a} - type arity6<'a> = {i6: 'a} - type arity7<'a> = {i7: 'a} - type arity8<'a> = {i8: 'a} - type arity9<'a> = {i9: 'a} - type arity10<'a> = {i10: 'a} - type arity11<'a> = {i11: 'a} - type arity12<'a> = {i12: 'a} - type arity13<'a> = {i13: 'a} - type arity14<'a> = {i14: 'a} - type arity15<'a> = {i15: 'a} - type arity16<'a> = {i16: 'a} - type arity17<'a> = {i17: 'a} - type arity18<'a> = {i18: 'a} - type arity19<'a> = {i19: 'a} - type arity20<'a> = {i20: 'a} - type arity21<'a> = {i21: 'a} - type arity22<'a> = {i22: 'a} - } -} -type arity0 = (. ()) => unit -type arity0b = (. ()) => int -type arity0c = (. ()) => (. ()) => array -type arity0d = (. ()) => unit => unit -type arity1 = (. int) => int +type arity1a = (. unit) => int +type arity1b = (. int) => int type arity2 = (. int, int) => int -type arity3 = (. int, int, int) => int -type arity4 = (. int, int, int, int) => int -type arity5 = (. int, int, int, int, int) => int -type arity6 = (. int, int, int, int, int, int) => int -type arity7 = (. int, int, int, int, int, int, int) => int -type arity8 = (. int, int, int, int, int, int, int, int) => int -type arity9 = (. int, int, int, int, int, int, int, int, int) => int -type arity10 = (. int, int, int, int, int, int, int, int, int, int) => int -type arity11 = (. int, int, int, int, int, int, int, int, int, int, int) => int -type arity12 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity13 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity14 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity15 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity16 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity17 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity18 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity19 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity20 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity21 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int -type arity22 = (. - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, - int, -) => int type obj1<'a> = option<{"a": int}> type obj2 = {"a": int} type obj3 = {"a": int} type obj4 = {"a": int} -type obj5<'a> = Js.t<'a> +type obj5<'a> = 'a constraint 'a = {..} type obj6 = {"a": int} type obj7 = {"a": int} diff --git a/res_syntax/tests/oprint/oprint.res b/res_syntax/tests/oprint/oprint.res index d276bd7cba..5caa4461cc 100644 --- a/res_syntax/tests/oprint/oprint.res +++ b/res_syntax/tests/oprint/oprint.res @@ -218,68 +218,15 @@ type exoticUser = { \"type": float } -module Js = { - type t<'a> = 'a - - module Fn = { - type arity0<'a> = {i0: unit => 'a} - type arity1<'a> = {i1: 'a} - type arity2<'a> = {i2: 'a} - type arity3<'a> = {i3: 'a} - type arity4<'a> = {i4: 'a} - type arity5<'a> = {i5: 'a} - type arity6<'a> = {i6: 'a} - type arity7<'a> = {i7: 'a} - type arity8<'a> = {i8: 'a} - type arity9<'a> = {i9: 'a} - type arity10<'a> = {i10: 'a} - type arity11<'a> = {i11: 'a} - type arity12<'a> = {i12: 'a} - type arity13<'a> = {i13: 'a} - type arity14<'a> = {i14: 'a} - type arity15<'a> = {i15: 'a} - type arity16<'a> = {i16: 'a} - type arity17<'a> = {i17: 'a} - type arity18<'a> = {i18: 'a} - type arity19<'a> = {i19: 'a} - type arity20<'a> = {i20: 'a} - type arity21<'a> = {i21: 'a} - type arity22<'a> = {i22: 'a} - } -} +type arity1a = (. ()) => int +type arity1b = (. int) => int +type arity2 = (. int, int) => int -type arity0 = Js.Fn.arity0 -type arity0b = Js.Fn.arity0 -type arity0c = Js.Fn.arity0>> -type arity0d = Js.Fn.arity0 unit> -type arity1 = Js.Fn.arity1<(int) => int> -type arity2 = Js.Fn.arity2<(int, int) => int> -type arity3 = Js.Fn.arity3<(int, int, int) => int> -type arity4 = Js.Fn.arity4<(int, int, int, int) => int> -type arity5 = Js.Fn.arity5<(int, int, int, int, int) => int> -type arity6 = Js.Fn.arity6<(int, int, int, int, int, int) => int> -type arity7 = Js.Fn.arity7<(int, int, int, int, int, int, int) => int> -type arity8 = Js.Fn.arity8<(int, int, int, int, int, int, int, int) => int> -type arity9 = Js.Fn.arity9<(int, int, int, int, int, int, int, int, int) => int> -type arity10 = Js.Fn.arity10<(int, int, int, int, int, int, int, int, int, int) => int> -type arity11 = Js.Fn.arity11<(int, int, int, int, int, int, int, int, int, int, int) => int> -type arity12 = Js.Fn.arity12<(int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity13 = Js.Fn.arity13<(int, int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity14 = Js.Fn.arity14<(int, int, int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity15 = Js.Fn.arity15<(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity16 = Js.Fn.arity16<(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity17 = Js.Fn.arity17<(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity18 = Js.Fn.arity18<(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity19 = Js.Fn.arity19<(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity20 = Js.Fn.arity20<(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity21 = Js.Fn.arity21<(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) => int> -type arity22 = Js.Fn.arity22<(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) => int> - -type obj1<'a> = option> -type obj2 = Js.t<{"a": int}> -type obj3 = Js.t<{. "a": int}> +type obj1<'a> = option<{"a": int}> +type obj2 = {"a": int} +type obj3 = {. "a": int} type obj4 = {"a": int} -type obj5<'a> = Js.t<{..} as 'a> +type obj5<'a> = {..} as 'a type obj6 = {"a": int} type obj7 = {. "a": int} type obj8<'a> = {.. "a": int} as 'a diff --git a/res_syntax/tests/parsing/errors/other/expected/regionMissingComma.res.txt b/res_syntax/tests/parsing/errors/other/expected/regionMissingComma.res.txt index 1352f7d960..11ff69899c 100644 --- a/res_syntax/tests/parsing/errors/other/expected/regionMissingComma.res.txt +++ b/res_syntax/tests/parsing/errors/other/expected/regionMissingComma.res.txt @@ -24,8 +24,8 @@ external make : ?style:((ReactDOMRe.Style.t)[@res.namedArgLoc ]) -> - (?image:((bool)[@res.namedArgLoc ]) -> React.element) Js.Fn.arity1 = - "ModalContent" + (?image:((bool)[@res.namedArgLoc ]) -> React.element, [ `Has_arity1 ]) + function$ = "ModalContent" type nonrec 'extraInfo student = { name: string ; diff --git a/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt b/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt index d5c21319c2..f1d09f99ef 100644 --- a/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt +++ b/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt @@ -1,29 +1,33 @@ let cApp = foo 3 let uApp = ((foo 3)[@res.uapp ]) let cFun x = 3 -let uFun = { Js.Fn.I1 = (fun x -> 3) } +let uFun = ((Function$ (fun x -> 3))[@res.arity 1]) let mixFun a = - { - Js.Fn.I2 = + ((Function$ (fun b -> fun c -> - ((fun d -> fun e -> fun f -> fun g -> { Js.Fn.I1 = (fun h -> 4) }) - [@res.braces ])) - } -let bracesFun = { Js.Fn.I1 = (fun x -> ((fun y -> x + y)[@res.braces ])) } + ((fun d -> + fun e -> + fun f -> fun g -> ((Function$ (fun h -> 4))[@res.arity 1])) + [@res.braces ]))) + [@res.arity 2]) +let bracesFun = ((Function$ (fun x -> ((fun y -> x + y)[@res.braces ]))) + [@res.arity 1]) let cFun2 x y = 3 -let uFun2 = { Js.Fn.I2 = (fun x -> fun y -> 3) } +let uFun2 = ((Function$ (fun x -> fun y -> 3))[@res.arity 2]) type nonrec cTyp = string -> int -type nonrec uTyp = (string -> int) Js.Fn.arity1 +type nonrec uTyp = (string -> int, [ `Has_arity1 ]) function$ type nonrec mixTyp = string -> (string -> string -> - string -> string -> string -> string -> (string -> int) Js.Fn.arity1) - Js.Fn.arity2 -type nonrec bTyp = (string -> string -> int) Js.Fn.arity1 + string -> + string -> + string -> string -> (string -> int, [ `Has_arity1 ]) function$, + [ `Has_arity2 ]) function$ +type nonrec bTyp = (string -> string -> int, [ `Has_arity1 ]) function$ type nonrec cTyp2 = string -> string -> int -type nonrec uTyp2 = (string -> string -> int) Js.Fn.arity2 +type nonrec uTyp2 = (string -> string -> int, [ `Has_arity2 ]) function$ type nonrec cu = unit -> int type nonrec cp = unit -> int type nonrec cuu = unit -> unit -> int @@ -32,62 +36,78 @@ type nonrec cup = unit -> unit -> int type nonrec cpp = unit -> unit -> int type nonrec cu2 = unit -> unit -> unit type nonrec cp2 = unit -> unit -> unit -type nonrec uu = (unit -> int) Js.Fn.arity1 -type nonrec up = (unit -> int) Js.Fn.arity1 -type nonrec uuu = (unit -> (unit -> int) Js.Fn.arity1) Js.Fn.arity1 -type nonrec upu = (unit -> (unit -> int) Js.Fn.arity1) Js.Fn.arity1 -type nonrec uup = (unit -> (unit -> int) Js.Fn.arity1) Js.Fn.arity1 -type nonrec upp = (unit -> (unit -> int) Js.Fn.arity1) Js.Fn.arity1 -type nonrec uu2 = (unit -> unit -> unit) Js.Fn.arity2 -type nonrec up2 = (unit -> unit -> unit) Js.Fn.arity2 +type nonrec uu = (unit -> int, [ `Has_arity1 ]) function$ +type nonrec up = (unit -> int, [ `Has_arity1 ]) function$ +type nonrec uuu = + (unit -> (unit -> int, [ `Has_arity1 ]) function$, [ `Has_arity1 ]) + function$ +type nonrec upu = + (unit -> (unit -> int, [ `Has_arity1 ]) function$, [ `Has_arity1 ]) + function$ +type nonrec uup = + (unit -> (unit -> int, [ `Has_arity1 ]) function$, [ `Has_arity1 ]) + function$ +type nonrec upp = + (unit -> (unit -> int, [ `Has_arity1 ]) function$, [ `Has_arity1 ]) + function$ +type nonrec uu2 = (unit -> unit -> unit, [ `Has_arity2 ]) function$ +type nonrec up2 = (unit -> unit -> unit, [ `Has_arity2 ]) function$ type nonrec cnested = (string -> unit) -> unit -type nonrec unested = ((string -> unit) Js.Fn.arity1 -> unit) Js.Fn.arity1 -let (uannpoly : ('a -> string) Js.Fn.arity1) = xx -let (uannint : (int -> string) Js.Fn.arity1) = xx -let _ = { Js.Fn.I1 = ((fun x -> 34)[@att ]) } -let _ = { Js.Fn.I1 = ((fun x -> 34)[@res.async ][@att ]) } -let _ = preserveAttr { Js.Fn.I1 = ((fun x -> 34)[@att ]) } -let _ = preserveAttr { Js.Fn.I1 = ((fun x -> 34)[@res.async ][@att ]) } +type nonrec unested = + ((string -> unit, [ `Has_arity1 ]) function$ -> unit, [ `Has_arity1 ]) + function$ +let (uannpoly : ('a -> string, [ `Has_arity1 ]) function$) = xx +let (uannint : (int -> string, [ `Has_arity1 ]) function$) = xx +let _ = ((Function$ ((fun x -> 34)[@att ]))[@res.arity 1]) +let _ = ((Function$ ((fun x -> 34)[@res.async ][@att ]))[@res.arity 1]) +let _ = preserveAttr ((Function$ ((fun x -> 34)[@att ]))[@res.arity 1]) +let _ = + preserveAttr ((Function$ ((fun x -> 34)[@res.async ][@att ])) + [@res.arity 1]) let t0 (type a) (type b) (l : a list) (x : a) = x :: l let t1 (type a) (type b) = - { Js.Fn.I2 = (fun (l : a list) -> fun (x : a) -> x :: l) } + ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) let t2 (type a) (type b) = - { Js.Fn.I2 = (fun (l : a list) -> fun (x : a) -> x :: l) } + ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) let t3 (type a) (type b) = - { Js.Fn.I2 = (fun (l : a list) -> fun (x : a) -> x :: l) } + ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) let t4 (type a) (type b) (l : a list) (x : a) = x :: l let t5 (type a) (type b) = - { Js.Fn.I2 = (fun (l : a list) -> fun (x : a) -> x :: l) } + ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) let t6 (type a) (type b) = - { Js.Fn.I2 = (fun (l : a list) -> fun (x : a) -> x :: l) } + ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) [@@@uncurried ] let cApp = foo 3 let uApp = ((foo 3)[@res.uapp ]) let cFun x = 3 -let uFun = { Js.Fn.I1 = (fun x -> 3) } +let uFun = ((Function$ (fun x -> 3))[@res.arity 1]) let mixFun a = - { - Js.Fn.I2 = + ((Function$ (fun b -> fun c -> - ((fun d -> fun e -> fun f -> fun g -> { Js.Fn.I1 = (fun h -> 4) }) - [@res.braces ])) - } -let bracesFun = { Js.Fn.I1 = (fun x -> ((fun y -> x + y)[@res.braces ])) } + ((fun d -> + fun e -> + fun f -> fun g -> ((Function$ (fun h -> 4))[@res.arity 1])) + [@res.braces ]))) + [@res.arity 2]) +let bracesFun = ((Function$ (fun x -> ((fun y -> x + y)[@res.braces ]))) + [@res.arity 1]) let cFun2 x y = 3 -let uFun2 = { Js.Fn.I2 = (fun x -> fun y -> 3) } +let uFun2 = ((Function$ (fun x -> fun y -> 3))[@res.arity 2]) let cFun2Dots x y = 3 type nonrec cTyp = string -> int -type nonrec uTyp = (string -> int) Js.Fn.arity1 +type nonrec uTyp = (string -> int, [ `Has_arity1 ]) function$ type nonrec mixTyp = string -> (string -> string -> - string -> string -> string -> string -> (string -> int) Js.Fn.arity1) - Js.Fn.arity2 -type nonrec bTyp = (string -> string -> int) Js.Fn.arity1 + string -> + string -> + string -> string -> (string -> int, [ `Has_arity1 ]) function$, + [ `Has_arity2 ]) function$ +type nonrec bTyp = (string -> string -> int, [ `Has_arity1 ]) function$ type nonrec cTyp2 = string -> string -> int -type nonrec uTyp2 = (string -> string -> int) Js.Fn.arity2 +type nonrec uTyp2 = (string -> string -> int, [ `Has_arity2 ]) function$ type nonrec cu = unit -> int type nonrec cp = unit -> int type nonrec cuu = unit -> unit -> int @@ -96,26 +116,39 @@ type nonrec cup = unit -> unit -> int type nonrec cpp = unit -> unit -> int type nonrec cu2 = unit -> unit -> unit type nonrec cp2 = unit -> unit -> unit -type nonrec uu = (unit -> int) Js.Fn.arity1 -type nonrec up = (unit -> int) Js.Fn.arity1 -type nonrec uuu = (unit -> (unit -> int) Js.Fn.arity1) Js.Fn.arity1 -type nonrec upu = (unit -> (unit -> int) Js.Fn.arity1) Js.Fn.arity1 -type nonrec uup = (unit -> (unit -> int) Js.Fn.arity1) Js.Fn.arity1 -type nonrec upp = (unit -> (unit -> int) Js.Fn.arity1) Js.Fn.arity1 -type nonrec uu2 = (unit -> unit -> unit) Js.Fn.arity2 -type nonrec up2 = (unit -> unit -> unit) Js.Fn.arity2 +type nonrec uu = (unit -> int, [ `Has_arity1 ]) function$ +type nonrec up = (unit -> int, [ `Has_arity1 ]) function$ +type nonrec uuu = + (unit -> (unit -> int, [ `Has_arity1 ]) function$, [ `Has_arity1 ]) + function$ +type nonrec upu = + (unit -> (unit -> int, [ `Has_arity1 ]) function$, [ `Has_arity1 ]) + function$ +type nonrec uup = + (unit -> (unit -> int, [ `Has_arity1 ]) function$, [ `Has_arity1 ]) + function$ +type nonrec upp = + (unit -> (unit -> int, [ `Has_arity1 ]) function$, [ `Has_arity1 ]) + function$ +type nonrec uu2 = (unit -> unit -> unit, [ `Has_arity2 ]) function$ +type nonrec up2 = (unit -> unit -> unit, [ `Has_arity2 ]) function$ type nonrec cnested = (string -> unit) -> unit -type nonrec unested = ((string -> unit) Js.Fn.arity1 -> unit) Js.Fn.arity1 +type nonrec unested = + ((string -> unit, [ `Has_arity1 ]) function$ -> unit, [ `Has_arity1 ]) + function$ let pipe1 = 3 |.u f -let (uannpoly : ('a -> string) Js.Fn.arity1) = xx -let (uannint : (int -> string) Js.Fn.arity1) = xx -let _ = { Js.Fn.I1 = ((fun x -> 34)[@att ]) } -let _ = { Js.Fn.I1 = ((fun x -> 34)[@res.async ][@att ]) } -let _ = ((preserveAttr { Js.Fn.I1 = ((fun x -> 34)[@att ]) })[@res.uapp ]) -let _ = ((preserveAttr { Js.Fn.I1 = ((fun x -> 34)[@res.async ][@att ]) }) +let (uannpoly : ('a -> string, [ `Has_arity1 ]) function$) = xx +let (uannint : (int -> string, [ `Has_arity1 ]) function$) = xx +let _ = ((Function$ ((fun x -> 34)[@att ]))[@res.arity 1]) +let _ = ((Function$ ((fun x -> 34)[@res.async ][@att ]))[@res.arity 1]) +let _ = ((preserveAttr ((Function$ ((fun x -> 34)[@att ]))[@res.arity 1])) + [@res.uapp ]) +let _ = + ((preserveAttr ((Function$ ((fun x -> 34)[@res.async ][@att ])) + [@res.arity 1])) [@res.uapp ]) let t0 (type a) (type b) = - { Js.Fn.I2 = (fun (l : a list) -> fun (x : a) -> x :: l) } + ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) let t1 (type a) (type b) (l : a list) (x : a) = x :: l let t2 (type a) (type b) (l : a list) (x : a) = x :: l let t3 (type a) (type b) (l : a list) (x : a) = x :: l \ No newline at end of file diff --git a/res_syntax/tests/parsing/grammar/expressions/expected/apply.res.txt b/res_syntax/tests/parsing/grammar/expressions/expected/apply.res.txt index 218f341699..e6a0aa7437 100644 --- a/res_syntax/tests/parsing/grammar/expressions/expected/apply.res.txt +++ b/res_syntax/tests/parsing/grammar/expressions/expected/apply.res.txt @@ -1,6 +1,6 @@ ;;foo (fun _ -> bla) blaz ;;foo (fun _ -> bla) blaz -;;foo { Js.Fn.I1 = (fun _ -> bla) } blaz +;;foo ((Function$ (fun _ -> bla))[@res.arity 1]) blaz ;;foo (fun _ -> bla) (fun _ -> blaz) ;;List.map (fun x -> x + 1) myList ;;List.reduce (fun acc -> fun curr -> acc + curr) 0 myList diff --git a/res_syntax/tests/parsing/grammar/expressions/expected/argument.res.txt b/res_syntax/tests/parsing/grammar/expressions/expected/argument.res.txt index 12a91a2750..5e176ba56f 100644 --- a/res_syntax/tests/parsing/grammar/expressions/expected/argument.res.txt +++ b/res_syntax/tests/parsing/grammar/expressions/expected/argument.res.txt @@ -1,6 +1,6 @@ let foo ~a:((a)[@res.namedArgLoc ]) = ((a (let __res_unit = () in __res_unit))[@res.uapp ]) +. 1. -let a = { Js.Fn.I1 = (fun () -> 2) } +let a = ((Function$ (fun () -> 2))[@res.arity 1]) let bar = foo ~a:((a)[@res.namedArgLoc ]) let comparisonResult = ((compare currentNode.value ~targetValue:((targetValue)[@res.namedArgLoc ])) diff --git a/res_syntax/tests/parsing/grammar/expressions/expected/arrow.res.txt b/res_syntax/tests/parsing/grammar/expressions/expected/arrow.res.txt index fe1a6abe7b..c907472b4e 100644 --- a/res_syntax/tests/parsing/grammar/expressions/expected/arrow.res.txt +++ b/res_syntax/tests/parsing/grammar/expressions/expected/arrow.res.txt @@ -40,37 +40,36 @@ let f ?a:(((x : int option))[@res.namedArgLoc ]) ?b:(((y : int option))[@res.namedArgLoc ]) c = match (x, y) with | (Some a, Some b) -> (a + b) + c | _ -> 3 let f a b = a + b -let f = { Js.Fn.I1 = (fun () -> ()) } -let f = { Js.Fn.I1 = (fun () -> ()) } -let f = { Js.Fn.I3 = (fun a -> fun b -> fun c -> ()) } +let f = ((Function$ (fun () -> ()))[@res.arity 1]) +let f = ((Function$ (fun () -> ()))[@res.arity 1]) +let f = ((Function$ (fun a -> fun b -> fun c -> ()))[@res.arity 3]) let f = - { Js.Fn.I2 = (fun a -> fun b -> { Js.Fn.I2 = (fun c -> fun d -> ()) }) } + ((Function$ + (fun a -> fun b -> ((Function$ (fun c -> fun d -> ()))[@res.arity 2]))) + [@res.arity 2]) let f = - { - Js.Fn.I1 = - (fun a -> { Js.Fn.I1 = (fun b -> { Js.Fn.I1 = (fun c -> ()) }) }) - } + ((Function$ + (fun a -> + ((Function$ (fun b -> ((Function$ (fun c -> ()))[@res.arity 1]))) + [@res.arity 1]))) + [@res.arity 1]) let f = - { - Js.Fn.I2 = + ((Function$ (fun ~a:((a)[@res.namedArgLoc ][@attr ]) -> fun b -> - { - Js.Fn.I2 = - (fun ~c:((c)[@res.namedArgLoc ][@attr ]) -> fun d -> ()) - }) - } + ((Function$ + (fun ~c:((c)[@res.namedArgLoc ][@attr ]) -> fun d -> ())) + [@res.arity 2]))) + [@res.arity 2]) let f = - { - Js.Fn.I2 = + ((Function$ (fun ~a:((a)[@res.namedArgLoc ][@attr ]) -> fun ((b)[@attrOnB ]) -> - { - Js.Fn.I2 = + ((Function$ (fun ~c:((c)[@res.namedArgLoc ][@attr ]) -> - fun ((d)[@attrOnD ]) -> ()) - }) - } + fun ((d)[@attrOnD ]) -> ())) + [@res.arity 2]))) + [@res.arity 2]) let f list = list () ;;match colour with | Red when diff --git a/res_syntax/tests/parsing/grammar/expressions/expected/async.res.txt b/res_syntax/tests/parsing/grammar/expressions/expected/async.res.txt index 1965d81b0f..585d61302e 100644 --- a/res_syntax/tests/parsing/grammar/expressions/expected/async.res.txt +++ b/res_syntax/tests/parsing/grammar/expressions/expected/async.res.txt @@ -6,18 +6,15 @@ let greetUser = [@res.async ]) ;;((fun () -> 123)[@res.async ]) let fetch = - (({ Js.Fn.I1 = ((fun url -> ((browserFetch url)[@res.uapp ]))[@res.async ]) - }) - [@res.braces ]) + ((Function$ ((fun url -> ((browserFetch url)[@res.uapp ]))[@res.async ])) + [@res.braces ][@res.arity 1]) let fetch2 = - (({ - Js.Fn.I1 = (((fun url -> ((browserFetch url)[@res.uapp ]))) - [@res.async ]) - }; - { - Js.Fn.I1 = (((fun url -> ((browserFetch2 url)[@res.uapp ]))) - [@res.async ]) - }) + ((((Function$ (((fun url -> ((browserFetch url)[@res.uapp ]))) + [@res.async ])) + [@res.arity 1]); + ((Function$ (((fun url -> ((browserFetch2 url)[@res.uapp ]))) + [@res.async ])) + [@res.arity 1])) [@res.braces ]) let async = ((let f = async () in diff --git a/res_syntax/tests/parsing/grammar/expressions/expected/uncurried.res.txt b/res_syntax/tests/parsing/grammar/expressions/expected/uncurried.res.txt index 60e79c4c0b..49f5b006cc 100644 --- a/res_syntax/tests/parsing/grammar/expressions/expected/uncurried.res.txt +++ b/res_syntax/tests/parsing/grammar/expressions/expected/uncurried.res.txt @@ -1,34 +1,35 @@ -let f = { Js.Fn.I2 = (fun a -> fun b -> a + b) } -let f = { Js.Fn.I1 = (fun a -> { Js.Fn.I1 = (fun b -> a + b) }) } +let f = ((Function$ (fun a -> fun b -> a + b))[@res.arity 2]) +let f = ((Function$ (fun a -> ((Function$ (fun b -> a + b))[@res.arity 1]))) + [@res.arity 1]) let f = - { - Js.Fn.I2 = - (fun a -> fun b -> { Js.Fn.I2 = (fun c -> fun d -> ((a + b) + c) + d) }) - } + ((Function$ + (fun a -> + fun b -> ((Function$ (fun c -> fun d -> ((a + b) + c) + d)) + [@res.arity 2]))) + [@res.arity 2]) let f = - { - Js.Fn.I1 = + ((Function$ ((fun a -> ((fun b -> - { - Js.Fn.I1 = ((fun c -> ((fun d -> ())[@res.braces ][@attr4 ])) - [@attr3 ]) - }) - [@res.braces ][@attr2 ]))[@attr ]) - } + ((Function$ ((fun c -> ((fun d -> ())[@res.braces ][@attr4 ])) + [@attr3 ])) + [@res.arity 1])) + [@res.braces ][@attr2 ])) + [@attr ])) + [@res.arity 1]) let f = - { - Js.Fn.I2 = + ((Function$ (fun ((a)[@attr ]) -> fun ((b)[@attr2 ]) -> - { Js.Fn.I2 = (fun ((c)[@attr3 ]) -> fun ((d)[@attr4 ]) -> ()) }) - } + ((Function$ (fun ((c)[@attr3 ]) -> fun ((d)[@attr4 ]) -> ())) + [@res.arity 2]))) + [@res.arity 2]) let f = - { - Js.Fn.I2 = + ((Function$ (fun ((a)[@attr ]) -> fun ((b)[@attr2 ]) -> - { Js.Fn.I2 = (fun ((c)[@attr3 ]) -> fun ((d)[@attr4 ]) -> ()) }) - } + ((Function$ (fun ((c)[@attr3 ]) -> fun ((d)[@attr4 ]) -> ())) + [@res.arity 2]))) + [@res.arity 2]) ;;((add 1 2)[@res.uapp ]) ;;((((((add 2 3 4)[@res.uapp ]) 5 6 7)[@res.uapp ]) 8 9 10)[@res.uapp ]) \ No newline at end of file diff --git a/res_syntax/tests/parsing/grammar/typexpr/expected/uncurried.res.txt b/res_syntax/tests/parsing/grammar/typexpr/expected/uncurried.res.txt index 413302962a..5097ce68d8 100644 --- a/res_syntax/tests/parsing/grammar/typexpr/expected/uncurried.res.txt +++ b/res_syntax/tests/parsing/grammar/typexpr/expected/uncurried.res.txt @@ -1,22 +1,28 @@ -type nonrec t = { - mutable field: (float -> int -> bool -> unit) Js.Fn.arity3 } -type nonrec t = (float -> int -> bool -> unit) Js.Fn.arity3 +type nonrec t = + { + mutable field: (float -> int -> bool -> unit, [ `Has_arity3 ]) function$ } +type nonrec t = (float -> int -> bool -> unit, [ `Has_arity3 ]) function$ type nonrec t = (((float)[@attr ]) -> ((int)[@attr2 ]) -> - (((bool)[@attr3 ]) -> ((string)[@attr4 ]) -> unit) Js.Fn.arity2) - Js.Fn.arity2 + (((bool)[@attr3 ]) -> ((string)[@attr4 ]) -> unit, [ `Has_arity2 ]) + function$, + [ `Has_arity2 ]) function$ type nonrec t = (((float -> ((int)[@attr2 ]) -> - (((bool -> ((string)[@attr4 ]) -> unit) Js.Fn.arity1)[@attr3 ])) - Js.Fn.arity1)[@attr ]) + (((bool -> ((string)[@attr4 ]) -> unit, [ `Has_arity1 ]) function$) + [@attr3 ]), + [ `Has_arity1 ]) function$)[@attr ]) type nonrec t = (((float)[@attr ]) -> ((int)[@attr2 ]) -> - (((bool)[@attr3 ]) -> ((string)[@attr4 ]) -> unit) Js.Fn.arity2) - Js.Fn.arity2 + (((bool)[@attr3 ]) -> ((string)[@attr4 ]) -> unit, [ `Has_arity2 ]) + function$, + [ `Has_arity2 ]) function$ external setTimeout : - (unit -> unit) Js.Fn.arity1 -> int -> timerId = "setTimeout"[@@bs.val ] + (unit -> unit, [ `Has_arity1 ]) function$ -> int -> timerId = "setTimeout" +[@@bs.val ] external setTimeout : - ((unit -> unit) -> int -> timerId) Js.Fn.arity2 = "setTimeout" \ No newline at end of file + ((unit -> unit) -> int -> timerId, [ `Has_arity2 ]) function$ = + "setTimeout" \ No newline at end of file