Skip to content

Commit aa56c0c

Browse files
committed
add @import support
1 parent b68b9bd commit aa56c0c

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = function(css){
1414
function stylesheet() {
1515
var rules = [];
1616
var node;
17+
whitespace();
1718
comments();
1819
while (node = atrule() || rule()) {
1920
comments();
@@ -177,12 +178,23 @@ module.exports = function(css){
177178
return decls;
178179
}
179180

180-
/**
181-
* Parse at rule.
182-
*/
183-
181+
/**
182+
* Parse import
183+
*/
184+
185+
function atimport() {
186+
var m = match(/^@import *([^;\n]+);\s*/);
187+
if (!m) return;
188+
return { import: m[1] };
189+
}
190+
191+
/**
192+
* Parse at rule.
193+
*/
194+
184195
function atrule() {
185-
return keyframes();
196+
return keyframes()
197+
|| atimport();
186198
}
187199

188200
/**

test/cases/import.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
@import url("fineprint.css") print;
3+
@import url("bluish.css") projection, tv;
4+
@import 'custom.css';
5+
@import "common.css" screen, projection;
6+
@import url('landscape.css') screen and (orientation:landscape);

test/cases/import.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"stylesheet": {
3+
"rules": [
4+
{
5+
"import": "url(\"fineprint.css\") print"
6+
},
7+
{
8+
"import": "url(\"bluish.css\") projection, tv"
9+
},
10+
{
11+
"import": "'custom.css'"
12+
},
13+
{
14+
"import": "\"common.css\" screen, projection"
15+
},
16+
{
17+
"import": "url('landscape.css') screen and (orientation:landscape)"
18+
}
19+
]
20+
}
21+
}

0 commit comments

Comments
 (0)