Skip to content

Commit ef3ae80

Browse files
committed
position: true by default
1 parent 190ba98 commit ef3ae80

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* rename source to filename
55
- `source` is now the CSS string
66
- `filename` is now the optional filename
7+
* changed default `options.position` value to `true`
78

89
1.7.0 / 2013-12-21
910
==================

Readme.md

+20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ console.log(JSON.stringify(output_obj, null, 2));
2424

2525
````
2626

27+
## API
28+
29+
### var ast = parse(css, [options])
30+
31+
`options`:
32+
33+
- `filename` - recommended for debugging
34+
- `position` - `true` by default.
35+
36+
### Errors
37+
38+
Errors will have `err.position` where `position` is:
39+
40+
- `start` - start line and column numbers
41+
- `end` - end line and column numbers
42+
- `filename` - filename if passed to options
43+
- `source` - source CSS string
44+
45+
If you create any errors in plugins such as in [rework](https://github.com/visionmedia/rework), you __must__ set the `position` as well for consistency.
46+
2747
## Example
2848

2949
css:

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = function(css, options){
22
options = options || {};
3+
options.position = options.position === false ? false : true;
34

45
/**
56
* Positional.

test/css-parse.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,22 @@ describe('parse(str)', function(){
1616
it('should parse ' + file, function(){
1717
var css = read(path.join('test', 'cases', file + '.css'), 'utf8');
1818
var json = read(path.join('test', 'cases', file + '.json'), 'utf8');
19-
var ret = parse(css, { position: true, filename: file + '.css' });
19+
var ret = parse(css, { filename: file + '.css' });
2020
ret = JSON.stringify(ret, null, 2);
2121
ret.should.equal(json);
2222
})
2323
});
24+
25+
it('should save the filename and source', function(){
26+
var css = 'booty {\n size: large;\n}\n';
27+
var ast = parse(css, {
28+
filename: 'booty.css'
29+
});
30+
31+
var position = ast.stylesheet.rules[0].position
32+
position.start.should.be.ok;
33+
position.end.should.be.ok;
34+
position.filename.should.equal('booty.css');
35+
position.source.should.equal(css);
36+
});
2437
})

0 commit comments

Comments
 (0)