@@ -376,11 +376,10 @@ let printLongident = function
376376 | Longident. Lident txt -> Doc. text txt
377377 | lid -> Doc. join ~sep: Doc. dot (printLongidentAux [] lid)
378378
379- type identifierStyle = ExoticLike | NormalIdent
379+ type polyVarIdentifierStyle = ExoticLike | NormalIdent
380380
381- let classifyIdentContent txt =
382- if Ext_ident. is_exotic txt then ExoticLike
383- else if Token. isKeywordTxt txt then ExoticLike
381+ let classifyPolyVarIdentContent txt =
382+ if Token. isKeywordTxt txt then ExoticLike
384383 else
385384 let len = String. length txt in
386385 let rec loop i =
@@ -406,7 +405,7 @@ let for_all_from s start p =
406405 unsafe_for_all_range s ~start ~finish: (len - 1 ) p
407406
408407(* See https://github.com/rescript-lang/rescript-compiler/blob/726cfa534314b586e5b5734471bc2023ad99ebd9/jscomp/ext/ext_string.ml#L510 *)
409- let isValidNumericPolyvarNumber (x : string ) =
408+ let isValidNumericPolyVarNumber (x : string ) =
410409 let len = String. length x in
411410 len > 0
412411 &&
@@ -423,12 +422,10 @@ let isValidNumericPolyvarNumber (x : string) =
423422(* Exotic identifiers in poly-vars have a "lighter" syntax: #"ease-in" *)
424423let printPolyVarIdent txt =
425424 (* numeric poly-vars don't need quotes: #644 *)
426- if isValidNumericPolyvarNumber txt then Doc. text txt
425+ if isValidNumericPolyVarNumber txt then Doc. text txt
427426 else
428- match classifyIdentContent txt with
429- | ExoticLike ->
430- Doc. concat
431- [Doc. text " \" " ; Doc. text (Ext_ident. unwrap_exotic txt); Doc. text " \" " ]
427+ match classifyPolyVarIdentContent txt with
428+ | ExoticLike -> Doc. text (" \" " ^ Ext_ident. unwrap_exotic txt ^ " \" " )
432429 | NormalIdent -> (
433430 match txt with
434431 | "" -> Doc. concat [Doc. text " \" " ; Doc. text txt; Doc. text " \" " ]
@@ -438,6 +435,10 @@ let polyVarIdentToString polyVarIdent =
438435 Doc. concat [Doc. text " #" ; printPolyVarIdent polyVarIdent]
439436 |> Doc. toString ~width: 80
440437
438+ let printIdentPossiblyInfixOperator txt =
439+ if Res_token. isInfixOperatorTxt txt then Doc. text (Ext_ident. wrap_exotic txt)
440+ else Doc. text txt
441+
441442let printLident l =
442443 let flatLidOpt lid =
443444 let rec flat accu = function
@@ -448,14 +449,16 @@ let printLident l =
448449 flat [] lid
449450 in
450451 match l with
451- | Longident. Lident txt -> Doc. text txt
452+ | Longident. Lident txt -> printIdentPossiblyInfixOperator txt
452453 | Longident. Ldot (path , txt ) ->
453454 let doc =
454455 match flatLidOpt path with
455456 | Some txts ->
456457 Doc. concat
457458 [
458- Doc. join ~sep: Doc. dot (List. map Doc. text txts); Doc. dot; Doc. text txt;
459+ Doc. join ~sep: Doc. dot (List. map Doc. text txts);
460+ Doc. dot;
461+ printIdentPossiblyInfixOperator txt;
459462 ]
460463 | None -> Doc. text " printLident: Longident.Lapply is not supported"
461464 in
@@ -1053,7 +1056,7 @@ and printValueDescription ~state valueDescription cmtTbl =
10531056 attrs;
10541057 Doc. text header;
10551058 printComments
1056- (Doc. text valueDescription.pval_name.txt)
1059+ (printIdentPossiblyInfixOperator valueDescription.pval_name.txt)
10571060 cmtTbl valueDescription.pval_name.loc;
10581061 Doc. text " : " ;
10591062 printTypExpr ~state valueDescription.pval_type cmtTbl;
@@ -2119,7 +2122,7 @@ and printPattern ~state (p : Parsetree.pattern) cmtTbl =
21192122 let patternWithoutAttributes =
21202123 match p.ppat_desc with
21212124 | Ppat_any -> Doc. text " _"
2122- | Ppat_var var -> Doc. text var.txt
2125+ | Ppat_var var -> printIdentPossiblyInfixOperator var.txt
21232126 | Ppat_constant c ->
21242127 let templateLiteral =
21252128 ParsetreeViewer. hasTemplateLiteralAttr p.ppat_attributes
@@ -4421,16 +4424,15 @@ and printJsxProp ~state arg cmtTbl =
44214424 * Navabar.createElement -> Navbar
44224425 * Staff.Users.createElement -> Staff.Users *)
44234426and printJsxName {txt = lident } =
4424- let printIdent = Doc. text in
44254427 let rec flatten acc lident =
44264428 match lident with
4427- | Longident. Lident txt -> printIdent txt :: acc
4429+ | Longident. Lident txt -> Doc. text txt :: acc
44284430 | Ldot (lident , "createElement" ) -> flatten acc lident
4429- | Ldot (lident , txt ) -> flatten (printIdent txt :: acc) lident
4431+ | Ldot (lident , txt ) -> flatten (Doc. text txt :: acc) lident
44304432 | _ -> acc
44314433 in
44324434 match lident with
4433- | Longident. Lident txt -> printIdent txt
4435+ | Longident. Lident txt -> Doc. text txt
44344436 | _ as lident ->
44354437 let segments = flatten [] lident in
44364438 Doc. join ~sep: Doc. dot segments
@@ -4987,7 +4989,7 @@ and printExpFunParameter ~state parameter cmtTbl =
49874989 [
49884990 printAttributes ~state ppat_attributes cmtTbl;
49894991 Doc. text " ~" ;
4990- Doc. text lbl;
4992+ printIdentPossiblyInfixOperator lbl;
49914993 ]
49924994 | ( (Asttypes. Labelled lbl | Optional lbl),
49934995 {
@@ -5000,7 +5002,7 @@ and printExpFunParameter ~state parameter cmtTbl =
50005002 [
50015003 printAttributes ~state ppat_attributes cmtTbl;
50025004 Doc. text " ~" ;
5003- Doc. text lbl;
5005+ printIdentPossiblyInfixOperator lbl;
50045006 Doc. text " : " ;
50055007 printTypExpr ~state typ cmtTbl;
50065008 ]
@@ -5009,7 +5011,7 @@ and printExpFunParameter ~state parameter cmtTbl =
50095011 Doc. concat
50105012 [
50115013 Doc. text " ~" ;
5012- Doc. text lbl;
5014+ printIdentPossiblyInfixOperator lbl;
50135015 Doc. text " as " ;
50145016 printPattern ~state pattern cmtTbl;
50155017 ]
0 commit comments