Skip to content

Commit 1d91321

Browse files
committed
Add source property to position
This allows for source map generation when multiple source files are used to create a single output file. It could something simple as concatenating several files, or something more complex such as joining rules with the same selector.
1 parent 455dc95 commit 1d91321

26 files changed

+286
-142
lines changed

Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ parse tree with `.position` enabled:
104104
}
105105
```
106106

107+
If you also pass in `source: 'path/to/original.css'`, that will be set
108+
on `node.position.source`.
109+
107110
## Performance
108111

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

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ module.exports = function(css, options){
3131
return function(node){
3232
node.position = {
3333
start: start,
34-
end: { line: lineno, column: column }
34+
end: { line: lineno, column: column },
35+
source: options.source
3536
};
3637

3738
whitespace();

test/cases/charset.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"end": {
1414
"line": 1,
1515
"column": 18
16-
}
16+
},
17+
"source": "charset.css"
1718
}
1819
},
1920
{
@@ -27,7 +28,8 @@
2728
"end": {
2829
"line": 1,
2930
"column": 82
30-
}
31+
},
32+
"source": "charset.css"
3133
}
3234
},
3335
{
@@ -41,7 +43,8 @@
4143
"end": {
4244
"line": 2,
4345
"column": 24
44-
}
46+
},
47+
"source": "charset.css"
4548
}
4649
},
4750
{
@@ -55,7 +58,8 @@
5558
"end": {
5659
"line": 2,
5760
"column": 122
58-
}
61+
},
62+
"source": "charset.css"
5963
}
6064
}
6165
]

test/cases/colon-space.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"end": {
2121
"line": 2,
2222
"column": 19
23-
}
23+
},
24+
"source": "colon-space.css"
2425
}
2526
},
2627
{
@@ -35,7 +36,8 @@
3536
"end": {
3637
"line": 3,
3738
"column": 16
38-
}
39+
},
40+
"source": "colon-space.css"
3941
}
4042
}
4143
],
@@ -47,7 +49,8 @@
4749
"end": {
4850
"line": 4,
4951
"column": 2
50-
}
52+
},
53+
"source": "colon-space.css"
5154
}
5255
}
5356
]

test/cases/comment.json

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"end": {
1414
"line": 1,
1515
"column": 8
16-
}
16+
},
17+
"source": "comment.css"
1718
}
1819
},
1920
{
@@ -33,7 +34,8 @@
3334
"end": {
3435
"line": 3,
3536
"column": 15
36-
}
37+
},
38+
"source": "comment.css"
3739
}
3840
},
3941
{
@@ -47,7 +49,8 @@
4749
"end": {
4850
"line": 4,
4951
"column": 10
50-
}
52+
},
53+
"source": "comment.css"
5154
}
5255
},
5356
{
@@ -61,7 +64,8 @@
6164
"end": {
6265
"line": 5,
6366
"column": 7
64-
}
67+
},
68+
"source": "comment.css"
6569
}
6670
},
6771
{
@@ -76,7 +80,8 @@
7680
"end": {
7781
"line": 5,
7882
"column": 17
79-
}
83+
},
84+
"source": "comment.css"
8085
}
8186
},
8287
{
@@ -90,7 +95,8 @@
9095
"end": {
9196
"line": 6,
9297
"column": 10
93-
}
98+
},
99+
"source": "comment.css"
94100
}
95101
}
96102
],
@@ -102,7 +108,8 @@
102108
"end": {
103109
"line": 7,
104110
"column": 2
105-
}
111+
},
112+
"source": "comment.css"
106113
}
107114
},
108115
{
@@ -116,7 +123,8 @@
116123
"end": {
117124
"line": 7,
118125
"column": 10
119-
}
126+
},
127+
"source": "comment.css"
120128
}
121129
},
122130
{
@@ -130,7 +138,8 @@
130138
"end": {
131139
"line": 9,
132140
"column": 8
133-
}
141+
},
142+
"source": "comment.css"
134143
}
135144
}
136145
]

test/cases/comment.url.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"end": {
1414
"line": 1,
1515
"column": 34
16-
}
16+
},
17+
"source": "comment.url.css"
1718
}
1819
},
1920
{
@@ -27,7 +28,8 @@
2728
"end": {
2829
"line": 2,
2930
"column": 5
30-
}
31+
},
32+
"source": "comment.url.css"
3133
}
3234
},
3335
{
@@ -47,7 +49,8 @@
4749
"end": {
4850
"line": 4,
4951
"column": 12
50-
}
52+
},
53+
"source": "comment.url.css"
5154
}
5255
},
5356
{
@@ -61,7 +64,8 @@
6164
"end": {
6265
"line": 5,
6366
"column": 18
64-
}
67+
},
68+
"source": "comment.url.css"
6569
}
6670
},
6771
{
@@ -76,7 +80,8 @@
7680
"end": {
7781
"line": 6,
7882
"column": 11
79-
}
83+
},
84+
"source": "comment.url.css"
8085
}
8186
},
8287
{
@@ -90,7 +95,8 @@
9095
"end": {
9196
"line": 6,
9297
"column": 46
93-
}
98+
},
99+
"source": "comment.url.css"
94100
}
95101
}
96102
],
@@ -102,7 +108,8 @@
102108
"end": {
103109
"line": 7,
104110
"column": 2
105-
}
111+
},
112+
"source": "comment.url.css"
106113
}
107114
}
108115
]

test/cases/document.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"end": {
1919
"line": 2,
2020
"column": 17
21-
}
21+
},
22+
"source": "document.css"
2223
}
2324
},
2425
{
@@ -38,7 +39,8 @@
3839
"end": {
3940
"line": 4,
4041
"column": 20
41-
}
42+
},
43+
"source": "document.css"
4244
}
4345
},
4446
{
@@ -53,7 +55,8 @@
5355
"end": {
5456
"line": 6,
5557
"column": 3
56-
}
58+
},
59+
"source": "document.css"
5760
}
5861
}
5962
],
@@ -65,7 +68,8 @@
6568
"end": {
6669
"line": 6,
6770
"column": 4
68-
}
71+
},
72+
"source": "document.css"
6973
}
7074
}
7175
],
@@ -77,7 +81,8 @@
7781
"end": {
7882
"line": 7,
7983
"column": 2
80-
}
84+
},
85+
"source": "document.css"
8186
}
8287
}
8388
]

test/cases/import.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"end": {
1414
"line": 2,
1515
"column": 36
16-
}
16+
},
17+
"source": "import.css"
1718
}
1819
},
1920
{
@@ -27,7 +28,8 @@
2728
"end": {
2829
"line": 3,
2930
"column": 42
30-
}
31+
},
32+
"source": "import.css"
3133
}
3234
},
3335
{
@@ -41,7 +43,8 @@
4143
"end": {
4244
"line": 4,
4345
"column": 22
44-
}
46+
},
47+
"source": "import.css"
4548
}
4649
},
4750
{
@@ -55,7 +58,8 @@
5558
"end": {
5659
"line": 5,
5760
"column": 41
58-
}
61+
},
62+
"source": "import.css"
5963
}
6064
},
6165
{
@@ -69,7 +73,8 @@
6973
"end": {
7074
"line": 6,
7175
"column": 65
72-
}
76+
},
77+
"source": "import.css"
7378
}
7479
}
7580
]

test/cases/import.messed.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"end": {
1414
"line": 2,
1515
"column": 39
16-
}
16+
},
17+
"source": "import.messed.css"
1718
}
1819
},
1920
{
@@ -27,7 +28,8 @@
2728
"end": {
2829
"line": 3,
2930
"column": 44
30-
}
31+
},
32+
"source": "import.messed.css"
3133
}
3234
},
3335
{
@@ -41,7 +43,8 @@
4143
"end": {
4244
"line": 4,
4345
"column": 28
44-
}
46+
},
47+
"source": "import.messed.css"
4548
}
4649
},
4750
{
@@ -55,7 +58,8 @@
5558
"end": {
5659
"line": 5,
5760
"column": 45
58-
}
61+
},
62+
"source": "import.messed.css"
5963
}
6064
},
6165
{
@@ -69,7 +73,8 @@
6973
"end": {
7074
"line": 7,
7175
"column": 67
72-
}
76+
},
77+
"source": "import.messed.css"
7378
}
7479
}
7580
]

0 commit comments

Comments
 (0)