File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,11 +88,6 @@ let has_template_attr attrs =
8888let remove_template_attr attrs =
8989 List. filter (fun ({Location. txt} , _ ) -> txt <> " res.template" ) attrs
9090
91- let decode_js_string ~loc s =
92- match String_literal. decode_js_escapes s with
93- | Some s -> s
94- | None -> Location. raise_errorf ~loc " Invalid string escape sequence"
95-
9691let normalize_ppx_semantic_string semantic =
9792 let length = String. length semantic in
9893 let buffer = Buffer. create length in
Original file line number Diff line number Diff line change @@ -240,14 +240,6 @@ let template_from_source source : template_segment option =
240240let template_from_semantic semantic : template_segment =
241241 Valid {source = encode_js_template semantic; semantic}
242242
243- let string_as_template (literal : string_literal) : template_segment =
244- match literal with
245- | Valid {source; semantic} -> (
246- match decode_js_template_escapes source with
247- | Some decoded when decoded = semantic -> Valid {source; semantic}
248- | _ -> template_from_semantic semantic)
249- | Invalid_source _ -> template_from_semantic " "
250-
251243let concat_template segments =
252244 let source = String.concat " " (List.map source segments) in
253245 let semantic = String.concat " " (List.map semantic segments) in
Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ type template_kind
33type 'kind payload
44
55type string_literal = string_kind payload
6- (* * A validated ordinary JavaScript string body and its semantic value. *)
6+ (* * An ordinary JavaScript string body and its semantic value. Parser error
7+ recovery may retain an invalid source spelling with an empty placeholder
8+ semantic value. *)
79
810type template_segment = template_kind payload
911(* * A validated JavaScript template segment and its semantic value. *)
@@ -52,10 +54,6 @@ val template_from_source : string -> template_segment option
5254val template_from_semantic : string -> template_segment
5355(* * Construct a template segment with canonical source spelling. *)
5456
55- val string_as_template : string_literal -> template_segment
56- (* * Convert an ordinary string payload to a template segment, preserving its
57- source spelling when that spelling has the same template semantics. *)
58-
5957val concat_template : template_segment list -> template_segment
6058(* * Concatenate template segments, preserving their combined source spelling
6159 when it still decodes to the combined semantic value and otherwise using a
Original file line number Diff line number Diff line change @@ -407,19 +407,6 @@ let suites =
407407 ( " template segments reject interpolation openers " >:: fun _ ->
408408 assert_invalid_template " ${value} ";
409409 assert_template_decoded ~encoded:" \\${value} " ~expected:" ${value} " );
410- ( " ordinary strings convert safely to template segments " >:: fun _ ->
411- let preserved =
412- String_literal.string_from_source {|\x61 |}
413- |> Option.get |> String_literal.string_as_template
414- in
415- OUnit.assert_equal ~printer:(Printf.sprintf " %S") {|\x61 |}
416- (String_literal.source preserved);
417- let escaped_interpolation =
418- String_literal.string_from_source " ${value} "
419- |> Option.get |> String_literal.string_as_template
420- in
421- OUnit.assert_equal ~printer:(Printf.sprintf " %S") " \\${value} "
422- (String_literal.source escaped_interpolation) );
423410 ( " ordinary literals become semantic strings " >:: fun _ ->
424411 assert_parsed_string ~source:{|\x61\n \uD83D\uDE00|}
425412 ~expected_semantic:" a \n 😀" );
You can’t perform that action at this time.
0 commit comments