Skip to content

Commit 697cd1f

Browse files
chore: update postcss-selector-parser (#12)
1 parent 8ab7051 commit 697cd1f

File tree

4 files changed

+385
-391
lines changed

4 files changed

+385
-391
lines changed

index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@ function localizeNode(rule, mode, options) {
4141
switch (node.type) {
4242
case 'root': {
4343
let resultingGlobal;
44+
4445
context.hasPureGlobals = false;
46+
4547
newNodes = node.nodes.map(function(n) {
4648
const nContext = {
4749
global: context.global,
4850
lastWasSpacing: true,
4951
hasLocals: false,
5052
explicit: false,
5153
};
54+
5255
n = transform(n, nContext);
56+
5357
if (typeof resultingGlobal === 'undefined') {
5458
resultingGlobal = nContext.global;
5559
} else if (resultingGlobal !== nContext.global) {
@@ -59,11 +63,14 @@ function localizeNode(rule, mode, options) {
5963
'" (multiple selectors must result in the same mode for the rule)'
6064
);
6165
}
66+
6267
if (!nContext.hasLocals) {
6368
context.hasPureGlobals = true;
6469
}
70+
6571
return n;
6672
});
73+
6774
context.global = resultingGlobal;
6875

6976
node.nodes = normalizeNodeArray(newNodes);
@@ -160,7 +167,6 @@ function localizeNode(rule, mode, options) {
160167
);
161168
}
162169

163-
const next = node.parent;
164170
const addBackSpacing = !!node.spaces.before;
165171

166172
context.ignoreNextSpacing = context.lastWasSpacing
@@ -205,6 +211,7 @@ function localizeNode(rule, mode, options) {
205211
context.lastWasSpacing = false;
206212
context.ignoreNextSpacing = false;
207213
context.enforceNoSpacing = false;
214+
208215
return node;
209216
};
210217

@@ -213,11 +220,10 @@ function localizeNode(rule, mode, options) {
213220
hasPureGlobals: false,
214221
};
215222

216-
const selector = selectorParser(root => {
223+
rootContext.selector = selectorParser(root => {
217224
transform(root, rootContext);
218225
}).processSync(rule, { updateSelector: false, lossless: true });
219226

220-
rootContext.selector = selector;
221227
return rootContext;
222228
}
223229

@@ -400,6 +406,7 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
400406
if (typeof options !== 'object') {
401407
options = {}; // If options is undefined or not an object the plugin fails
402408
}
409+
403410
if (options && options.mode) {
404411
if (
405412
options.mode !== 'global' &&
@@ -411,8 +418,10 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
411418
);
412419
}
413420
}
421+
414422
const pureMode = options && options.mode === 'pure';
415423
const globalMode = options && options.mode === 'global';
424+
416425
return function(css) {
417426
css.walkAtRules(function(atrule) {
418427
if (/keyframes$/i.test(atrule.name)) {
@@ -450,6 +459,7 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
450459
});
451460
}
452461
});
462+
453463
css.walkRules(function(rule) {
454464
if (
455465
rule.parent.type === 'atrule' &&
@@ -480,7 +490,9 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
480490
'(pure selectors must contain at least one local class or id)'
481491
);
482492
}
493+
483494
rule.selector = context.selector;
495+
484496
// Less-syntax mixins parse as rules with no nodes
485497
if (rule.nodes) {
486498
rule.nodes.forEach(decl => localizeDecl(decl, context));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"dependencies": {
2727
"postcss": "^7.0.6",
28-
"postcss-selector-parser": "^5.0.0",
28+
"postcss-selector-parser": "^6.0.0",
2929
"postcss-value-parser": "^3.3.1"
3030
},
3131
"devDependencies": {

test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,26 @@ const tests = [
1111
input: '.foobar {}',
1212
expected: ':local(.foobar) {}',
1313
},
14+
{
15+
should: 'scope escaped selectors',
16+
input: '.\\3A \\) {}',
17+
expected: ':local(.\\3A \\)) {}',
18+
},
1419
{
1520
should: 'scope ids',
1621
input: '#foobar {}',
1722
expected: ':local(#foobar) {}',
1823
},
24+
{
25+
should: 'scope escaped ids',
26+
input: '#\\#test {}',
27+
expected: ':local(#\\#test) {}',
28+
},
29+
{
30+
should: 'scope escaped ids (2)',
31+
input: '#u-m\\00002b {}',
32+
expected: ':local(#u-m\\00002b) {}',
33+
},
1934
{
2035
should: 'scope multiple selectors',
2136
input: '.foo, .baz {}',

0 commit comments

Comments
 (0)