strings.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Prevent strings from being parsed as directives
  2. // See https://github.com/prettier/prettier/pull/1560#issue-227225960
  3. 0;
  4. // Every string will be changed to double quotes, unless we end up with fewer
  5. // escaped quotes by using single quotes. (Vice versa if the "singleQuote"
  6. // option is true).
  7. //
  8. // Note that even if a string already has the correct enclosing quotes, it is
  9. // still processed in order to remove unnecessarily escaped quotes within it,
  10. // for consistency.
  11. // Simple strings.
  12. "abc"
  13. 'abc'
  14. // Escape.
  15. '\0'
  16. // Emoji.
  17. '🐶'
  18. // Empty string.
  19. ""
  20. ''
  21. // Single double quote.
  22. "\""
  23. '"'
  24. // Single single quote.
  25. "'"
  26. '\''
  27. // Unnecessary escapes.
  28. "\'"
  29. '\"'
  30. "\a"
  31. '\a'
  32. "hol\a"
  33. 'hol\a'
  34. "hol\\a (the a is not escaped)"
  35. 'hol\\a (the a is not escaped)'
  36. "multiple \a unnecessary \a escapes"
  37. 'multiple \a unnecessary \a escapes'
  38. "unnecessarily escaped character preceded by escaped backslash \\\a"
  39. 'unnecessarily escaped character preceded by escaped backslash \\\a'
  40. "unescaped character preceded by two escaped backslashes \\\\a"
  41. 'unescaped character preceded by two escaped backslashes \\\\a'
  42. "\a\a" // consecutive unnecessarily escaped characters
  43. '\a\a' // consecutive unnecessarily escaped characters
  44. 'escaped \u2030 \‰ (should not stay escaped)'
  45. // Meaningful escapes
  46. "octal escapes \0 \1 \2 \3 \4 \5 \6 \7"
  47. 'octal escapes \0 \1 \2 \3 \4 \5 \6 \7'
  48. "meaningfully escaped alphabetical characters \n \r \v \t \b \f \u2713 \x61"
  49. 'meaningfully escaped alphabetical characters \n \r \v \t \b \f \u2713 \x61'
  50. 'escaped newline \
  51. '
  52. 'escaped carriage return \
  53. '
  54. 'escaped \u2028 \
'
  55. 'escaped \u2029 \
'
  56. // One of each.
  57. "\"'"
  58. '"\''
  59. // One of each with unnecessary escapes.
  60. "\"\'"
  61. '\"\''
  62. // More double quotes than single quotes.
  63. "\"'\""
  64. '"\'"'
  65. // More single quotes than double quotes.
  66. "\"''"
  67. '"\'\''
  68. // Two of each.
  69. "\"\"''"
  70. '""\'\''
  71. // Single backslash.
  72. '\\'
  73. "\\"
  74. // Backslases.
  75. "\"\\\"\\\\\" '\'\\'\\\'\\\\'"
  76. '\'\\\'\\\\\' "\"\\"\\\"\\\\"'
  77. // Somewhat more real-word example.
  78. "He's sayin': \"How's it goin'?\" Don't ask me why."
  79. 'He\'s sayin\': "How\'s it goin\'?" Don\'t ask me why.'
  80. // Somewhat more real-word example 2.
  81. "var backslash = \"\\\", doubleQuote = '\"';"
  82. 'var backslash = "\\", doubleQuote = \'"\';'