Skip to content

Commit 131b944

Browse files
committed
Use res.uapp for uncurried app attribute coming from the parser.
1 parent 06be27b commit 131b944

File tree

19 files changed

+282
-104
lines changed

19 files changed

+282
-104
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
bs: bool;
@@ -49633,6 +49636,21 @@ let processBsAttribute attrs =
4963349636
in
4963449637
process false [] attrs
4963549638

49639+
let processUncurriedAppAttribute attrs =
49640+
let rec process bsSpotted acc attrs =
49641+
match attrs with
49642+
| [] -> (bsSpotted, List.rev acc)
49643+
| ( {
49644+
Location.txt =
49645+
"bs" (* still support @bs to convert .ml files *) | "res.uapp";
49646+
},
49647+
_ )
49648+
:: rest ->
49649+
process true acc rest
49650+
| attr :: rest -> process bsSpotted (attr :: acc) rest
49651+
in
49652+
process false [] attrs
49653+
4963649654
type functionAttributesInfo = {
4963749655
async: bool;
4963849656
bs: bool;
@@ -49762,7 +49780,7 @@ let filterParsingAttrs attrs =
4976249780
match attr with
4976349781
| ( {
4976449782
Location.txt =
49765-
( "bs" | "ns.braces" | "ns.iflet" | "ns.namedArgLoc"
49783+
( "bs" | "res.uapp" | "ns.braces" | "ns.iflet" | "ns.namedArgLoc"
4976649784
| "ns.optional" | "ns.ternary" | "res.async" | "res.await"
4976749785
| "res.template" );
4976849786
},
@@ -49911,8 +49929,8 @@ let hasAttributes attrs =
4991149929
match attr with
4991249930
| ( {
4991349931
Location.txt =
49914-
( "bs" | "ns.braces" | "ns.iflet" | "ns.ternary" | "res.async"
49915-
| "res.await" | "res.template" );
49932+
( "bs" | "res.uapp" | "ns.braces" | "ns.iflet" | "ns.ternary"
49933+
| "res.async" | "res.await" | "res.template" );
4991649934
},
4991749935
_ ) ->
4991849936
false
@@ -50093,8 +50111,8 @@ let isPrintableAttribute attr =
5009350111
match attr with
5009450112
| ( {
5009550113
Location.txt =
50096-
( "bs" | "ns.iflet" | "ns.braces" | "JSX" | "res.async" | "res.await"
50097-
| "res.template" | "ns.ternary" );
50114+
( "bs" | "res.uapp" | "ns.iflet" | "ns.braces" | "JSX" | "res.async"
50115+
| "res.await" | "res.template" | "ns.ternary" );
5009850116
},
5009950117
_ ) ->
5010050118
false
@@ -57064,7 +57082,7 @@ and printPexpApply ~state expr cmtTbl =
5706457082
args
5706557083
in
5706657084
let hasBs, attrs =
57067-
ParsetreeViewer.processBsAttribute expr.pexp_attributes
57085+
ParsetreeViewer.processUncurriedAppAttribute expr.pexp_attributes
5706857086
in
5706957087
let dotted =
5707057088
if state.State.uncurried_by_default then not hasBs else hasBs
@@ -145082,6 +145100,8 @@ val is_bs : attr -> bool
145082145100
(* val is_optional : attr -> bool
145083145101
val is_bs_as : attr -> bool *)
145084145102

145103+
val is_uncurried_app : attr -> bool
145104+
145085145105
val bs_get : attr
145086145106

145087145107
val bs_get_index : attr
@@ -145408,9 +145428,12 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) =
145408145428
_;
145409145429
};
145410145430
]
145411-
when Ast_utf8_string_interp.parse_processed_delim delim_ <> None -> (
145431+
when Ast_utf8_string_interp.parse_processed_delim delim_
145432+
<> None -> (
145412145433
let delim =
145413-
match Ast_utf8_string_interp.parse_processed_delim delim_ with
145434+
match
145435+
Ast_utf8_string_interp.parse_processed_delim delim_
145436+
with
145414145437
| None -> assert false
145415145438
| Some delim -> delim
145416145439
in
@@ -145441,6 +145464,9 @@ let locg = Location.none
145441145464
let is_bs (attr : attr) =
145442145465
match attr with { Location.txt = "bs"; _ }, _ -> true | _ -> false
145443145466

145467+
let is_uncurried_app (attr : attr) =
145468+
match attr with { Location.txt = "res.uapp"; _ }, _ -> true | _ -> false
145469+
145444145470
let bs_get : attr = ({ txt = "bs.get"; loc = locg }, Ast_payload.empty)
145445145471

145446145472
let bs_get_index : attr =
@@ -150465,8 +150491,9 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150465150491
})
150466150492
| _ -> (
150467150493
match
150468-
( Ext_list.exclude_with_val f_.pexp_attributes
150469-
Ast_attributes.is_bs,
150494+
( Ext_list.exclude_with_val f_.pexp_attributes (fun a ->
150495+
Ast_attributes.is_bs a
150496+
|| Ast_attributes.is_uncurried_app a),
150470150497
f_.pexp_desc )
150471150498
with
150472150499
| Some other_attributes, Pexp_apply (fn1, args) ->
@@ -150480,8 +150507,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150480150507
fn1.pexp_attributes;
150481150508
{
150482150509
pexp_desc =
150483-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op="|.") e.pexp_loc self fn1
150484-
((Nolabel, a) :: args);
150510+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op = "|.")
150511+
e.pexp_loc self fn1 ((Nolabel, a) :: args);
150485150512
pexp_loc = e.pexp_loc;
150486150513
pexp_attributes = e.pexp_attributes @ other_attributes;
150487150514
}
@@ -150490,7 +150517,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150490150517
Uncurried unary application *)
150491150518
{
150492150519
pexp_desc =
150493-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false e.pexp_loc self f
150520+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false
150521+
e.pexp_loc self f
150494150522
[ (Nolabel, a) ];
150495150523
pexp_loc = e.pexp_loc;
150496150524
pexp_attributes = e.pexp_attributes;
@@ -150590,14 +150618,28 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150590150618
match
150591150619
Ext_list.exclude_with_val e.pexp_attributes Ast_attributes.is_bs
150592150620
with
150593-
| None -> default_expr_mapper self e
150594150621
| Some pexp_attributes ->
150595150622
{
150596150623
e with
150597150624
pexp_desc =
150598-
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc self fn args;
150625+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc
150626+
self fn args;
150599150627
pexp_attributes;
150600-
}))
150628+
}
150629+
| None -> (
150630+
match
150631+
Ext_list.exclude_with_val e.pexp_attributes
150632+
Ast_attributes.is_uncurried_app
150633+
with
150634+
| Some pexp_attributes ->
150635+
{
150636+
e with
150637+
pexp_desc =
150638+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false
150639+
e.pexp_loc self fn args;
150640+
pexp_attributes;
150641+
}
150642+
| None -> default_expr_mapper self e)))
150601150643

150602150644
end
150603150645
module Ast_exp : sig

0 commit comments

Comments
 (0)