From 8d454f3d2851fd2491f294676716cecf1b2071f9 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 31 May 2022 21:05:22 +0200 Subject: [PATCH] Adapt @as ppx to new string literals. String literals are now represented as `{j*|xxx|j*}`. Chang the `@as` ppx accordingly. --- jscomp/frontend/ast_attributes.ml | 9 +++++---- lib/4.06.1/unstable/js_compiler.ml | 9 +++++---- lib/4.06.1/whole_compiler.ml | 9 +++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/jscomp/frontend/ast_attributes.ml b/jscomp/frontend/ast_attributes.ml index a66403a3eb..7e21a91534 100644 --- a/jscomp/frontend/ast_attributes.ml +++ b/jscomp/frontend/ast_attributes.ml @@ -292,15 +292,16 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) = pexp_desc = Pexp_constant (Pconst_string - (s, ((None | Some "json") as dec))); + (s, ((None | Some "json"| Some "*j") as dec))); pexp_loc; _; }, _ ); _; }; - ] -> - if dec = None then st := Some (Str s) + ] + -> + if dec = None || dec = Some "*j" then st := Some (Str s) else ( (match Classify_function.classify @@ -313,7 +314,7 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) = Location.raise_errorf ~loc:pexp_loc "an object literal expected"); st := Some (Js_literal_str s)) - | _ -> Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal + | _ -> Bs_syntaxerr.err loc (Expect_int_or_string_or_json_literal) ) | Some v -> st := Some (Int v)) else Bs_syntaxerr.err loc Duplicated_bs_as diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 8066f7a449..fdbd83c89f 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -254524,15 +254524,16 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) = pexp_desc = Pexp_constant (Pconst_string - (s, ((None | Some "json") as dec))); + (s, ((None | Some "json"| Some "*j") as dec))); pexp_loc; _; }, _ ); _; }; - ] -> - if dec = None then st := Some (Str s) + ] + -> + if dec = None || dec = Some "*j" then st := Some (Str s) else ( (match Classify_function.classify @@ -254545,7 +254546,7 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) = Location.raise_errorf ~loc:pexp_loc "an object literal expected"); st := Some (Js_literal_str s)) - | _ -> Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal + | _ -> Bs_syntaxerr.err loc (Expect_int_or_string_or_json_literal) ) | Some v -> st := Some (Int v)) else Bs_syntaxerr.err loc Duplicated_bs_as diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index d3e24ece82..c3f15e1579 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -258595,15 +258595,16 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) = pexp_desc = Pexp_constant (Pconst_string - (s, ((None | Some "json") as dec))); + (s, ((None | Some "json"| Some "*j") as dec))); pexp_loc; _; }, _ ); _; }; - ] -> - if dec = None then st := Some (Str s) + ] + -> + if dec = None || dec = Some "*j" then st := Some (Str s) else ( (match Classify_function.classify @@ -258616,7 +258617,7 @@ let iter_process_bs_string_or_int_as (attrs : Parsetree.attributes) = Location.raise_errorf ~loc:pexp_loc "an object literal expected"); st := Some (Js_literal_str s)) - | _ -> Bs_syntaxerr.err loc Expect_int_or_string_or_json_literal + | _ -> Bs_syntaxerr.err loc (Expect_int_or_string_or_json_literal) ) | Some v -> st := Some (Int v)) else Bs_syntaxerr.err loc Duplicated_bs_as