Skip to content

Commit ab97819

Browse files
committed
refactor: clarify uppercase exotic ident path
1 parent 08c6345 commit ab97819

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
@@ -376,7 +376,7 @@ let printLongident = function
376376
| Longident.Lident txt -> Doc.text txt
377377
| lid -> Doc.join ~sep:Doc.dot (printLongidentAux [] lid)
378378

379-
type identifierStyle = ExoticIdent | NormalIdent
379+
type identifierStyle = UppercaseExoticIdent | ExoticIdent | NormalIdent
380380

381381
let classifyIdentContent ?(allowUident = false) ?(allowHyphen = false) txt =
382382
if Token.isKeywordTxt txt then ExoticIdent
@@ -386,9 +386,9 @@ let classifyIdentContent ?(allowUident = false) ?(allowHyphen = false) txt =
386386
if i == len then NormalIdent
387387
else if i == 0 then
388388
match String.unsafe_get txt i with
389+
| '\\' -> UppercaseExoticIdent
389390
| 'A' .. 'Z' when allowUident -> loop (i + 1)
390391
| 'a' .. 'z' | '_' -> loop (i + 1)
391-
| '-' when allowHyphen -> loop (i + 1)
392392
| _ -> ExoticIdent
393393
else
394394
match String.unsafe_get txt i with
@@ -402,7 +402,7 @@ let printIdentLike ?allowUident ?allowHyphen txt =
402402
let txt = Ext_ident.unwrap_uppercase_exotic txt in
403403
match classifyIdentContent ?allowUident ?allowHyphen txt with
404404
| ExoticIdent -> Doc.concat [Doc.text "\\\""; Doc.text txt; Doc.text "\""]
405-
| NormalIdent -> Doc.text txt
405+
| UppercaseExoticIdent | NormalIdent -> Doc.text txt
406406

407407
let rec unsafe_for_all_range s ~start ~finish p =
408408
start > finish
@@ -433,8 +433,14 @@ let printPolyVarIdent txt =
433433
(* numeric poly-vars don't need quotes: #644 *)
434434
if isValidNumericPolyvarNumber txt then Doc.text txt
435435
else
436-
let txt = Ext_ident.unwrap_uppercase_exotic txt in
437436
match classifyIdentContent ~allowUident:true txt with
437+
| UppercaseExoticIdent ->
438+
Doc.concat
439+
[
440+
Doc.text "\"";
441+
Doc.text (Ext_ident.unwrap_uppercase_exotic txt);
442+
Doc.text "\"";
443+
]
438444
| ExoticIdent -> Doc.concat [Doc.text "\""; Doc.text txt; Doc.text "\""]
439445
| NormalIdent -> (
440446
match txt with

0 commit comments

Comments
 (0)