diff --git a/jscomp/frontend/ast_utf8_string.ml b/jscomp/frontend/ast_utf8_string.ml index bf754ad89d..8d62246efd 100644 --- a/jscomp/frontend/ast_utf8_string.ml +++ b/jscomp/frontend/ast_utf8_string.ml @@ -25,7 +25,6 @@ type error = | Invalid_code_point | Unterminated_backslash - | Invalid_escape_code of char | Invalid_hex_escape | Invalid_unicode_escape | Invalid_unicode_codepoint_escape @@ -36,7 +35,6 @@ let pp_error fmt err = match err with | Invalid_code_point -> "Invalid code point" | Unterminated_backslash -> "\\ ended unexpectedly" - | Invalid_escape_code c -> "Invalid escape code: " ^ String.make 1 c | Invalid_hex_escape -> "Invalid \\x escape" | Invalid_unicode_escape -> "Invalid \\u escape" | Invalid_unicode_codepoint_escape -> @@ -109,7 +107,11 @@ and escape_code loc buf s offset s_len = | 'x' -> Buffer.add_char buf cur_char; two_hex (loc + 1) buf s (offset + 1) s_len - | _ -> error ~loc (Invalid_escape_code cur_char) + | _ -> + (* Regular characters, like `a` in `\a`, + * are valid escape sequences *) + Buffer.add_char buf cur_char; + check_and_transform (loc + 1) buf s (offset + 1) s_len and two_hex loc buf s offset s_len = if offset + 1 >= s_len then error ~loc Invalid_hex_escape; diff --git a/jscomp/ounit_tests/ounit_unicode_tests.ml b/jscomp/ounit_tests/ounit_unicode_tests.ml index 97edf17f88..65826252e5 100644 --- a/jscomp/ounit_tests/ounit_unicode_tests.ml +++ b/jscomp/ounit_tests/ounit_unicode_tests.ml @@ -47,6 +47,9 @@ let suites = Ast_utf8_string.transform_test "\\n" =~ "\\n" end; + __LOC__ >:: begin fun _ -> + Ast_utf8_string.transform_test {|\h\e\l\lo \"world\"!|} =~ {|\h\e\l\lo \"world\"!|} + end; __LOC__ >:: begin fun _ -> Ast_utf8_string.transform_test "\\u{1d306}" =~ "\\u{1d306}" end;