Skip to content

Commit a7a0f7c

Browse files
committed
Add node.position.content containing source string
1 parent 759dc56 commit a7a0f7c

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* changed default `options.position` value to `true`
55
* remove comments from properties and values
66
* asserts when selectors are missing
7+
* added `node.position.content` property
78

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

Readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ parse tree with `.position` enabled:
144144
}
145145
```
146146

147-
If you also pass in `source: 'path/to/original.css'`, that will be set
148-
on `node.position.source`.
147+
`node.position.content` is set on each node to the full source string. If you
148+
also pass in `source: 'path/to/original.css'`, that will be set on
149+
`node.position.source`.
149150

150151
## Performance
151152

index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,28 @@ module.exports = function(css, options){
3333
if (!options.position) return positionNoop;
3434

3535
return function(node){
36-
node.position = {
37-
start: start,
38-
end: { line: lineno, column: column },
39-
source: options.source
40-
};
41-
36+
node.position = new Position(start);
4237
whitespace();
4338
return node;
4439
};
4540
}
4641

42+
/**
43+
* Store position information for a node
44+
*/
45+
46+
function Position(start) {
47+
this.start = start;
48+
this.end = { line: lineno, column: column };
49+
this.source = options.source;
50+
}
51+
52+
/**
53+
* Non-enumerable source string
54+
*/
55+
56+
Position.prototype.content = css;
57+
4758
/**
4859
* Return `node`.
4960
*/

test/css-parse.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('parse(str)', function(){
3333
position.start.should.be.ok;
3434
position.end.should.be.ok;
3535
position.source.should.equal('booty.css');
36+
position.content.should.equal(css);
3637
});
3738

3839
it('should throw when a selector is missing', function(){

0 commit comments

Comments
 (0)