feat: remove spaces after \HEX escapes that are not followed by a hex digit

This commit is contained in:
karishmas6
2024-06-06 01:26:33 +05:30
parent 358efd6dea
commit e7a3d146df

View File

@@ -537,6 +537,23 @@ export const getSelectors = async (page: Page, coordinates: Coordinates) => {
output = '\\3' + firstChar + ' ' + output.slice(1);
}
}
// Remove spaces after `\HEX` escapes that are not followed by a hex digit,
// since theyre redundant. Note that this is only possible if the escape
// sequence isnt preceded by an odd number of backslashes.
output = output.replace(regexExcessiveSpaces, function ($0, $1, $2) {
if ($1 && $1.length % 2) {
// Its not safe to remove the space, so dont.
return $0;
}
// Strip the space.
return ($1 || '') + $2;
});
if (!isIdentifier && options.wrap) {
return quote + output + quote;
}
return output;
}