Skip to content

Commit 46f1e3a

Browse files
committed
Merge pull request #13 from css-modules/animation-frames
Drop global leakage detection & fix animation blocks
2 parents cc92a12 + bbbe18d commit 46f1e3a

File tree

2 files changed

+17
-45
lines changed

2 files changed

+17
-45
lines changed

index.js

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ function localizeNode(node, context) {
3131
case "selectors":
3232
var resultingGlobal;
3333
context.hasPureGlobals = false;
34-
context.hasPureImplicitGlobals = false;
3534
newNodes = node.nodes.map(function(n) {
3635
var nContext = {
3736
global: context.global,
3837
lastWasSpacing: true,
3938
hasLocals: false,
40-
hasImplicitGlobals: false,
4139
explicit: false
4240
};
4341
n = localizeNode(n, nContext);
@@ -49,9 +47,6 @@ function localizeNode(node, context) {
4947
}
5048
if(!nContext.hasLocals) {
5149
context.hasPureGlobals = true;
52-
if(nContext.hasImplicitGlobals) {
53-
context.hasPureImplicitGlobals = true;
54-
}
5550
}
5651
return n;
5752
});
@@ -101,7 +96,6 @@ function localizeNode(node, context) {
10196
global: (node.name === "global"),
10297
inside: node.name,
10398
hasLocals: false,
104-
hasImplicitGlobals: false,
10599
explicit: true
106100
};
107101
node = node.nodes.map(function(n) {
@@ -116,7 +110,6 @@ function localizeNode(node, context) {
116110
inside: context.inside,
117111
lastWasSpacing: true,
118112
hasLocals: false,
119-
hasImplicitGlobals: false,
120113
explicit: context.explicit
121114
};
122115
newNodes = node.nodes.map(function(n) {
@@ -128,16 +121,6 @@ function localizeNode(node, context) {
128121
if(subContext.hasLocals) {
129122
context.hasLocals = true;
130123
}
131-
if(subContext.hasImplicitGlobals) {
132-
context.hasImplicitGlobals = true;
133-
}
134-
break;
135-
136-
case "attribute":
137-
case "element":
138-
if(!context.global && !context.explicit) {
139-
context.hasImplicitGlobals = true;
140-
}
141124
break;
142125

143126
case "id":
@@ -231,12 +214,15 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
231214
}
232215
});
233216
css.eachRule(function(rule) {
217+
if(rule.parent.type === "atrule" && /keyframes$/.test(rule.parent.name)) {
218+
// ignore keyframe rules
219+
return;
220+
}
234221
var selector = Tokenizer.parse(rule.selector);
235222
var context = {
236223
options: options,
237224
global: globalMode,
238-
hasPureGlobals: false,
239-
hasPureImplicitGlobals: false
225+
hasPureGlobals: false
240226
};
241227
var newSelector;
242228
try {
@@ -248,10 +234,6 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
248234
throw rule.error("Selector '" + Tokenizer.stringify(selector) + "' is not pure " +
249235
"(pure selectors must contain at least one local class or id)");
250236
}
251-
if(!globalMode && context.hasPureImplicitGlobals) {
252-
throw rule.error("Selector '" + Tokenizer.stringify(selector) + "' must be explicit flagged :global " +
253-
"(elsewise it would leak globally)");
254-
}
255237
rule.nodes.forEach(function(decl) {
256238
localizeDecl(decl, context);
257239
});

test.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ var tests = [
211211
},
212212
{
213213
should: 'localize keyframes',
214-
input: '@keyframes foo {}',
215-
expected: '@keyframes :local(foo) {}'
214+
input: '@keyframes foo { from { color: red; } to { color: blue; } }',
215+
expected: '@keyframes :local(foo) { from { color: red; } to { color: blue; } }'
216216
},
217217
{
218218
should: 'localize keyframes in global default mode',
@@ -222,8 +222,8 @@ var tests = [
222222
},
223223
{
224224
should: 'localize explicit keyframes',
225-
input: '@keyframes :local(foo) {} @-webkit-keyframes :global(bar) {}',
226-
expected: '@keyframes :local(foo) {} @-webkit-keyframes bar {}'
225+
input: '@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes :global(bar) { from { color: red; } to { color: blue; } }',
226+
expected: '@keyframes :local(foo) { 0% { color: red; } 33.3% { color: yellow; } 100% { color: blue; } } @-webkit-keyframes bar { from { color: red; } to { color: blue; } }'
227227
},
228228
{
229229
should: 'ignore :export statements',
@@ -330,31 +330,20 @@ var tests = [
330330
error: /@keyframes :global\(\.\.\.\) is not allowed in pure mode/
331331
},
332332
{
333-
should: 'throw on implicit global element',
333+
should: 'pass through global element',
334334
input: 'input {}',
335-
error: /'input' must be explicit flagged :global/
336-
},
337-
{
338-
should: 'throw on implicit global element (with multiple 1)',
339-
input: 'input, .foo {}',
340-
error: /'input, \.foo' must be explicit flagged :global/
335+
expected: 'input {}'
341336
},
342337
{
343-
should: 'throw on implicit global element (with multiple 2)',
344-
input: '.foo, input {}',
345-
error: /'\.foo, input' must be explicit flagged :global/
338+
should: 'localise class and pass through element',
339+
input: '.foo input {}',
340+
expected: ':local(.foo) input {}'
346341
},
347342
{
348-
should: 'throw on implicit global attribute',
343+
should: 'pass through attribute selector',
349344
input: '[type="radio"] {}',
350-
error: /'\[type="radio"\]' must be explicit flagged :global/
345+
expected: '[type="radio"] {}'
351346
},
352-
{
353-
should: 'throw on implicit global attribute in nested',
354-
input: ':not([type="radio"]) {}',
355-
error: /':not\(\[type="radio"\]\)' must be explicit flagged :global/
356-
},
357-
358347
{
359348
should: 'not modify urls without option',
360349
input: '.a { background: url(./image.png); }\n' +
@@ -379,6 +368,7 @@ var tests = [
379368
'.b { background: url((global\\)image.png\\\"global\\\"); }\n' +
380369
':local(.c) { background: url(\"(local)./image.png\\\"local\\\"\"); }'
381370
}
371+
382372
];
383373

384374
function process (css, options) {

0 commit comments

Comments
 (0)