@@ -51,6 +51,28 @@ function getSingleLocalNamesForComposes(root) {
5151 } ) ;
5252}
5353
54+ const whitespace = '[\\x20\\t\\r\\n\\f]' ;
55+ const unescapeRegExp = new RegExp (
56+ '\\\\([\\da-f]{1,6}' + whitespace + '?|(' + whitespace + ')|.)' ,
57+ 'ig'
58+ ) ;
59+
60+ function unescape ( str ) {
61+ return str . replace ( unescapeRegExp , ( _ , escaped , escapedWhitespace ) => {
62+ const high = '0x' + escaped - 0x10000 ;
63+
64+ // NaN means non-codepoint
65+ // Workaround erroneous numeric interpretation of +"0x"
66+ return high !== high || escapedWhitespace
67+ ? escaped
68+ : high < 0
69+ ? // BMP codepoint
70+ String . fromCharCode ( high + 0x10000 )
71+ : // Supplemental Plane codepoint (surrogate pair)
72+ String . fromCharCode ( ( high >> 10 ) | 0xd800 , ( high & 0x3ff ) | 0xdc00 ) ;
73+ } ) ;
74+ }
75+
5476const processor = postcss . plugin ( 'postcss-modules-scope' , function ( options ) {
5577 return css => {
5678 const generateScopedName =
@@ -64,10 +86,15 @@ const processor = postcss.plugin('postcss-modules-scope', function(options) {
6486 css . source . input . from ,
6587 css . source . input . css
6688 ) ;
89+
6790 exports [ name ] = exports [ name ] || [ ] ;
68- if ( exports [ name ] . indexOf ( scopedName ) < 0 ) {
69- exports [ name ] . push ( scopedName ) ;
91+
92+ const unescapedScopedName = unescape ( scopedName ) ;
93+
94+ if ( exports [ name ] . indexOf ( unescapedScopedName ) < 0 ) {
95+ exports [ name ] . push ( unescapedScopedName ) ;
7096 }
97+
7198 return scopedName ;
7299 }
73100
0 commit comments