Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 15041cf

Browse files
fix: handle scoped :global and :local in nested pseudo (#58)
1 parent 9adc96b commit 15041cf

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

‎src/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,19 @@ function localizeNode(rule, mode, localAliasMap) {
149149
hasLocals: false,
150150
explicit: context.explicit,
151151
};
152-
newNodes = node.map((childNode) =>
153-
transform(childNode, childContext)
154-
);
152+
newNodes = node.map((childNode) => {
153+
const newContext = {
154+
...childContext,
155+
enforceNoSpacing: false,
156+
};
157+
158+
const result = transform(childNode, newContext);
159+
160+
childContext.global = newContext.global;
161+
childContext.hasLocals = newContext.hasLocals;
162+
163+
return result;
164+
});
155165

156166
node = node.clone();
157167
node.nodes = normalizeNodeArray(newNodes);

‎test/index.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,51 @@ const tests = [
276276
input: ":global .foo { animation: foo; animation-name: bar; }",
277277
expected: ".foo { animation: foo; animation-name: bar; }",
278278
},
279+
{
280+
name: "handle nested global",
281+
input: ":global .a:not(:global .b) {}",
282+
expected: ".a:not(.b) {}",
283+
},
284+
{
285+
name: "handle nested global #1",
286+
input: ":global .a:not(:global .b:not(:global .c)) {}",
287+
expected: ".a:not(.b:not(.c)) {}",
288+
},
289+
{
290+
name: "handle nested global #2",
291+
input: ":local .a:not(:not(:not(:global .c))) {}",
292+
expected: ":local(.a):not(:not(:not(.c))) {}",
293+
},
294+
{
295+
name: "handle nested global #3",
296+
input: ":global .a:not(:global .b, :global .c) {}",
297+
expected: ".a:not(.b, .c) {}",
298+
},
299+
{
300+
name: "handle nested global #4",
301+
input: ":local .a:not(:global .b, :local .c) {}",
302+
expected: ":local(.a):not(.b, :local(.c)) {}",
303+
},
304+
{
305+
name: "handle nested global #5",
306+
input: ":global .a:not(:local .b, :global .c) {}",
307+
expected: ".a:not(:local(.b), .c) {}",
308+
},
309+
{
310+
name: "handle nested global #6",
311+
input: ":global .a:not(.b, .c) {}",
312+
expected: ".a:not(.b, .c) {}",
313+
},
314+
{
315+
name: "handle nested global #7",
316+
input: ":local .a:not(.b, .c) {}",
317+
expected: ":local(.a):not(:local(.b), :local(.c)) {}",
318+
},
319+
{
320+
name: "handle nested global #8",
321+
input: ":global .a:not(:local .b, .c) {}",
322+
expected: ".a:not(:local(.b), :local(.c)) {}",
323+
},
279324
{
280325
name: "handle a complex animation rule",
281326
input:
@@ -739,6 +784,11 @@ const tests = [
739784
input: ":global(#) {}",
740785
error: /Invalidclassoridselectorsyntax/,
741786
},
787+
{
788+
name: "throw on invalid global class usage",
789+
input: ":global(.a:not(:global .b, :global .c)) {}",
790+
error: /A:globalisnotallowedinsideofa:global/,
791+
},
742792
/*
743793
Bug in postcss-selector-parser
744794
{

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /