Skip to content

Commit 1ba6e95

Browse files
fix: Single quotes not changed to double quotes (#1254) (#1582)
1 parent 934b4fd commit 1ba6e95

60 files changed

Lines changed: 2273 additions & 2147 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/util.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -580,24 +580,24 @@ function getNodeKindIncludingLogical(node) {
580580
}
581581

582582
/**
583-
* Check if string can safely be converted from double to single quotes, i.e.
583+
* Check if string can safely be converted from double to single quotes and vice-versa, i.e.
584584
*
585585
* - no embedded variables ("foo $bar")
586586
* - no linebreaks
587587
* - no special characters like \n, \t, ...
588588
* - no octal/hex/unicode characters
589589
*
590-
* See http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double
590+
* See https://php.net/manual/en/language.types.string.php#language.types.string.syntax.double
591591
*/
592592
function useDoubleQuote(node, options) {
593-
if (node.isDoubleQuote && options.singleQuote) {
593+
if (node.isDoubleQuote === options.singleQuote) {
594+
// We have a double quote and the user passed singleQuote:true, or the other way around.
594595
const rawValue = node.raw.slice(node.raw[0] === "b" ? 2 : 1, -1);
595-
596-
return rawValue.match(
597-
/\\([$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u{([0-9a-fA-F]+)})|\r?\n|'|"/
596+
const isComplex = rawValue.match(
597+
/\\([$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u{([0-9a-fA-F]+)})|\r?\n|'|"|\$/
598598
);
599+
return node.isDoubleQuote ? isComplex : !isComplex;
599600
}
600-
601601
return node.isDoubleQuote;
602602
}
603603

0 commit comments

Comments
 (0)