Skip to content

Commit b6dbd79

Browse files
committed
decode property name earlier
1 parent 39903eb commit b6dbd79

File tree

5 files changed

+237
-225
lines changed

5 files changed

+237
-225
lines changed

jscomp/core/lam_compile.ml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,14 +1432,14 @@ and compile_prim (prim_info : Lam.prim_info) (lambda_cxt : Lam_compile_context.t
14321432
we need mark something that such eta-conversion can not be simplified in some cases
14331433
*)
14341434

1435-
| {primitive = Pjs_unsafe_downgrade {name;loc}; args = [obj]}
1435+
| {primitive = Pjs_unsafe_downgrade {name = property;loc; setter }; args = [obj]}
14361436

14371437
->
14381438
(**
14391439
either a getter {[ x #. height ]} or {[ x ## method_call ]}
14401440
*)
1441-
assert (not (Ext_string.ends_with name Literals.setter_suffix));
1442-
let property = Lam_methname.translate ~loc name in
1441+
assert (not setter);
1442+
14431443
(match compile_lambda {lambda_cxt with continuation = NeedValue Not_tail} obj
14441444
with
14451445
| {value = None} -> assert false
@@ -1464,15 +1464,11 @@ and compile_prim (prim_info : Lam.prim_info) (lambda_cxt : Lam_compile_context.t
14641464
(match args_lambda with
14651465
| [Lprim{
14661466
primitive =
1467-
Pjs_unsafe_downgrade {name = method_name; loc; setter = true};
1467+
Pjs_unsafe_downgrade {name = property; loc; setter = true};
14681468
args = args_l} ;
14691469
arg] (** x##name arg could be specialized as a setter *)
14701470
->
1471-
let obj = Ext_list.singleton_exn args_l in
1472-
let property =
1473-
Lam_methname.translate ~loc
1474-
(String.sub method_name 0
1475-
(String.length method_name - Literals.setter_suffix_len)) in
1471+
let obj = Ext_list.singleton_exn args_l in
14761472
let need_value_no_return_cxt = {lambda_cxt with continuation = NeedValue Not_tail} in
14771473
let obj_output = compile_lambda need_value_no_return_cxt obj in
14781474
let arg_output = compile_lambda need_value_no_return_cxt arg in

jscomp/core/lam_convert.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,14 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
638638
->
639639
begin match kind, ls with
640640
| Public (Some name), [] ->
641-
prim ~primitive:(Pjs_unsafe_downgrade {name;loc; setter = Ext_string.ends_with name Literals.setter_suffix})
641+
let setter = Ext_string.ends_with name Literals.setter_suffix in
642+
let property =
643+
if setter then
644+
Lam_methname.translate ~loc
645+
(String.sub name 0
646+
(String.length name - Literals.setter_suffix_len))
647+
else Lam_methname.translate ~loc name in
648+
prim ~primitive:(Pjs_unsafe_downgrade {name = property;loc; setter})
642649
~args loc
643650
| _ -> assert false
644651
end

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125272,14 +125272,14 @@ and compile_prim (prim_info : Lam.prim_info) (lambda_cxt : Lam_compile_context.t
125272125272
we need mark something that such eta-conversion can not be simplified in some cases
125273125273
*)
125274125274

125275-
| {primitive = Pjs_unsafe_downgrade {name;loc}; args = [obj]}
125275+
| {primitive = Pjs_unsafe_downgrade {name = property;loc; setter }; args = [obj]}
125276125276

125277125277
->
125278125278
(**
125279125279
either a getter {[ x #. height ]} or {[ x ## method_call ]}
125280125280
*)
125281-
assert (not (Ext_string.ends_with name Literals.setter_suffix));
125282-
let property = Lam_methname.translate ~loc name in
125281+
assert (not setter);
125282+
125283125283
(match compile_lambda {lambda_cxt with continuation = NeedValue Not_tail} obj
125284125284
with
125285125285
| {value = None} -> assert false
@@ -125304,15 +125304,11 @@ and compile_prim (prim_info : Lam.prim_info) (lambda_cxt : Lam_compile_context.t
125304125304
(match args_lambda with
125305125305
| [Lprim{
125306125306
primitive =
125307-
Pjs_unsafe_downgrade {name = method_name; loc; setter = true};
125307+
Pjs_unsafe_downgrade {name = property; loc; setter = true};
125308125308
args = args_l} ;
125309125309
arg] (** x##name arg could be specialized as a setter *)
125310125310
->
125311-
let obj = Ext_list.singleton_exn args_l in
125312-
let property =
125313-
Lam_methname.translate ~loc
125314-
(String.sub method_name 0
125315-
(String.length method_name - Literals.setter_suffix_len)) in
125311+
let obj = Ext_list.singleton_exn args_l in
125316125312
let need_value_no_return_cxt = {lambda_cxt with continuation = NeedValue Not_tail} in
125317125313
let obj_output = compile_lambda need_value_no_return_cxt obj in
125318125314
let arg_output = compile_lambda need_value_no_return_cxt arg in
@@ -126474,7 +126470,14 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
126474126470
->
126475126471
begin match kind, ls with
126476126472
| Public (Some name), [] ->
126477-
prim ~primitive:(Pjs_unsafe_downgrade {name;loc; setter = Ext_string.ends_with name Literals.setter_suffix})
126473+
let setter = Ext_string.ends_with name Literals.setter_suffix in
126474+
let property =
126475+
if setter then
126476+
Lam_methname.translate ~loc
126477+
(String.sub name 0
126478+
(String.length name - Literals.setter_suffix_len))
126479+
else Lam_methname.translate ~loc name in
126480+
prim ~primitive:(Pjs_unsafe_downgrade {name = property;loc; setter})
126478126481
~args loc
126479126482
| _ -> assert false
126480126483
end

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125272,14 +125272,14 @@ and compile_prim (prim_info : Lam.prim_info) (lambda_cxt : Lam_compile_context.t
125272125272
we need mark something that such eta-conversion can not be simplified in some cases
125273125273
*)
125274125274

125275-
| {primitive = Pjs_unsafe_downgrade {name;loc}; args = [obj]}
125275+
| {primitive = Pjs_unsafe_downgrade {name = property;loc; setter }; args = [obj]}
125276125276

125277125277
->
125278125278
(**
125279125279
either a getter {[ x #. height ]} or {[ x ## method_call ]}
125280125280
*)
125281-
assert (not (Ext_string.ends_with name Literals.setter_suffix));
125282-
let property = Lam_methname.translate ~loc name in
125281+
assert (not setter);
125282+
125283125283
(match compile_lambda {lambda_cxt with continuation = NeedValue Not_tail} obj
125284125284
with
125285125285
| {value = None} -> assert false
@@ -125304,15 +125304,11 @@ and compile_prim (prim_info : Lam.prim_info) (lambda_cxt : Lam_compile_context.t
125304125304
(match args_lambda with
125305125305
| [Lprim{
125306125306
primitive =
125307-
Pjs_unsafe_downgrade {name = method_name; loc; setter = true};
125307+
Pjs_unsafe_downgrade {name = property; loc; setter = true};
125308125308
args = args_l} ;
125309125309
arg] (** x##name arg could be specialized as a setter *)
125310125310
->
125311-
let obj = Ext_list.singleton_exn args_l in
125312-
let property =
125313-
Lam_methname.translate ~loc
125314-
(String.sub method_name 0
125315-
(String.length method_name - Literals.setter_suffix_len)) in
125311+
let obj = Ext_list.singleton_exn args_l in
125316125312
let need_value_no_return_cxt = {lambda_cxt with continuation = NeedValue Not_tail} in
125317125313
let obj_output = compile_lambda need_value_no_return_cxt obj in
125318125314
let arg_output = compile_lambda need_value_no_return_cxt arg in
@@ -126474,7 +126470,14 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
126474126470
->
126475126471
begin match kind, ls with
126476126472
| Public (Some name), [] ->
126477-
prim ~primitive:(Pjs_unsafe_downgrade {name;loc; setter = Ext_string.ends_with name Literals.setter_suffix})
126473+
let setter = Ext_string.ends_with name Literals.setter_suffix in
126474+
let property =
126475+
if setter then
126476+
Lam_methname.translate ~loc
126477+
(String.sub name 0
126478+
(String.length name - Literals.setter_suffix_len))
126479+
else Lam_methname.translate ~loc name in
126480+
prim ~primitive:(Pjs_unsafe_downgrade {name = property;loc; setter})
126478126481
~args loc
126479126482
| _ -> assert false
126480126483
end

0 commit comments

Comments
 (0)