Skip to content

Commit 190ba98

Browse files
committed
rename source -> filename
1 parent ce56f46 commit 190ba98

30 files changed

+273
-262
lines changed

History.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2.0.0 /
2+
==================
3+
4+
* rename source to filename
5+
- `source` is now the CSS string
6+
- `filename` is now the optional filename
17

28
1.7.0 / 2013-12-21
39
==================

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-
// Position and Source parameters
20-
var output_obj_pos = parse(css, { position: true, source: 'file.css' });
19+
// Position and Filename parameters
20+
var output_obj_pos = parse(css, { position: true, filename: 'file.css' });
2121

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

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

131131
## Performance
132132

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

135135
## Related
136-
137-
[css-stringify](https://github.com/visionmedia/css-stringify "CSS-Stringify")
138-
[css-value](https://github.com/visionmedia/css-value "CSS-Value")
136+
137+
[css-stringify](https://github.com/visionmedia/css-stringify "CSS-Stringify")
138+
[css-value](https://github.com/visionmedia/css-value "CSS-Value")
139139

140140
## License
141141

index.js

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

2626
function position() {
27-
var start = { line: lineno, column: column };
2827
if (!options.position) return positionNoop;
2928

30-
return function(node){
31-
node.position = {
32-
start: start,
33-
end: { line: lineno, column: column },
34-
source: options.source
35-
};
29+
var start = { line: lineno, column: column };
3630

31+
return function(node){
32+
node.position = new Position(start);
3733
whitespace();
3834
return node;
3935
}
4036
}
4137

38+
function Position(start) {
39+
this.start = start;
40+
this.end = { line: lineno, column: column };
41+
this.filename = options.filename;
42+
}
43+
44+
/**
45+
* Non-enumerable source string.
46+
*/
47+
48+
Position.prototype.source = css;
49+
4250
/**
4351
* Return `node`.
4452
*/
@@ -52,12 +60,9 @@ module.exports = function(css, options){
5260
* Error `msg`.
5361
*/
5462

55-
function error(msg) {
63+
function error(msg, start) {
5664
var err = new Error(msg + ' near line ' + lineno + ':' + column);
57-
err.filename = options.source;
58-
err.line = lineno;
59-
err.column = column;
60-
err.source = css;
65+
err.position = new Position(start);
6166
throw err;
6267
}
6368

@@ -169,7 +174,7 @@ module.exports = function(css, options){
169174
function selector() {
170175
var m = match(/^([^{]+)/);
171176
if (!m) return;
172-
/* @fix Remove all comments from selectors
177+
/* @fix Remove all comments from selectors
173178
* http://ostermiller.org/findcomment.html */
174179
return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '').split(/\s*,\s*/);
175180
}

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-
"source": "charset.css"
17+
"filename": "charset.css"
1818
}
1919
},
2020
{
@@ -29,7 +29,7 @@
2929
"line": 1,
3030
"column": 82
3131
},
32-
"source": "charset.css"
32+
"filename": "charset.css"
3333
}
3434
},
3535
{
@@ -44,7 +44,7 @@
4444
"line": 2,
4545
"column": 24
4646
},
47-
"source": "charset.css"
47+
"filename": "charset.css"
4848
}
4949
},
5050
{
@@ -59,7 +59,7 @@
5959
"line": 2,
6060
"column": 122
6161
},
62-
"source": "charset.css"
62+
"filename": "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-
"source": "colon-space.css"
24+
"filename": "colon-space.css"
2525
}
2626
},
2727
{
@@ -37,7 +37,7 @@
3737
"line": 3,
3838
"column": 16
3939
},
40-
"source": "colon-space.css"
40+
"filename": "colon-space.css"
4141
}
4242
}
4343
],
@@ -50,7 +50,7 @@
5050
"line": 4,
5151
"column": 2
5252
},
53-
"source": "colon-space.css"
53+
"filename": "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-
"source": "comment.css"
17+
"filename": "comment.css"
1818
}
1919
},
2020
{
@@ -36,7 +36,7 @@
3636
"line": 3,
3737
"column": 44
3838
},
39-
"source": "comment.css"
39+
"filename": "comment.css"
4040
}
4141
},
4242
{
@@ -51,7 +51,7 @@
5151
"line": 4,
5252
"column": 10
5353
},
54-
"source": "comment.css"
54+
"filename": "comment.css"
5555
}
5656
},
5757
{
@@ -66,7 +66,7 @@
6666
"line": 5,
6767
"column": 7
6868
},
69-
"source": "comment.css"
69+
"filename": "comment.css"
7070
}
7171
},
7272
{
@@ -82,7 +82,7 @@
8282
"line": 5,
8383
"column": 17
8484
},
85-
"source": "comment.css"
85+
"filename": "comment.css"
8686
}
8787
},
8888
{
@@ -97,7 +97,7 @@
9797
"line": 6,
9898
"column": 10
9999
},
100-
"source": "comment.css"
100+
"filename": "comment.css"
101101
}
102102
}
103103
],
@@ -110,7 +110,7 @@
110110
"line": 7,
111111
"column": 2
112112
},
113-
"source": "comment.css"
113+
"filename": "comment.css"
114114
}
115115
},
116116
{
@@ -125,7 +125,7 @@
125125
"line": 7,
126126
"column": 10
127127
},
128-
"source": "comment.css"
128+
"filename": "comment.css"
129129
}
130130
},
131131
{
@@ -140,7 +140,7 @@
140140
"line": 9,
141141
"column": 8
142142
},
143-
"source": "comment.css"
143+
"filename": "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-
"source": "comment.url.css"
17+
"filename": "comment.url.css"
1818
}
1919
},
2020
{
@@ -29,7 +29,7 @@
2929
"line": 2,
3030
"column": 5
3131
},
32-
"source": "comment.url.css"
32+
"filename": "comment.url.css"
3333
}
3434
},
3535
{
@@ -50,7 +50,7 @@
5050
"line": 4,
5151
"column": 12
5252
},
53-
"source": "comment.url.css"
53+
"filename": "comment.url.css"
5454
}
5555
},
5656
{
@@ -65,7 +65,7 @@
6565
"line": 5,
6666
"column": 18
6767
},
68-
"source": "comment.url.css"
68+
"filename": "comment.url.css"
6969
}
7070
},
7171
{
@@ -81,7 +81,7 @@
8181
"line": 6,
8282
"column": 11
8383
},
84-
"source": "comment.url.css"
84+
"filename": "comment.url.css"
8585
}
8686
},
8787
{
@@ -96,7 +96,7 @@
9696
"line": 6,
9797
"column": 46
9898
},
99-
"source": "comment.url.css"
99+
"filename": "comment.url.css"
100100
}
101101
}
102102
],
@@ -109,7 +109,7 @@
109109
"line": 7,
110110
"column": 2
111111
},
112-
"source": "comment.url.css"
112+
"filename": "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-
"source": "document.css"
22+
"filename": "document.css"
2323
}
2424
},
2525
{
@@ -40,7 +40,7 @@
4040
"line": 4,
4141
"column": 20
4242
},
43-
"source": "document.css"
43+
"filename": "document.css"
4444
}
4545
},
4646
{
@@ -56,7 +56,7 @@
5656
"line": 6,
5757
"column": 3
5858
},
59-
"source": "document.css"
59+
"filename": "document.css"
6060
}
6161
}
6262
],
@@ -69,7 +69,7 @@
6969
"line": 6,
7070
"column": 4
7171
},
72-
"source": "document.css"
72+
"filename": "document.css"
7373
}
7474
}
7575
],
@@ -82,7 +82,7 @@
8282
"line": 7,
8383
"column": 2
8484
},
85-
"source": "document.css"
85+
"filename": "document.css"
8686
}
8787
}
8888
]

0 commit comments

Comments
 (0)