Skip to content

Commit 92ba998

Browse files
committed
simplify x##property#= 3 into x#property#= 3
1 parent c4468b4 commit 92ba998

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

jscomp/frontend/ast_exp_apply.ml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,32 @@ let app_exp_mapper
202202
]}
203203
*)
204204
| Some {op = "#="; loc; args = [obj; arg]} ->
205-
begin match view_as_app obj ["##"] with
206-
| Some { args = [obj; {
207-
pexp_desc =
208-
Pexp_ident {txt = Lident name}
205+
let gen_assignment obj name name_loc =
206+
sane_property_name_check name_loc name;
207+
Exp.constraint_ ~loc
208+
{ e with
209+
pexp_desc =
210+
Ast_uncurry_apply.method_apply loc self obj
211+
(name ^ Literals.setter_suffix) [Nolabel,arg] }
212+
(Ast_literal.type_unit ~loc ()) in
213+
begin match obj.pexp_desc with
214+
| Pexp_send (obj , {txt = name; loc = name_loc})
215+
-> gen_assignment obj name name_loc
216+
| _ ->
217+
match view_as_app obj ["##"] with
218+
| Some { args = [obj; {
219+
pexp_desc =
220+
Pexp_ident {txt = Lident name}
209221
| Pexp_constant (
210-
Pconst_string
211-
(name, None)); pexp_loc
212-
}
213-
]
214-
}
215-
->
216-
sane_property_name_check pexp_loc name;
217-
Exp.constraint_ ~loc
218-
{ e with
219-
pexp_desc =
220-
Ast_uncurry_apply.method_apply loc self obj
221-
(name ^ Literals.setter_suffix) [Nolabel,arg] }
222-
(Ast_literal.type_unit ~loc ())
223-
| _ -> assert false
222+
Pconst_string
223+
(name, None)); pexp_loc = name_loc
224+
}
225+
]
226+
}
227+
->
228+
gen_assignment obj name name_loc
229+
| _ ->
230+
Location.raise_errorf ~loc "invalid #= assignment"
224231
end
225232
| Some { op = "|."; loc; } ->
226233
Location.raise_errorf ~loc

jscomp/test/hash_sugar_desugar.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ function h4(u) {
1919
return u.hi(1, 2);
2020
}
2121

22+
function g5(u) {
23+
u.hi = 3;
24+
25+
}
26+
2227
function h5(u) {
2328
u.hi = 3;
2429

@@ -45,6 +50,7 @@ exports.h1 = h1;
4550
exports.h2 = h2;
4651
exports.h3 = h3;
4752
exports.h4 = h4;
53+
exports.g5 = g5;
4854
exports.h5 = h5;
4955
exports.h6 = h6;
5056
exports.h7 = h7;

jscomp/test/hash_sugar_desugar.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ let h3 u =
2929
u ["hi"] (1, 2)
3030
*)
3131

32+
let g5 u =
33+
u#hi #= 3
3234
let h5 u =
3335
u ##hi #= 3
3436
(* assignment

jscomp/test/hash_sugar_desugar.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ val h1 : < p : 'a; .. > -> 'a
44
val h2 : < m : (int -> int -> 'a [@bs]); .. > -> 'a
55
val h3 : < hi : int -> int -> 'a; .. > -> 'a
66
val h4 : < hi : (int -> int -> 'a [@bs.meth]); .. > -> 'a
7-
7+
val g5 : < hi : int [@bs.set]; .. > -> unit
88
val h5 : < hi : int [@bs.set]; .. > -> unit
99
(* The inferred type is
1010
val h5 : < hi#= : (int -> unit [@bs.meth]); .. > -> unit

0 commit comments

Comments
 (0)