Skip to content

Commit b410526

Browse files
committed
leak :global into rules
1 parent a8623d9 commit b410526

File tree

7 files changed

+115
-10
lines changed

7 files changed

+115
-10
lines changed

lib/parseSource.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ function importMatch(match, url, mediaQuery, index) {
3838
}
3939

4040
function rulesStartMatch() {
41-
this.mode = null;
41+
this.blockMode = this.mode;
4242
return "firstRule";
4343
}
4444

4545
function rulesEndMatch() {
46+
this.mode = null;
4647
this.activeSelectors = [];
4748
return "source";
4849
}
@@ -128,6 +129,11 @@ function selectorMatch(match, prefix, name, index) {
128129
this.activeSelectors.push(selector);
129130
}
130131

132+
function ruleScopedMatch() {
133+
this.mode = this.blockMode;
134+
return "ruleScoped";
135+
}
136+
131137
function extendsStartMatch(match, index) {
132138
this.remove.push({
133139
start: index,
@@ -192,7 +198,7 @@ var parser = new Parser({
192198
"(url\\s*\\()(\\s*([^)]*)\\s*)\\)": urlMatch
193199
},
194200
scopedRules: {
195-
"(?:-[a-z]+-)?animation(?:-name)?:": "ruleScoped"
201+
"(?:-[a-z]+-)?animation(?:-name)?:": ruleScopedMatch
196202
},
197203

198204
// states
@@ -297,7 +303,7 @@ var parser = new Parser({
297303
"comments",
298304
{
299305
// reactivate
300-
",": "ruleScoped",
306+
",": ruleScopedMatch,
301307

302308
// back to normal rule
303309
";": "rule",

test/helpers.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require("should");
44
var cssLoader = require("../index.js");
55
var vm = require("vm");
66

7-
function assetEvaluated(output, result, modules, noLocals) {
7+
function getEvaluated(output, result, modules) {
88
try {
99
var fn = vm.runInThisContext("(function(module, exports, require) {" + output + "})", "testcase.js");
1010
var m = { exports: {}, id: 1 };
@@ -23,9 +23,12 @@ function assetEvaluated(output, result, modules, noLocals) {
2323
}
2424
delete m.exports.toString;
2525
delete m.exports.i;
26-
if(noLocals) delete m.exports.locals;
27-
m.exports.should.be.eql(result);
26+
return m.exports;
27+
}
2828

29+
function assetEvaluated(output, result, modules) {
30+
var exports = getEvaluated(output, result, modules);
31+
exports.should.be.eql(result);
2932
}
3033

3134
exports.test = function test(name, input, result, query, modules) {
@@ -48,7 +51,7 @@ exports.test = function test(name, input, result, query, modules) {
4851
});
4952
};
5053

51-
exports.testWithoutLocals = function testWithoutLocals(name, input, result, query, modules) {
54+
exports.testSingleItem = function testSingleItem(name, input, result, query, modules) {
5255
it(name, function() {
5356
var output = cssLoader.call({
5457
options: {
@@ -64,7 +67,13 @@ exports.testWithoutLocals = function testWithoutLocals(name, input, result, quer
6467
throw new Error(message);
6568
}
6669
}, input);
67-
assetEvaluated(output, result, modules, true);
70+
var exports = getEvaluated(output, result, modules);
71+
Array.isArray(exports).should.be.eql(true);
72+
(exports.length).should.be.eql(1);
73+
(exports[0].length).should.be.eql(3);
74+
(exports[0][0]).should.be.eql(1);
75+
(exports[0][2]).should.be.eql("");
76+
(exports[0][1]).should.be.eql(result);
6877
});
6978
};
7079

test/moduleTest.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*globals describe */
22

3-
var test = require("./helpers").testWithoutLocals;
3+
var test = require("./helpers").testSingleItem;
44

55
var path = require("path");
66
var fs = require("fs");
@@ -12,6 +12,6 @@ describe("module", function() {
1212
var source = fs.readFileSync(path.join(testCasesPath, name, "source.css"), "utf-8");
1313
var expected = fs.readFileSync(path.join(testCasesPath, name, "expected.css"), "utf-8");
1414

15-
test(name, source, [[1, expected, ""]], "?module&localIdentName=_[local]_");
15+
test(name, source, expected, "?module&localIdentName=_[local]_");
1616
});
1717
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
._a_ {
2+
color: green;
3+
animation: _a_;
4+
}
5+
6+
@keyframes _b_ {
7+
0% { left: 10px; }
8+
100% { left: 20px; }
9+
}
10+
11+
._b_ {
12+
animation: _b_;
13+
}
14+
15+
@keyframes c {
16+
0% { left: 10px; }
17+
100% { left: 20px; }
18+
}
19+
20+
._c_ {
21+
animation: c1;
22+
animation: _c2_, c3, _c4_;
23+
}
24+
25+
@keyframes d {
26+
0% { left: 10px; }
27+
100% { left: 20px; }
28+
}
29+
30+
.d1 {
31+
animation: d1;
32+
animation: d2, _d3_, d4;
33+
}
34+
35+
.d2 {
36+
animation: _d2_;
37+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.a {
2+
color: green;
3+
animation: a;
4+
}
5+
6+
@keyframes b {
7+
0% { left: 10px; }
8+
100% { left: 20px; }
9+
}
10+
11+
.b {
12+
animation: b;
13+
}
14+
15+
@keyframes :global c {
16+
0% { left: 10px; }
17+
100% { left: 20px; }
18+
}
19+
20+
.c {
21+
animation: :global c1;
22+
animation: c2, :global c3, c4;
23+
}
24+
25+
@keyframes :global d {
26+
0% { left: 10px; }
27+
100% { left: 20px; }
28+
}
29+
30+
:global .d1 {
31+
animation: d1;
32+
animation: d2, :local(d3), d4;
33+
}
34+
35+
:global(.d2) {
36+
animation: d2;
37+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
._a_ {
2+
background: url({./module});
3+
background: url({./module});
4+
background: url({./module});
5+
background: url({./module}#?iefix);
6+
background: url("#hash");
7+
background: url("#");
8+
}

test/moduleTestCases/urls/source.css

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.a {
2+
background: url(./module);
3+
background: url("./module");
4+
background: url('./module');
5+
background: url("./module#?iefix");
6+
background: url("#hash");
7+
background: url("#");
8+
}

0 commit comments

Comments
 (0)