Skip to content

Commit 4640aaa

Browse files
committed
Merge pull request #58 from reworkcss/at-rule-linebreak
Allow EOL characters in all at-rules
2 parents 7a9c329 + 703fdf1 commit 4640aaa

File tree

47 files changed

+620
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+620
-3
lines changed

History.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Next
2+
====
3+
4+
* accept EOL characters and all other whitespace characters in `@` rules such
5+
as `@media`
6+
17
2.1.0 / 2014-08-05
28
==================
39

generate-tests.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Generates missing output source and AST files for the test cases
2+
// IMPORTANT: Always verify the generated files when using this!
3+
4+
var fs = require('fs');
5+
var path = require('path');
6+
var parse = require('./').parse;
7+
var stringify = require('./').stringify;
8+
9+
var casesDir = path.join(__dirname, 'test', 'cases');
10+
var cases = fs.readdirSync(casesDir)
11+
.map(function(f) { return path.join(casesDir, f); });
12+
13+
cases.forEach(function(dir) {
14+
var inputFile = path.join(dir, 'input.css');
15+
if (!fs.existsSync(inputFile))
16+
throw new Error('Missing input file ' + inputFile);
17+
18+
var input = fs.readFileSync(inputFile, 'utf8');
19+
var parsed;
20+
try {
21+
parsed = parse(input, { source: 'input.css' });
22+
} catch(e) {
23+
console.log('Failed to parse', inputFile);
24+
throw e;
25+
}
26+
27+
var outputFile = path.join(dir, 'output.css');
28+
if (!fs.existsSync(outputFile)) {
29+
console.log('Generating', outputFile);
30+
var output = stringify(parsed);
31+
fs.writeFileSync(outputFile, output, 'utf8');
32+
}
33+
34+
var compressedFile = path.join(dir, 'compressed.css');
35+
if (!fs.existsSync(compressedFile)) {
36+
console.log('Generating', compressedFile);
37+
var compressed = stringify(parsed, { compress: true });
38+
fs.writeFileSync(compressedFile, compressed, 'utf8');
39+
}
40+
41+
var astFile = path.join(dir, 'ast.json');
42+
if (!fs.existsSync(astFile)) {
43+
console.log('Generating', astFile);
44+
var ast = JSON.stringify(parsed, null, ' ');
45+
fs.writeFileSync(astFile, ast, 'utf8');
46+
}
47+
});

lib/parse/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ module.exports = function(css, options){
342342

343343
function athost() {
344344
var pos = position();
345-
var m = match(/^@host */);
345+
var m = match(/^@host\s*/);
346346

347347
if (!m) return;
348348

@@ -389,7 +389,7 @@ module.exports = function(css, options){
389389

390390
function atcustommedia() {
391391
var pos = position();
392-
var m = match(/^@custom-media (--[^\s]+) *([^{;]+);/);
392+
var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
393393
if (!m) return;
394394

395395
return pos({
@@ -506,7 +506,7 @@ module.exports = function(css, options){
506506

507507

508508
function _compileAtrule(name) {
509-
var re = new RegExp('^@' + name + ' *([^;\\n]+);');
509+
var re = new RegExp('^@' + name + '\\s*([^;]+);');
510510
return function() {
511511
var pos = position();
512512
var m = match(re);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"type": "stylesheet",
3+
"stylesheet": {
4+
"rules": [
5+
{
6+
"type": "charset",
7+
"charset": "\"UTF-8\"",
8+
"position": {
9+
"start": {
10+
"line": 1,
11+
"column": 1
12+
},
13+
"end": {
14+
"line": 3,
15+
"column": 6
16+
},
17+
"source": "input.css"
18+
}
19+
}
20+
]
21+
}
22+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@charset "UTF-8";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@charset
2+
"UTF-8"
3+
;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@charset "UTF-8";
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "stylesheet",
3+
"stylesheet": {
4+
"rules": [
5+
{
6+
"type": "custom-media",
7+
"name": "--test",
8+
"media": "(min-width: 200px)",
9+
"position": {
10+
"start": {
11+
"line": 1,
12+
"column": 1
13+
},
14+
"end": {
15+
"line": 4,
16+
"column": 2
17+
},
18+
"source": "input.css"
19+
}
20+
}
21+
]
22+
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@custom-media --test (min-width: 200px);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@custom-media
2+
--test
3+
(min-width: 200px)
4+
;

0 commit comments

Comments
 (0)