Skip to content

Commit 901bb86

Browse files
committed
handle IE-7 style, declaration name starts with * and .
1 parent 9268ce8 commit 901bb86

File tree

1 file changed

+34
-52
lines changed

1 file changed

+34
-52
lines changed

index.js

Lines changed: 34 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
// http://www.w3.org/TR/CSS21/grammar.html
2-
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
3-
var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g
41

52
module.exports = function(css, options){
63
options = options || {};
7-
options.position = options.position === false ? false : true;
84

95
/**
106
* Positional.
@@ -33,28 +29,17 @@ module.exports = function(css, options){
3329
if (!options.position) return positionNoop;
3430

3531
return function(node){
36-
node.position = new Position(start);
32+
node.position = {
33+
start: start,
34+
end: { line: lineno, column: column },
35+
source: options.source
36+
};
37+
3738
whitespace();
3839
return node;
39-
};
40-
}
41-
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;
40+
}
5041
}
5142

52-
/**
53-
* Non-enumerable source string
54-
*/
55-
56-
Position.prototype.content = css;
57-
5843
/**
5944
* Return `node`.
6045
*/
@@ -75,6 +60,7 @@ module.exports = function(css, options){
7560
err.column = column;
7661
err.source = css;
7762
throw err;
63+
// console.log(err);
7864
}
7965

8066
/**
@@ -115,7 +101,7 @@ module.exports = function(css, options){
115101
var rules = [];
116102
whitespace();
117103
comments(rules);
118-
while (css.length && css.charAt(0) != '}' && (node = atrule() || rule())) {
104+
while (css.charAt(0) != '}' && (node = atrule() || rule())) {
119105
rules.push(node);
120106
comments(rules);
121107
}
@@ -163,13 +149,9 @@ module.exports = function(css, options){
163149
if ('/' != css.charAt(0) || '*' != css.charAt(1)) return;
164150

165151
var i = 2;
166-
while ("" != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i;
152+
while (null != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i;
167153
i += 2;
168154

169-
if ("" === css.charAt(i-1)) {
170-
return error('End of comment missing');
171-
}
172-
173155
var str = css.slice(2, i - 2);
174156
column += 2;
175157
updatePosition(str);
@@ -189,9 +171,7 @@ module.exports = function(css, options){
189171
function selector() {
190172
var m = match(/^([^{]+)/);
191173
if (!m) return;
192-
/* @fix Remove all comments from selectors
193-
* http://ostermiller.org/findcomment.html */
194-
return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '').split(/\s*,\s*/);
174+
return trim(m[0]).split(/\s*,\s*/);
195175
}
196176

197177
/**
@@ -201,12 +181,12 @@ module.exports = function(css, options){
201181
function declaration() {
202182
var pos = position();
203183

204-
// prop
205-
var prop = match(/^(\*?[-#\/\*\w]+(\[[0-9a-z_-]+\])?)\s*/);
184+
// prop /* AUSTIN HACK */
185+
// var prop = match(/^(\*?\.*[-#\/\*\w]+(\[[0-9a-z_-]+\])?)\s*/);
186+
var prop = match(/^(\*?[-\.#\/\* \w]+(\[[0-9a-z_-]+\])?)\s*/);
206187
if (!prop) return;
207188
prop = trim(prop[0]);
208-
209-
// :
189+
// : /* AUSTIN HACK! */
210190
if (!match(/^:\s*/)) return error("property missing ':'");
211191

212192
// val
@@ -215,8 +195,8 @@ module.exports = function(css, options){
215195

216196
var ret = pos({
217197
type: 'declaration',
218-
property: prop.replace(commentre, ''),
219-
value: trim(val[0]).replace(commentre, '')
198+
property: prop,
199+
value: trim(val[0])
220200
});
221201

222202
// ;
@@ -434,35 +414,37 @@ module.exports = function(css, options){
434414
* Parse import
435415
*/
436416

437-
var atimport = _compileAtrule('import');
417+
function atimport() {
418+
return _atrule('import');
419+
}
438420

439421
/**
440422
* Parse charset
441423
*/
442424

443-
var atcharset = _compileAtrule('charset');
425+
function atcharset() {
426+
return _atrule('charset');
427+
}
444428

445429
/**
446430
* Parse namespace
447431
*/
448432

449-
var atnamespace = _compileAtrule('namespace');
433+
function atnamespace() {
434+
return _atrule('namespace')
435+
}
450436

451437
/**
452438
* Parse non-block at-rules
453439
*/
454440

455-
456-
function _compileAtrule(name) {
457-
var re = new RegExp('^@' + name + ' *([^;\\n]+);');
458-
return function() {
459-
var pos = position();
460-
var m = match(re);
461-
if (!m) return;
462-
var ret = { type: name };
463-
ret[name] = m[1].trim();
464-
return pos(ret);
465-
}
441+
function _atrule(name) {
442+
var pos = position();
443+
var m = match(new RegExp('^@' + name + ' *([^;\\n]+);'));
444+
if (!m) return;
445+
var ret = { type: name };
446+
ret[name] = trim(m[1]);
447+
return pos(ret);
466448
}
467449

468450
/**
@@ -491,7 +473,7 @@ module.exports = function(css, options){
491473
var pos = position();
492474
var sel = selector();
493475

494-
if (!sel) return error('selector missing');
476+
if (!sel) return;
495477
comments();
496478

497479
return pos({

0 commit comments

Comments
 (0)