Upgrade to latest reworkcss sans the stringify module.

This commit is contained in:
Hristo Deshev
2015-10-14 11:26:52 +03:00
parent e3778dd48f
commit 4ae638f546
3 changed files with 47 additions and 28 deletions

1
css/index.js Normal file
View File

@ -0,0 +1 @@
exports.parse = require('./lib/parse');

View File

@ -2,7 +2,7 @@
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g
module.exports.parse = function(css, options){
module.exports = function(css, options){
options = options || {};
/**
@ -56,37 +56,35 @@ module.exports.parse = function(css, options){
* Error `msg`.
*/
var errorsList = [];
function error(msg) {
if (options.silent === true) {
return false;
};
var errorMessage;
if (options.source) {
errorMessage = options.source + ':' + lineno + ':' + column + ': ' + msg;
}
else {
errorMessage = "Parsing '" + css + "' issue an error: " + msg;
}
var err = new Error(errorMessage);
var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
err.reason = msg;
err.filename = options.source;
err.line = lineno;
err.column = column;
err.source = css;
if (options.silent) {
errorsList.push(err);
} else {
throw err;
}
}
/**
* Parse stylesheet.
*/
function stylesheet() {
var rulesList = rules();
return {
type: 'stylesheet',
stylesheet: {
rules: rules()
rules: rulesList,
parsingErrors: errorsList
}
};
}
@ -200,7 +198,7 @@ module.exports.parse = function(css, options){
* http://ostermiller.org/findcomment.html */
return trim(m[0])
.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
.replace(/(?:"[^"]*"|'[^']*')/g, function(m) {
.replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(m) {
return m.replace(/,/g, '\u200C');
})
.split(/\s*(?![^(]*\)),\s*/)
@ -291,7 +289,7 @@ module.exports.parse = function(css, options){
function atkeyframes() {
var pos = position();
var m = match(/^@([-\w]+)?keyframes */);
var m = match(/^@([-\w]+)?keyframes\s*/);
if (!m) return;
var vendor = m[1];
@ -350,7 +348,7 @@ module.exports.parse = function(css, options){
function athost() {
var pos = position();
var m = match(/^@host */);
var m = match(/^@host\s*/);
if (!m) return;
@ -397,7 +395,7 @@ module.exports.parse = function(css, options){
function atcustommedia() {
var pos = position();
var m = match(/^@custom-media (--[^\s]+) *([^{;]+);/);
var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
if (!m) return;
return pos({
@ -469,7 +467,7 @@ module.exports.parse = function(css, options){
function atfontface() {
var pos = position();
var m = match(/^@font-face */);
var m = match(/^@font-face\s*/);
if (!m) return;
if (!open()) return error("@font-face missing '{'");
@ -514,7 +512,7 @@ module.exports.parse = function(css, options){
function _compileAtrule(name) {
var re = new RegExp('^@' + name + ' *([^;\\n]+);');
var re = new RegExp('^@' + name + '\\s*([^;]+);');
return function() {
var pos = position();
var m = match(re);

View File

@ -1,8 +1,28 @@
{
"name": "css",
"version": "2.1.0",
"description": "CSS parser",
"main": "reworkcss.js",
"version": "2.2.1",
"description": "CSS parser / stringifier",
"main": "index",
"files": [
"index.js",
"lib"
],
"dependencies": {
"source-map": "^0.1.38",
"source-map-resolve": "^0.3.0",
"urix": "^0.1.0",
"inherits": "^2.0.1"
},
"devDependencies": {
"mocha": "^1.21.3",
"should": "^4.0.4",
"matcha": "^0.5.0",
"bytes": "^1.0.0"
},
"scripts": {
"benchmark": "matcha",
"test": "mocha --require should --reporter spec --bail test/*.js"
},
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"license": "MIT",
"repository": {