Skip to content

Commit c5d5790

Browse files
committed
remove comments from properties and values
refactored from #49. closes #49.
1 parent ef3ae80 commit c5d5790

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- `source` is now the CSS string
66
- `filename` is now the optional filename
77
* changed default `options.position` value to `true`
8+
* remove comments from properties and values
89

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

index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// http://www.w3.org/TR/CSS21/grammar.html
2+
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
3+
var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g
4+
15
module.exports = function(css, options){
26
options = options || {};
37
options.position = options.position === false ? false : true;
@@ -201,8 +205,8 @@ module.exports = function(css, options){
201205

202206
var ret = pos({
203207
type: 'declaration',
204-
property: prop,
205-
value: trim(val[0])
208+
property: prop.replace(commentre, ''),
209+
value: trim(val[0]).replace(commentre, '')
206210
});
207211

208212
// ;

test/cases/comment.in.css

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a {
2+
color/**/: 12px;
3+
padding/*4815162342*/: 1px /**/ 2px /*13*/ 3px;
4+
}

test/cases/comment.in.json

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"type": "stylesheet",
3+
"stylesheet": {
4+
"rules": [
5+
{
6+
"type": "rule",
7+
"selectors": [
8+
"a"
9+
],
10+
"declarations": [
11+
{
12+
"type": "declaration",
13+
"property": "color",
14+
"value": "12px",
15+
"position": {
16+
"start": {
17+
"line": 2,
18+
"column": 5
19+
},
20+
"end": {
21+
"line": 2,
22+
"column": 20
23+
},
24+
"filename": "comment.in.css"
25+
}
26+
},
27+
{
28+
"type": "declaration",
29+
"property": "padding",
30+
"value": "1px 2px 3px",
31+
"position": {
32+
"start": {
33+
"line": 3,
34+
"column": 5
35+
},
36+
"end": {
37+
"line": 3,
38+
"column": 51
39+
},
40+
"filename": "comment.in.css"
41+
}
42+
}
43+
],
44+
"position": {
45+
"start": {
46+
"line": 1,
47+
"column": 1
48+
},
49+
"end": {
50+
"line": 4,
51+
"column": 2
52+
},
53+
"filename": "comment.in.css"
54+
}
55+
}
56+
]
57+
}
58+
}

0 commit comments

Comments
 (0)