Skip to content

Add source property to position #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ parse tree with `.position` enabled:
}
```

If you also pass in `source: 'path/to/original.css'`, that will be set
on `node.position.source`.

## Performance

Parsed 15,000 lines of CSS (2mb) in 40ms on my macbook air.
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ module.exports = function(css, options){
return function(node){
node.position = {
start: start,
end: { line: lineno, column: column }
end: { line: lineno, column: column },
source: options.source
};

whitespace();
Expand Down
12 changes: 8 additions & 4 deletions test/cases/charset.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"end": {
"line": 1,
"column": 18
}
},
"source": "charset.css"
}
},
{
Expand All @@ -27,7 +28,8 @@
"end": {
"line": 1,
"column": 82
}
},
"source": "charset.css"
}
},
{
Expand All @@ -41,7 +43,8 @@
"end": {
"line": 2,
"column": 24
}
},
"source": "charset.css"
}
},
{
Expand All @@ -55,7 +58,8 @@
"end": {
"line": 2,
"column": 122
}
},
"source": "charset.css"
}
}
]
Expand Down
9 changes: 6 additions & 3 deletions test/cases/colon-space.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"end": {
"line": 2,
"column": 19
}
},
"source": "colon-space.css"
}
},
{
Expand All @@ -35,7 +36,8 @@
"end": {
"line": 3,
"column": 16
}
},
"source": "colon-space.css"
}
}
],
Expand All @@ -47,7 +49,8 @@
"end": {
"line": 4,
"column": 2
}
},
"source": "colon-space.css"
}
}
]
Expand Down
27 changes: 18 additions & 9 deletions test/cases/comment.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"end": {
"line": 1,
"column": 8
}
},
"source": "comment.css"
}
},
{
Expand All @@ -33,7 +34,8 @@
"end": {
"line": 3,
"column": 15
}
},
"source": "comment.css"
}
},
{
Expand All @@ -47,7 +49,8 @@
"end": {
"line": 4,
"column": 10
}
},
"source": "comment.css"
}
},
{
Expand All @@ -61,7 +64,8 @@
"end": {
"line": 5,
"column": 7
}
},
"source": "comment.css"
}
},
{
Expand All @@ -76,7 +80,8 @@
"end": {
"line": 5,
"column": 17
}
},
"source": "comment.css"
}
},
{
Expand All @@ -90,7 +95,8 @@
"end": {
"line": 6,
"column": 10
}
},
"source": "comment.css"
}
}
],
Expand All @@ -102,7 +108,8 @@
"end": {
"line": 7,
"column": 2
}
},
"source": "comment.css"
}
},
{
Expand All @@ -116,7 +123,8 @@
"end": {
"line": 7,
"column": 10
}
},
"source": "comment.css"
}
},
{
Expand All @@ -130,7 +138,8 @@
"end": {
"line": 9,
"column": 8
}
},
"source": "comment.css"
}
}
]
Expand Down
21 changes: 14 additions & 7 deletions test/cases/comment.url.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"end": {
"line": 1,
"column": 34
}
},
"source": "comment.url.css"
}
},
{
Expand All @@ -27,7 +28,8 @@
"end": {
"line": 2,
"column": 5
}
},
"source": "comment.url.css"
}
},
{
Expand All @@ -47,7 +49,8 @@
"end": {
"line": 4,
"column": 12
}
},
"source": "comment.url.css"
}
},
{
Expand All @@ -61,7 +64,8 @@
"end": {
"line": 5,
"column": 18
}
},
"source": "comment.url.css"
}
},
{
Expand All @@ -76,7 +80,8 @@
"end": {
"line": 6,
"column": 11
}
},
"source": "comment.url.css"
}
},
{
Expand All @@ -90,7 +95,8 @@
"end": {
"line": 6,
"column": 46
}
},
"source": "comment.url.css"
}
}
],
Expand All @@ -102,7 +108,8 @@
"end": {
"line": 7,
"column": 2
}
},
"source": "comment.url.css"
}
}
]
Expand Down
15 changes: 10 additions & 5 deletions test/cases/document.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"end": {
"line": 2,
"column": 17
}
},
"source": "document.css"
}
},
{
Expand All @@ -38,7 +39,8 @@
"end": {
"line": 4,
"column": 20
}
},
"source": "document.css"
}
},
{
Expand All @@ -53,7 +55,8 @@
"end": {
"line": 6,
"column": 3
}
},
"source": "document.css"
}
}
],
Expand All @@ -65,7 +68,8 @@
"end": {
"line": 6,
"column": 4
}
},
"source": "document.css"
}
}
],
Expand All @@ -77,7 +81,8 @@
"end": {
"line": 7,
"column": 2
}
},
"source": "document.css"
}
}
]
Expand Down
15 changes: 10 additions & 5 deletions test/cases/import.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"end": {
"line": 2,
"column": 36
}
},
"source": "import.css"
}
},
{
Expand All @@ -27,7 +28,8 @@
"end": {
"line": 3,
"column": 42
}
},
"source": "import.css"
}
},
{
Expand All @@ -41,7 +43,8 @@
"end": {
"line": 4,
"column": 22
}
},
"source": "import.css"
}
},
{
Expand All @@ -55,7 +58,8 @@
"end": {
"line": 5,
"column": 41
}
},
"source": "import.css"
}
},
{
Expand All @@ -69,7 +73,8 @@
"end": {
"line": 6,
"column": 65
}
},
"source": "import.css"
}
}
]
Expand Down
15 changes: 10 additions & 5 deletions test/cases/import.messed.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"end": {
"line": 2,
"column": 39
}
},
"source": "import.messed.css"
}
},
{
Expand All @@ -27,7 +28,8 @@
"end": {
"line": 3,
"column": 44
}
},
"source": "import.messed.css"
}
},
{
Expand All @@ -41,7 +43,8 @@
"end": {
"line": 4,
"column": 28
}
},
"source": "import.messed.css"
}
},
{
Expand All @@ -55,7 +58,8 @@
"end": {
"line": 5,
"column": 45
}
},
"source": "import.messed.css"
}
},
{
Expand All @@ -69,7 +73,8 @@
"end": {
"line": 7,
"column": 67
}
},
"source": "import.messed.css"
}
}
]
Expand Down
Loading