Skip to content

Commit 018175e

Browse files
committed
Revert "rename source -> filename"
This reverts commit 190ba98. Conflicts: History.md Readme.md test/css-parse.js
1 parent 35d5931 commit 018175e

30 files changed

+262
-271
lines changed

History.md

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
21
2.0.0 / 2014-01-24
32
==================
43

5-
* rename source to filename
6-
- `source` is now the CSS string
7-
- `filename` is now the optional filename
84
* changed default `options.position` value to `true`
95
* remove comments from properties and values
106
* asserts when selectors are missing

Readme.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ var css = "body { \n background-color: #fff;\n }";
1616

1717
var output_obj = parse(css);
1818

19-
// Filename parameter for source mapping
20-
var output_obj_pos = parse(css, { filename: 'file.css' });
19+
// Source parameter to specify source file name for source maps
20+
var output_obj_pos = parse(css, { source: 'file.css' });
2121

2222
// Print parsed object as CSS string
2323
console.log(JSON.stringify(output_obj, null, 2));
@@ -145,17 +145,17 @@ parse tree with `.position` enabled:
145145
}
146146
```
147147

148-
If you also pass in `filename: 'path/to/original.css'`, that will be set
149-
on `node.position.filename`.
148+
If you also pass in `source: 'path/to/original.css'`, that will be set
149+
on `node.position.source`.
150150

151151
## Performance
152152

153153
Parsed 15,000 lines of CSS (2mb) in 40ms on my macbook air.
154154

155155
## Related
156-
157-
[css-stringify](https://github.com/visionmedia/css-stringify "CSS-Stringify")
158-
[css-value](https://github.com/visionmedia/css-value "CSS-Value")
156+
157+
[css-stringify](https://github.com/visionmedia/css-stringify "CSS-Stringify")
158+
[css-value](https://github.com/visionmedia/css-value "CSS-Value")
159159

160160
## License
161161

index.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,21 @@ module.exports = function(css, options){
2929
*/
3030

3131
function position() {
32-
if (!options.position) return positionNoop;
33-
3432
var start = { line: lineno, column: column };
33+
if (!options.position) return positionNoop;
3534

3635
return function(node){
37-
node.position = new Position(start);
36+
node.position = {
37+
start: start,
38+
end: { line: lineno, column: column },
39+
source: options.source
40+
};
41+
3842
whitespace();
3943
return node;
4044
};
4145
}
4246

43-
function Position(start) {
44-
this.start = start;
45-
this.end = { line: lineno, column: column };
46-
this.filename = options.filename;
47-
}
48-
49-
/**
50-
* Non-enumerable source string.
51-
*/
52-
53-
Position.prototype.source = css;
54-
5547
/**
5648
* Return `node`.
5749
*/
@@ -65,9 +57,12 @@ module.exports = function(css, options){
6557
* Error `msg`.
6658
*/
6759

68-
function error(msg, start) {
60+
function error(msg) {
6961
var err = new Error(msg + ' near line ' + lineno + ':' + column);
70-
err.position = new Position(start);
62+
err.filename = options.source;
63+
err.line = lineno;
64+
err.column = column;
65+
err.source = css;
7166
throw err;
7267
}
7368

@@ -183,7 +178,7 @@ module.exports = function(css, options){
183178
function selector() {
184179
var m = match(/^([^{]+)/);
185180
if (!m) return;
186-
/* @fix Remove all comments from selectors
181+
/* @fix Remove all comments from selectors
187182
* http://ostermiller.org/findcomment.html */
188183
return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '').split(/\s*,\s*/);
189184
}

test/cases/charset.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"line": 1,
1515
"column": 18
1616
},
17-
"filename": "charset.css"
17+
"source": "charset.css"
1818
}
1919
},
2020
{
@@ -29,7 +29,7 @@
2929
"line": 1,
3030
"column": 82
3131
},
32-
"filename": "charset.css"
32+
"source": "charset.css"
3333
}
3434
},
3535
{
@@ -44,7 +44,7 @@
4444
"line": 2,
4545
"column": 24
4646
},
47-
"filename": "charset.css"
47+
"source": "charset.css"
4848
}
4949
},
5050
{
@@ -59,7 +59,7 @@
5959
"line": 2,
6060
"column": 122
6161
},
62-
"filename": "charset.css"
62+
"source": "charset.css"
6363
}
6464
}
6565
]

test/cases/colon-space.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"line": 2,
2222
"column": 19
2323
},
24-
"filename": "colon-space.css"
24+
"source": "colon-space.css"
2525
}
2626
},
2727
{
@@ -37,7 +37,7 @@
3737
"line": 3,
3838
"column": 16
3939
},
40-
"filename": "colon-space.css"
40+
"source": "colon-space.css"
4141
}
4242
}
4343
],
@@ -50,7 +50,7 @@
5050
"line": 4,
5151
"column": 2
5252
},
53-
"filename": "colon-space.css"
53+
"source": "colon-space.css"
5454
}
5555
}
5656
]

test/cases/comment.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"line": 1,
1515
"column": 8
1616
},
17-
"filename": "comment.css"
17+
"source": "comment.css"
1818
}
1919
},
2020
{
@@ -36,7 +36,7 @@
3636
"line": 3,
3737
"column": 44
3838
},
39-
"filename": "comment.css"
39+
"source": "comment.css"
4040
}
4141
},
4242
{
@@ -51,7 +51,7 @@
5151
"line": 4,
5252
"column": 10
5353
},
54-
"filename": "comment.css"
54+
"source": "comment.css"
5555
}
5656
},
5757
{
@@ -66,7 +66,7 @@
6666
"line": 5,
6767
"column": 7
6868
},
69-
"filename": "comment.css"
69+
"source": "comment.css"
7070
}
7171
},
7272
{
@@ -82,7 +82,7 @@
8282
"line": 5,
8383
"column": 17
8484
},
85-
"filename": "comment.css"
85+
"source": "comment.css"
8686
}
8787
},
8888
{
@@ -97,7 +97,7 @@
9797
"line": 6,
9898
"column": 10
9999
},
100-
"filename": "comment.css"
100+
"source": "comment.css"
101101
}
102102
}
103103
],
@@ -110,7 +110,7 @@
110110
"line": 7,
111111
"column": 2
112112
},
113-
"filename": "comment.css"
113+
"source": "comment.css"
114114
}
115115
},
116116
{
@@ -125,7 +125,7 @@
125125
"line": 7,
126126
"column": 10
127127
},
128-
"filename": "comment.css"
128+
"source": "comment.css"
129129
}
130130
},
131131
{
@@ -140,7 +140,7 @@
140140
"line": 9,
141141
"column": 8
142142
},
143-
"filename": "comment.css"
143+
"source": "comment.css"
144144
}
145145
}
146146
]

test/cases/comment.url.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"line": 1,
1515
"column": 34
1616
},
17-
"filename": "comment.url.css"
17+
"source": "comment.url.css"
1818
}
1919
},
2020
{
@@ -29,7 +29,7 @@
2929
"line": 2,
3030
"column": 5
3131
},
32-
"filename": "comment.url.css"
32+
"source": "comment.url.css"
3333
}
3434
},
3535
{
@@ -50,7 +50,7 @@
5050
"line": 4,
5151
"column": 12
5252
},
53-
"filename": "comment.url.css"
53+
"source": "comment.url.css"
5454
}
5555
},
5656
{
@@ -65,7 +65,7 @@
6565
"line": 5,
6666
"column": 18
6767
},
68-
"filename": "comment.url.css"
68+
"source": "comment.url.css"
6969
}
7070
},
7171
{
@@ -81,7 +81,7 @@
8181
"line": 6,
8282
"column": 11
8383
},
84-
"filename": "comment.url.css"
84+
"source": "comment.url.css"
8585
}
8686
},
8787
{
@@ -96,7 +96,7 @@
9696
"line": 6,
9797
"column": 46
9898
},
99-
"filename": "comment.url.css"
99+
"source": "comment.url.css"
100100
}
101101
}
102102
],
@@ -109,7 +109,7 @@
109109
"line": 7,
110110
"column": 2
111111
},
112-
"filename": "comment.url.css"
112+
"source": "comment.url.css"
113113
}
114114
}
115115
]

test/cases/document.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"line": 2,
2020
"column": 17
2121
},
22-
"filename": "document.css"
22+
"source": "document.css"
2323
}
2424
},
2525
{
@@ -40,7 +40,7 @@
4040
"line": 4,
4141
"column": 20
4242
},
43-
"filename": "document.css"
43+
"source": "document.css"
4444
}
4545
},
4646
{
@@ -56,7 +56,7 @@
5656
"line": 6,
5757
"column": 3
5858
},
59-
"filename": "document.css"
59+
"source": "document.css"
6060
}
6161
}
6262
],
@@ -69,7 +69,7 @@
6969
"line": 6,
7070
"column": 4
7171
},
72-
"filename": "document.css"
72+
"source": "document.css"
7373
}
7474
}
7575
],
@@ -82,7 +82,7 @@
8282
"line": 7,
8383
"column": 2
8484
},
85-
"filename": "document.css"
85+
"source": "document.css"
8686
}
8787
}
8888
]

0 commit comments

Comments
 (0)