Skip to content

Commit 9266240

Browse files
committed
added support for more atrules
added support for `@keyframes` and `animation`
1 parent 29433bc commit 9266240

File tree

8 files changed

+372
-154
lines changed

8 files changed

+372
-154
lines changed

lib/parseSource.js

+219-151
Large diffs are not rendered by default.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "css loader module for webpack",
66
"dependencies": {
77
"clean-css": "^3.1.9",
8-
"fastparse": "^1.0.0",
8+
"fastparse": "^1.1.1",
99
"loader-utils": "~0.2.2",
1010
"source-list-map": "^0.1.4"
1111
},
@@ -18,7 +18,7 @@
1818
"scripts": {
1919
"test": "mocha",
2020
"travis": "npm run cover -- --report lcovonly",
21-
"cover": "istanbul cover -x *.runtime.js node_modules/mocha/bin/_mocha",
21+
"cover": "istanbul cover node_modules/mocha/bin/_mocha",
2222
"publish-patch": "mocha && npm version patch && git push && git push --tags && npm publish"
2323
},
2424
"repository": {

test/helpers.js

+22-1
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) {
7+
function assetEvaluated(output, result, modules, noLocals) {
88
try {
99
var fn = vm.runInThisContext("(function(module, exports, require) {" + output + "})", "testcase.js");
1010
var m = { exports: {}, id: 1 };
@@ -23,6 +23,7 @@ function assetEvaluated(output, result, modules) {
2323
}
2424
delete m.exports.toString;
2525
delete m.exports.i;
26+
if(noLocals) delete m.exports.locals;
2627
m.exports.should.be.eql(result);
2728

2829
}
@@ -47,6 +48,26 @@ exports.test = function test(name, input, result, query, modules) {
4748
});
4849
};
4950

51+
exports.testWithoutLocals = function testWithoutLocals(name, input, result, query, modules) {
52+
it(name, function() {
53+
var output = cssLoader.call({
54+
options: {
55+
context: ""
56+
},
57+
loaders: [{request: "loader"}],
58+
loaderIndex: 0,
59+
context: "",
60+
resource: "test.css",
61+
request: "css-loader!test.css",
62+
query: query,
63+
emitError: function(message) {
64+
throw new Error(message);
65+
}
66+
}, input);
67+
assetEvaluated(output, result, modules, true);
68+
});
69+
};
70+
5071
exports.testMinimize = function testMinimize(name, input, result, query, modules) {
5172
it(name, function() {
5273
var output = cssLoader.call({

test/moduleTest.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*globals describe */
2+
3+
var test = require("./helpers").testWithoutLocals;
4+
5+
var path = require("path");
6+
var fs = require("fs");
7+
var testCasesPath = path.join(__dirname, "moduleTestCases");
8+
var testCases = fs.readdirSync(testCasesPath);
9+
10+
describe("module", function() {
11+
testCases.forEach(function(name) {
12+
var source = fs.readFileSync(path.join(testCasesPath, name, "source.css"), "utf-8");
13+
var expected = fs.readFileSync(path.join(testCasesPath, name, "expected.css"), "utf-8");
14+
15+
test(name, source, [[1, expected, ""]], "?module&localIdentName=_[local]_");
16+
});
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
._a_ {
2+
color: green;
3+
}
4+
5+
@keyframes _bounce_ {
6+
0% {
7+
transform: translateY(-100%);
8+
opacity: 0;
9+
}
10+
5% {
11+
transform: translateY(-100%);
12+
opacity: 0;
13+
}
14+
}
15+
16+
@-webkit-keyframes _bounce2_ {
17+
0% {
18+
transform: translateY(-100%);
19+
opacity: 0;
20+
}
21+
5% {
22+
transform: translateY(-100%);
23+
opacity: 0;
24+
}
25+
}
26+
27+
._bounce_ {
28+
animation-name: _bounce_;
29+
animation: _bounce2_ 1s ease;
30+
}
31+
32+
._bounce2_ {
33+
color: green;
34+
animation: _bounce_ 1s ease;
35+
animation-name: _bounce2_;
36+
}
37+
38+
._bounce3_ {
39+
animation: _bounce_ 1s ease, _bounce2_
40+
}
41+
42+
._bounce4_ {
43+
animation: _bounce_ 1s ease, _bounce2_;
44+
}
45+
46+
._b_ {
47+
color: green;
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.a {
2+
color: green;
3+
}
4+
5+
@keyframes bounce {
6+
0% {
7+
transform: translateY(-100%);
8+
opacity: 0;
9+
}
10+
5% {
11+
transform: translateY(-100%);
12+
opacity: 0;
13+
}
14+
}
15+
16+
@-webkit-keyframes bounce2 {
17+
0% {
18+
transform: translateY(-100%);
19+
opacity: 0;
20+
}
21+
5% {
22+
transform: translateY(-100%);
23+
opacity: 0;
24+
}
25+
}
26+
27+
.bounce {
28+
animation-name: bounce;
29+
animation: bounce2 1s ease;
30+
}
31+
32+
.bounce2 {
33+
color: green;
34+
animation: bounce 1s ease;
35+
animation-name: bounce2;
36+
}
37+
38+
.bounce3 {
39+
animation: bounce 1s ease, bounce2
40+
}
41+
42+
.bounce4 {
43+
animation: bounce 1s ease, bounce2;
44+
}
45+
46+
.b {
47+
color: green;
48+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
._a_ ._b_, ._c_ ._d_, #_id_ {
2+
color: green;
3+
font-size: 1.5pt;
4+
}
5+
a[href="#b.c"]._x_._y_ {
6+
color: green;
7+
font-size: 1.5pt;
8+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.a .b, .c .d, #id {
2+
color: green;
3+
font-size: 1.5pt;
4+
}
5+
a[href="#b.c"].x.y {
6+
color: green;
7+
font-size: 1.5pt;
8+
}

0 commit comments

Comments
 (0)