Skip to content

Commit

Permalink
fix: add additional space after the escape sequence (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Nov 27, 2019
1 parent 5e4d69d commit 8365f77
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"postcss-selector-parser": "^6.0.0"
},
"devDependencies": {
"cssesc": "^3.0.0",
"chokidar-cli": "^1.0.1",
"codecov.io": "^0.1.2",
"coveralls": "^3.0.2",
Expand Down
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
// non-container node
selector.first.spaces = node.spaces;

const nextNode = node.next();

if (
nextNode &&
nextNode.type === 'combinator' &&
nextNode.value === ' ' &&
/\\[A-F0-9]{1,6}$/.test(selector.last.value)
) {
selector.last.spaces.after = ' ';
}

node.replaceWith(selector);

return;
Expand Down
80 changes: 80 additions & 0 deletions test/test-cases/escape-sequence/expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
.\1F600 {
color: red;
}

.\1F600 .\1F600 {
color: red;
}

.\1F600 .\1F600 .\1F600 {
color: red;
}

.\1F600 A {
color: red;
}

.\1F600 .\1F600 {
color: red;
}

.\1F600 .\1F600 {
color: red;
}

.\1F600 .\1F600 .\1F600 {
color: red;
}

.\1F600 .\1F600 A .\1F600 {
color: red;
}

#\1F600 #\1F600 #\1F600 {
color: red;
}

#\1F600 #\1F600 A #\1F600 {
color: red;
}

.a .\1F600 b {
color: red;
}

.\1F600 > .\1F600 > .\1F600 {
color: red;
}

.\1F600 .\1F600 {
color: red;
}

.\1F600.\1F600 {
color: red;
}

.\1F600 .\1F600 {
color: red;
}

.\1F600 .a {
color: red;
}

.\1F600.a {
color: red;
}

.a .\1F600 {
color: red;
}

.a.\1F600 {
color: red;
}

:export {
smile: 😀;
smile_with_A: 😀A;
}
21 changes: 21 additions & 0 deletions test/test-cases/escape-sequence/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const cssesc = require('cssesc');

const filenameReservedRegex = /[<>:"/\\|?*\x00-\x1F]/g;
const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
const reRelativePath = /^\.+/;

module.exports = {
generateScopedName: function(name) {
return cssesc(
name
.replace(/smile/, '😀')
.replace(/_with_A/g, 'A')
.replace(/^((-?[0-9])|--)/, '_$1')
.replace(filenameReservedRegex, '-')
.replace(reControlChars, '-')
.replace(reRelativePath, '-')
.replace(/\./g, '-'),
{ isIdentifier: true }
);
},
};
75 changes: 75 additions & 0 deletions test/test-cases/escape-sequence/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
:local(.smile) {
color: red;
}

:local(.smile) :local(.smile) {
color: red;
}

:local(.smile) :local(.smile) :local(.smile) {
color: red;
}

:local(.smile_with_A) {
color: red;
}

.\1F600 :local(.smile) {
color: red;
}

:local(.smile) .\1F600 {
color: red;
}

.\1F600 :local(.smile) .\1F600 {
color: red;
}

.\1F600 :local(.smile_with_A) .\1F600 {
color: red;
}

#\1F600 :local(#smile) #\1F600 {
color: red;
}

#\1F600 :local(#smile_with_A) #\1F600 {
color: red;
}

.a :local(.smile) b {
color: red;
}

:local(.smile) > :local(.smile) > :local(.smile) {
color: red;
}

.\1F600 :local(.smile) {
color: red;
}

.\1F600:local(.smile) {
color: red;
}

.\1F600 :local(.smile) {
color: red;
}

:local(.smile) .a {
color: red;
}

:local(.smile).a {
color: red;
}

.a :local(.smile) {
color: red;
}

.a:local(.smile) {
color: red;
}

0 comments on commit 8365f77

Please sign in to comment.