-
Notifications
You must be signed in to change notification settings - Fork 484
Normalize ordinary string literals at the frontend #8603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
5c66d39
7ea5df8
e45efcd
558b6c1
a8794b0
a3558b3
f74e760
d712635
760c85d
f400ea7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,11 +279,16 @@ module Delim = struct | |
| | "js" -> if is_template then BackQuotes else Js | ||
| | _ -> Unrecognized | ||
|
|
||
| let escaped_j_delimiter = "*j" (* not user level syntax allowed *) | ||
| let some_escaped_back_quote_delimiter = Some "bq" | ||
| let some_escaped_j_delimiter = Some escaped_j_delimiter | ||
| end | ||
|
|
||
| (* Scanner string payloads still contain JavaScript escape spelling. Decode an | ||
| ordinary string exactly once here, before it reaches typing and matching. *) | ||
| let semantic_string loc s = | ||
| match String_literal.decode_js_escapes s with | ||
| | Some decoded -> decoded | ||
| | None -> Location.raise_errorf ~loc "Invalid string escape sequence" | ||
|
|
||
| let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression = | ||
| let is_template = | ||
| Ext_list.exists e.pexp_attributes (fun ({txt}, _) -> | ||
|
|
@@ -293,12 +298,8 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression = | |
| in | ||
| match Delim.parse_unprocessed is_template delim with | ||
| | Js -> | ||
| let js_str = Ast_utf8_string.transform e.pexp_loc s in | ||
| { | ||
| e with | ||
| pexp_desc = | ||
| Pexp_constant (Pconst_string (js_str, Delim.some_escaped_j_delimiter)); | ||
| } | ||
| let semantic = semantic_string e.pexp_loc s in | ||
| {e with pexp_desc = Pexp_constant (Pconst_string (semantic, None))} | ||
|
Comment on lines
300
to
+302
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| | BackQuotes -> | ||
| { | ||
| e with | ||
|
|
@@ -311,19 +312,18 @@ let transform_exp (e : Parsetree.expression) s delim : Parsetree.expression = | |
| let transform_pat (p : Parsetree.pattern) s delim : Parsetree.pattern = | ||
| match Delim.parse_unprocessed false delim with | ||
| | Js -> | ||
| let js_str = Ast_utf8_string.transform p.ppat_loc s in | ||
| { | ||
| p with | ||
| ppat_desc = | ||
| Ppat_constant (Pconst_string (js_str, Delim.some_escaped_j_delimiter)); | ||
| } | ||
| let semantic = semantic_string p.ppat_loc s in | ||
| {p with ppat_desc = Ppat_constant (Pconst_string (semantic, None))} | ||
| | BackQuotes -> | ||
| { | ||
| p with | ||
| ppat_desc = | ||
| Ppat_constant | ||
| (Pconst_string (s, Delim.some_escaped_back_quote_delimiter)); | ||
| } | ||
| | Unrecognized -> p | ||
| | Unrecognized when delim = "INTERNAL_RES_CHAR_CONTENTS" -> p | ||
| | Unrecognized -> | ||
| Location.raise_errorf ~loc:p.ppat_loc | ||
| "Tagged template literals are not supported in patterns" | ||
|
|
||
| let parse_processed_delim = External_arg_spec.parse_processed_delim | ||
Uh oh!
There was an error while loading. Please reload this page.