Skip to content

Commit

Permalink
Revert "rename source -> filename"
Browse files Browse the repository at this point in the history
This reverts commit 190ba98.

Conflicts:
	History.md
	Readme.md
	test/css-parse.js
  • Loading branch information
conradz committed Mar 6, 2014
1 parent 35d5931 commit 018175e
Show file tree
Hide file tree
Showing 30 changed files with 262 additions and 271 deletions.
4 changes: 0 additions & 4 deletions History.md
@@ -1,10 +1,6 @@

2.0.0 / 2014-01-24
==================

* rename source to filename
- `source` is now the CSS string
- `filename` is now the optional filename
* changed default `options.position` value to `true`
* remove comments from properties and values
* asserts when selectors are missing
Expand Down
14 changes: 7 additions & 7 deletions Readme.md
Expand Up @@ -16,8 +16,8 @@ var css = "body { \n background-color: #fff;\n }";

var output_obj = parse(css);

// Filename parameter for source mapping
var output_obj_pos = parse(css, { filename: 'file.css' });
// Source parameter to specify source file name for source maps
var output_obj_pos = parse(css, { source: 'file.css' });

// Print parsed object as CSS string
console.log(JSON.stringify(output_obj, null, 2));
Expand Down Expand Up @@ -145,17 +145,17 @@ parse tree with `.position` enabled:
}
```

If you also pass in `filename: 'path/to/original.css'`, that will be set
on `node.position.filename`.
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.

## Related

[css-stringify](https://github.com/visionmedia/css-stringify "CSS-Stringify")
[css-value](https://github.com/visionmedia/css-value "CSS-Value")
[css-stringify](https://github.com/visionmedia/css-stringify "CSS-Stringify")
[css-value](https://github.com/visionmedia/css-value "CSS-Value")

## License

Expand Down
31 changes: 13 additions & 18 deletions index.js
Expand Up @@ -29,29 +29,21 @@ module.exports = function(css, options){
*/

function position() {
if (!options.position) return positionNoop;

var start = { line: lineno, column: column };
if (!options.position) return positionNoop;

return function(node){
node.position = new Position(start);
node.position = {
start: start,
end: { line: lineno, column: column },
source: options.source
};

whitespace();
return node;
};
}

function Position(start) {
this.start = start;
this.end = { line: lineno, column: column };
this.filename = options.filename;
}

/**
* Non-enumerable source string.
*/

Position.prototype.source = css;

/**
* Return `node`.
*/
Expand All @@ -65,9 +57,12 @@ module.exports = function(css, options){
* Error `msg`.
*/

function error(msg, start) {
function error(msg) {
var err = new Error(msg + ' near line ' + lineno + ':' + column);
err.position = new Position(start);
err.filename = options.source;
err.line = lineno;
err.column = column;
err.source = css;
throw err;
}

Expand Down Expand Up @@ -183,7 +178,7 @@ module.exports = function(css, options){
function selector() {
var m = match(/^([^{]+)/);
if (!m) return;
/* @fix Remove all comments from selectors
/* @fix Remove all comments from selectors
* http://ostermiller.org/findcomment.html */
return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '').split(/\s*,\s*/);
}
Expand Down
8 changes: 4 additions & 4 deletions test/cases/charset.json
Expand Up @@ -14,7 +14,7 @@
"line": 1,
"column": 18
},
"filename": "charset.css"
"source": "charset.css"
}
},
{
Expand All @@ -29,7 +29,7 @@
"line": 1,
"column": 82
},
"filename": "charset.css"
"source": "charset.css"
}
},
{
Expand All @@ -44,7 +44,7 @@
"line": 2,
"column": 24
},
"filename": "charset.css"
"source": "charset.css"
}
},
{
Expand All @@ -59,7 +59,7 @@
"line": 2,
"column": 122
},
"filename": "charset.css"
"source": "charset.css"
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions test/cases/colon-space.json
Expand Up @@ -21,7 +21,7 @@
"line": 2,
"column": 19
},
"filename": "colon-space.css"
"source": "colon-space.css"
}
},
{
Expand All @@ -37,7 +37,7 @@
"line": 3,
"column": 16
},
"filename": "colon-space.css"
"source": "colon-space.css"
}
}
],
Expand All @@ -50,7 +50,7 @@
"line": 4,
"column": 2
},
"filename": "colon-space.css"
"source": "colon-space.css"
}
}
]
Expand Down
18 changes: 9 additions & 9 deletions test/cases/comment.json
Expand Up @@ -14,7 +14,7 @@
"line": 1,
"column": 8
},
"filename": "comment.css"
"source": "comment.css"
}
},
{
Expand All @@ -36,7 +36,7 @@
"line": 3,
"column": 44
},
"filename": "comment.css"
"source": "comment.css"
}
},
{
Expand All @@ -51,7 +51,7 @@
"line": 4,
"column": 10
},
"filename": "comment.css"
"source": "comment.css"
}
},
{
Expand All @@ -66,7 +66,7 @@
"line": 5,
"column": 7
},
"filename": "comment.css"
"source": "comment.css"
}
},
{
Expand All @@ -82,7 +82,7 @@
"line": 5,
"column": 17
},
"filename": "comment.css"
"source": "comment.css"
}
},
{
Expand All @@ -97,7 +97,7 @@
"line": 6,
"column": 10
},
"filename": "comment.css"
"source": "comment.css"
}
}
],
Expand All @@ -110,7 +110,7 @@
"line": 7,
"column": 2
},
"filename": "comment.css"
"source": "comment.css"
}
},
{
Expand All @@ -125,7 +125,7 @@
"line": 7,
"column": 10
},
"filename": "comment.css"
"source": "comment.css"
}
},
{
Expand All @@ -140,7 +140,7 @@
"line": 9,
"column": 8
},
"filename": "comment.css"
"source": "comment.css"
}
}
]
Expand Down
14 changes: 7 additions & 7 deletions test/cases/comment.url.json
Expand Up @@ -14,7 +14,7 @@
"line": 1,
"column": 34
},
"filename": "comment.url.css"
"source": "comment.url.css"
}
},
{
Expand All @@ -29,7 +29,7 @@
"line": 2,
"column": 5
},
"filename": "comment.url.css"
"source": "comment.url.css"
}
},
{
Expand All @@ -50,7 +50,7 @@
"line": 4,
"column": 12
},
"filename": "comment.url.css"
"source": "comment.url.css"
}
},
{
Expand All @@ -65,7 +65,7 @@
"line": 5,
"column": 18
},
"filename": "comment.url.css"
"source": "comment.url.css"
}
},
{
Expand All @@ -81,7 +81,7 @@
"line": 6,
"column": 11
},
"filename": "comment.url.css"
"source": "comment.url.css"
}
},
{
Expand All @@ -96,7 +96,7 @@
"line": 6,
"column": 46
},
"filename": "comment.url.css"
"source": "comment.url.css"
}
}
],
Expand All @@ -109,7 +109,7 @@
"line": 7,
"column": 2
},
"filename": "comment.url.css"
"source": "comment.url.css"
}
}
]
Expand Down
10 changes: 5 additions & 5 deletions test/cases/document.json
Expand Up @@ -19,7 +19,7 @@
"line": 2,
"column": 17
},
"filename": "document.css"
"source": "document.css"
}
},
{
Expand All @@ -40,7 +40,7 @@
"line": 4,
"column": 20
},
"filename": "document.css"
"source": "document.css"
}
},
{
Expand All @@ -56,7 +56,7 @@
"line": 6,
"column": 3
},
"filename": "document.css"
"source": "document.css"
}
}
],
Expand All @@ -69,7 +69,7 @@
"line": 6,
"column": 4
},
"filename": "document.css"
"source": "document.css"
}
}
],
Expand All @@ -82,7 +82,7 @@
"line": 7,
"column": 2
},
"filename": "document.css"
"source": "document.css"
}
}
]
Expand Down

0 comments on commit 018175e

Please sign in to comment.