Skip to content

Commit 0a12ef6

Browse files
committed
Use res.uapp for uncurried app attribute coming from the parser.
1 parent 2242e84 commit 0a12ef6

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
@@ -57042,7 +57060,7 @@ and printPexpApply ~state expr cmtTbl =
5704257060
args
5704357061
in
5704457062
let hasBs, attrs =
57045-
ParsetreeViewer.processBsAttribute expr.pexp_attributes
57063+
ParsetreeViewer.processUncurriedAppAttribute expr.pexp_attributes
5704657064
in
5704757065
let dotted =
5704857066
if state.State.uncurried_by_default then not hasBs else hasBs
@@ -145060,6 +145078,8 @@ val is_bs : attr -> bool
145060145078
(* val is_optional : attr -> bool
145061145079
val is_bs_as : attr -> bool *)
145062145080

145081+
val is_uncurried_app : attr -> bool
145082+
145063145083
val bs_get : attr
145064145084

145065145085
val bs_get_index : attr
@@ -145386,9 +145406,12 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
145386145406
_;
145387145407
};
145388145408
]
145389-
when Ast_utf8_string_interp.parse_processed_delim delim_ <> None -> (
145409+
when Ast_utf8_string_interp.parse_processed_delim delim_
145410+
<> None -> (
145390145411
let delim =
145391-
match Ast_utf8_string_interp.parse_processed_delim delim_ with
145412+
match
145413+
Ast_utf8_string_interp.parse_processed_delim delim_
145414+
with
145392145415
| None -> assert false
145393145416
| Some delim -> delim
145394145417
in
@@ -145419,6 +145442,9 @@ let locg = Location.none
145419145442
let is_bs (attr : attr) =
145420145443
match attr with { Location.txt = "bs"; _ }, _ -> true | _ -> false
145421145444

145445+
let is_uncurried_app (attr : attr) =
145446+
match attr with { Location.txt = "res.uapp"; _ }, _ -> true | _ -> false
145447+
145422145448
let bs_get : attr = ({ txt = "bs.get"; loc = locg }, Ast_payload.empty)
145423145449

145424145450
let bs_get_index : attr =
@@ -150443,8 +150469,9 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150443150469
})
150444150470
| _ -> (
150445150471
match
150446-
( Ext_list.exclude_with_val f_.pexp_attributes
150447-
Ast_attributes.is_bs,
150472+
( Ext_list.exclude_with_val f_.pexp_attributes (fun a ->
150473+
Ast_attributes.is_bs a
150474+
|| Ast_attributes.is_uncurried_app a),
150448150475
f_.pexp_desc )
150449150476
with
150450150477
| Some other_attributes, Pexp_apply (fn1, args) ->
@@ -150458,8 +150485,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150458150485
fn1.pexp_attributes;
150459150486
{
150460150487
pexp_desc =
150461-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op="|.") e.pexp_loc self fn1
150462-
((Nolabel, a) :: args);
150488+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op = "|.")
150489+
e.pexp_loc self fn1 ((Nolabel, a) :: args);
150463150490
pexp_loc = e.pexp_loc;
150464150491
pexp_attributes = e.pexp_attributes @ other_attributes;
150465150492
}
@@ -150468,7 +150495,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150468150495
Uncurried unary application *)
150469150496
{
150470150497
pexp_desc =
150471-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false e.pexp_loc self f
150498+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false
150499+
e.pexp_loc self f
150472150500
[ (Nolabel, a) ];
150473150501
pexp_loc = e.pexp_loc;
150474150502
pexp_attributes = e.pexp_attributes;
@@ -150568,14 +150596,28 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150568150596
match
150569150597
Ext_list.exclude_with_val e.pexp_attributes Ast_attributes.is_bs
150570150598
with
150571-
| None -> default_expr_mapper self e
150572150599
| Some pexp_attributes ->
150573150600
{
150574150601
e with
150575150602
pexp_desc =
150576-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc self fn args;
150603+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc
150604+
self fn args;
150577150605
pexp_attributes;
150578-
}))
150606+
}
150607+
| None -> (
150608+
match
150609+
Ext_list.exclude_with_val e.pexp_attributes
150610+
Ast_attributes.is_uncurried_app
150611+
with
150612+
| Some pexp_attributes ->
150613+
{
150614+
e with
150615+
pexp_desc =
150616+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false
150617+
e.pexp_loc self fn args;
150618+
pexp_attributes;
150619+
}
150620+
| None -> default_expr_mapper self e)))
150579150621

150580150622
end
150581150623
module Ast_exp : sig

0 commit comments

Comments
 (0)