Skip to content

Commit 861318b

Browse files
committed
Use res.uapp for uncurried app attribute coming from the parser.
1 parent 259dd81 commit 861318b

19 files changed

+270
-95
lines changed

jscomp/frontend/ast_attributes.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,12 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
305305
_;
306306
};
307307
]
308-
when Ast_utf8_string_interp.parse_processed_delim delim_ <> None -> (
308+
when Ast_utf8_string_interp.parse_processed_delim delim_
309+
<> None -> (
309310
let delim =
310-
match Ast_utf8_string_interp.parse_processed_delim delim_ with
311+
match
312+
Ast_utf8_string_interp.parse_processed_delim delim_
313+
with
311314
| None -> assert false
312315
| Some delim -> delim
313316
in
@@ -338,6 +341,9 @@ let locg = Location.none
338341
let is_bs (attr : attr) =
339342
match attr with { Location.txt = "bs"; _ }, _ -> true | _ -> false
340343

344+
let is_uncurried_app (attr : attr) =
345+
match attr with { Location.txt = "res.uapp"; _ }, _ -> true | _ -> false
346+
341347
let bs_get : attr = ({ txt = "bs.get"; loc = locg }, Ast_payload.empty)
342348

343349
let bs_get_index : attr =

jscomp/frontend/ast_attributes.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ val is_bs : attr -> bool
7272
(* val is_optional : attr -> bool
7373
val is_bs_as : attr -> bool *)
7474

75+
val is_uncurried_app : attr -> bool
76+
7577
val bs_get : attr
7678

7779
val bs_get_index : attr

jscomp/frontend/ast_exp_apply.ml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
158158
})
159159
| _ -> (
160160
match
161-
( Ext_list.exclude_with_val f_.pexp_attributes
162-
Ast_attributes.is_bs,
161+
( Ext_list.exclude_with_val f_.pexp_attributes (fun a ->
162+
Ast_attributes.is_bs a
163+
|| Ast_attributes.is_uncurried_app a),
163164
f_.pexp_desc )
164165
with
165166
| Some other_attributes, Pexp_apply (fn1, args) ->
@@ -173,8 +174,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
173174
fn1.pexp_attributes;
174175
{
175176
pexp_desc =
176-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op="|.") e.pexp_loc self fn1
177-
((Nolabel, a) :: args);
177+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op = "|.")
178+
e.pexp_loc self fn1 ((Nolabel, a) :: args);
178179
pexp_loc = e.pexp_loc;
179180
pexp_attributes = e.pexp_attributes @ other_attributes;
180181
}
@@ -183,7 +184,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
183184
Uncurried unary application *)
184185
{
185186
pexp_desc =
186-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false e.pexp_loc self f
187+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false
188+
e.pexp_loc self f
187189
[ (Nolabel, a) ];
188190
pexp_loc = e.pexp_loc;
189191
pexp_attributes = e.pexp_attributes;
@@ -283,11 +285,25 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
283285
match
284286
Ext_list.exclude_with_val e.pexp_attributes Ast_attributes.is_bs
285287
with
286-
| None -> default_expr_mapper self e
287288
| Some pexp_attributes ->
288289
{
289290
e with
290291
pexp_desc =
291-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc self fn args;
292+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc
293+
self fn args;
292294
pexp_attributes;
293-
}))
295+
}
296+
| None -> (
297+
match
298+
Ext_list.exclude_with_val e.pexp_attributes
299+
Ast_attributes.is_uncurried_app
300+
with
301+
| Some pexp_attributes ->
302+
{
303+
e with
304+
pexp_desc =
305+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false
306+
e.pexp_loc self fn args;
307+
pexp_attributes;
308+
}
309+
| None -> default_expr_mapper self e)))

jscomp/test/UncurriedExternals.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ module StandardNotation = {
2424
external toException: (. exn) => exn = "%identity"
2525
let te = toException(. Not_found)
2626

27-
@obj external ccreate : () => string = ""
28-
let tcr = ccreate()
27+
@obj external ccreate : (. unit) => string = ""
28+
let tcr = ccreate(.)
2929
}
3030

3131
@@uncurried
@@ -56,4 +56,4 @@ external toException: exn => exn = "%identity"
5656
let te = toException(Not_found)
5757

5858
@obj external ucreate : unit => string = ""
59-
let tcr = ucreate( (():unit))
59+
let tcr = ucreate()

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49432,6 +49432,9 @@ val functorType :
4943249432
(* filters @bs out of the provided attributes *)
4943349433
val processBsAttribute : Parsetree.attributes -> bool * Parsetree.attributes
4943449434

49435+
val processUncurriedAppAttribute :
49436+
Parsetree.attributes -> bool * Parsetree.attributes
49437+
4943549438
type functionAttributesInfo = {
4943649439
async: bool;
4943749440
uncurried: bool;
@@ -49631,6 +49634,21 @@ let processBsAttribute attrs =
4963149634
in
4963249635
process false [] attrs
4963349636

49637+
let processUncurriedAppAttribute attrs =
49638+
let rec process bsSpotted acc attrs =
49639+
match attrs with
49640+
| [] -> (bsSpotted, List.rev acc)
49641+
| ( {
49642+
Location.txt =
49643+
"bs" (* still support @bs to convert .ml files *) | "res.uapp";
49644+
},
49645+
_ )
49646+
:: rest ->
49647+
process true acc rest
49648+
| attr :: rest -> process bsSpotted (attr :: acc) rest
49649+
in
49650+
process false [] attrs
49651+
4963449652
type functionAttributesInfo = {
4963549653
async: bool;
4963649654
uncurried: bool;
@@ -49757,7 +49775,7 @@ let filterParsingAttrs attrs =
4975749775
match attr with
4975849776
| ( {
4975949777
Location.txt =
49760-
( "bs" | "ns.braces" | "ns.iflet" | "ns.namedArgLoc"
49778+
( "bs" | "res.uapp" | "ns.braces" | "ns.iflet" | "ns.namedArgLoc"
4976149779
| "ns.optional" | "ns.ternary" | "res.async" | "res.await"
4976249780
| "res.template" );
4976349781
},
@@ -49906,8 +49924,8 @@ let hasAttributes attrs =
4990649924
match attr with
4990749925
| ( {
4990849926
Location.txt =
49909-
( "bs" | "ns.braces" | "ns.iflet" | "ns.ternary" | "res.async"
49910-
| "res.await" | "res.template" );
49927+
( "bs" | "res.uapp" | "ns.braces" | "ns.iflet" | "ns.ternary"
49928+
| "res.async" | "res.await" | "res.template" );
4991149929
},
4991249930
_ ) ->
4991349931
false
@@ -50088,8 +50106,8 @@ let isPrintableAttribute attr =
5008850106
match attr with
5008950107
| ( {
5009050108
Location.txt =
50091-
( "bs" | "ns.iflet" | "ns.braces" | "JSX" | "res.async" | "res.await"
50092-
| "res.template" | "ns.ternary" );
50109+
( "bs" | "res.uapp" | "ns.iflet" | "ns.braces" | "JSX" | "res.async"
50110+
| "res.await" | "res.template" | "ns.ternary" );
5009350111
},
5009450112
_ ) ->
5009550113
false
@@ -57037,7 +57055,7 @@ and printPexpApply ~state expr cmtTbl =
5703757055
args
5703857056
in
5703957057
let hasBs, attrs =
57040-
ParsetreeViewer.processBsAttribute expr.pexp_attributes
57058+
ParsetreeViewer.processUncurriedAppAttribute expr.pexp_attributes
5704157059
in
5704257060
let dotted =
5704357061
if state.State.uncurried_by_default then not hasBs else hasBs
@@ -145055,6 +145073,8 @@ val is_bs : attr -> bool
145055145073
(* val is_optional : attr -> bool
145056145074
val is_bs_as : attr -> bool *)
145057145075

145076+
val is_uncurried_app : attr -> bool
145077+
145058145078
val bs_get : attr
145059145079

145060145080
val bs_get_index : attr
@@ -145381,9 +145401,12 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
145381145401
_;
145382145402
};
145383145403
]
145384-
when Ast_utf8_string_interp.parse_processed_delim delim_ <> None -> (
145404+
when Ast_utf8_string_interp.parse_processed_delim delim_
145405+
<> None -> (
145385145406
let delim =
145386-
match Ast_utf8_string_interp.parse_processed_delim delim_ with
145407+
match
145408+
Ast_utf8_string_interp.parse_processed_delim delim_
145409+
with
145387145410
| None -> assert false
145388145411
| Some delim -> delim
145389145412
in
@@ -145414,6 +145437,9 @@ let locg = Location.none
145414145437
let is_bs (attr : attr) =
145415145438
match attr with { Location.txt = "bs"; _ }, _ -> true | _ -> false
145416145439

145440+
let is_uncurried_app (attr : attr) =
145441+
match attr with { Location.txt = "res.uapp"; _ }, _ -> true | _ -> false
145442+
145417145443
let bs_get : attr = ({ txt = "bs.get"; loc = locg }, Ast_payload.empty)
145418145444

145419145445
let bs_get_index : attr =
@@ -150438,8 +150464,9 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150438150464
})
150439150465
| _ -> (
150440150466
match
150441-
( Ext_list.exclude_with_val f_.pexp_attributes
150442-
Ast_attributes.is_bs,
150467+
( Ext_list.exclude_with_val f_.pexp_attributes (fun a ->
150468+
Ast_attributes.is_bs a
150469+
|| Ast_attributes.is_uncurried_app a),
150443150470
f_.pexp_desc )
150444150471
with
150445150472
| Some other_attributes, Pexp_apply (fn1, args) ->
@@ -150453,8 +150480,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150453150480
fn1.pexp_attributes;
150454150481
{
150455150482
pexp_desc =
150456-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op="|.") e.pexp_loc self fn1
150457-
((Nolabel, a) :: args);
150483+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op = "|.")
150484+
e.pexp_loc self fn1 ((Nolabel, a) :: args);
150458150485
pexp_loc = e.pexp_loc;
150459150486
pexp_attributes = e.pexp_attributes @ other_attributes;
150460150487
}
@@ -150463,7 +150490,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150463150490
Uncurried unary application *)
150464150491
{
150465150492
pexp_desc =
150466-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false e.pexp_loc self f
150493+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false
150494+
e.pexp_loc self f
150467150495
[ (Nolabel, a) ];
150468150496
pexp_loc = e.pexp_loc;
150469150497
pexp_attributes = e.pexp_attributes;
@@ -150563,14 +150591,28 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150563150591
match
150564150592
Ext_list.exclude_with_val e.pexp_attributes Ast_attributes.is_bs
150565150593
with
150566-
| None -> default_expr_mapper self e
150567150594
| Some pexp_attributes ->
150568150595
{
150569150596
e with
150570150597
pexp_desc =
150571-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc self fn args;
150598+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc
150599+
self fn args;
150572150600
pexp_attributes;
150573-
}))
150601+
}
150602+
| None -> (
150603+
match
150604+
Ext_list.exclude_with_val e.pexp_attributes
150605+
Ast_attributes.is_uncurried_app
150606+
with
150607+
| Some pexp_attributes ->
150608+
{
150609+
e with
150610+
pexp_desc =
150611+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false
150612+
e.pexp_loc self fn args;
150613+
pexp_attributes;
150614+
}
150615+
| None -> default_expr_mapper self e)))
150574150616

150575150617
end
150576150618
module Ast_exp : sig

0 commit comments

Comments
 (0)