Skip to content

Commit f8026a0

Browse files
committed
refactor: clarify uppercase exotic ident path
1 parent c7dedbb commit f8026a0

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

jscomp/syntax/src/res_printer.ml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ let print_longident = function
378378
| Longident.Lident txt -> Doc.text txt
379379
| lid -> Doc.join ~sep:Doc.dot (print_longident_aux [] lid)
380380

381-
type identifier_style = ExoticIdent | NormalIdent
381+
type identifier_style = UppercaseExoticIdent | ExoticIdent | NormalIdent
382382

383383
let classify_ident_content ?(allow_uident = false) ?(allow_hyphen = false) txt =
384384
if Token.is_keyword_txt txt then ExoticIdent
@@ -388,9 +388,9 @@ let classify_ident_content ?(allow_uident = false) ?(allow_hyphen = false) txt =
388388
if i == len then NormalIdent
389389
else if i == 0 then
390390
match String.unsafe_get txt i with
391+
| '\\' -> UppercaseExoticIdent
391392
| 'A' .. 'Z' when allow_uident -> loop (i + 1)
392393
| 'a' .. 'z' | '_' -> loop (i + 1)
393-
| '-' when allow_hyphen -> loop (i + 1)
394394
| _ -> ExoticIdent
395395
else
396396
match String.unsafe_get txt i with
@@ -404,7 +404,7 @@ let print_ident_like ?allow_uident ?allow_hyphen txt =
404404
let txt = Ext_ident.unwrap_uppercase_exotic txt in
405405
match classify_ident_content ?allow_uident ?allow_hyphen txt with
406406
| ExoticIdent -> Doc.concat [Doc.text "\\\""; Doc.text txt; Doc.text "\""]
407-
| NormalIdent -> Doc.text txt
407+
| UppercaseExoticIdent | NormalIdent -> Doc.text txt
408408

409409
let rec unsafe_for_all_range s ~start ~finish p =
410410
start > finish
@@ -435,8 +435,14 @@ let print_poly_var_ident txt =
435435
(* numeric poly-vars don't need quotes: #644 *)
436436
if is_valid_numeric_polyvar_number txt then Doc.text txt
437437
else
438-
let txt = Ext_ident.unwrap_uppercase_exotic txt in
439438
match classify_ident_content ~allow_uident:true txt with
439+
| UppercaseExoticIdent ->
440+
Doc.concat
441+
[
442+
Doc.text "\"";
443+
Doc.text (Ext_ident.unwrap_uppercase_exotic txt);
444+
Doc.text "\"";
445+
]
440446
| ExoticIdent -> Doc.concat [Doc.text "\""; Doc.text txt; Doc.text "\""]
441447
| NormalIdent -> (
442448
match txt with

0 commit comments

Comments
 (0)