diff --git a/lib/postcssToCsso.js b/lib/postcssToCsso.js index 0f084ba..fbf3c33 100644 --- a/lib/postcssToCsso.js +++ b/lib/postcssToCsso.js @@ -21,9 +21,19 @@ function getInfo(node) { } function parseToCsso(str, context, node) { - var cssoNode = parse(str, { - context: context - }); + var cssoNode; + + try { + cssoNode = parse(str, { + context: context + }); + } catch (e) { + if (e.name === 'CssSyntaxError') { + throw node.error(e.message, { index: e.parseError.offset }); + } + + throw e; + } cssoNode.info = getInfo(node); @@ -69,8 +79,7 @@ function postcssToCsso(node) { case 'decl': return parseToCsso( (node.raws.before || '').trimLeft() + - node.prop + ':' + node.value + - (node.important ? '!important' : ''), + node.toString(), 'declaration', node ); diff --git a/package.json b/package.json index 02e4806..af77bf9 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "travis": "npm run codestyle-and-test" }, "dependencies": { - "csso": "^2.0.0", + "csso": "^2.1.0", "postcss": "^5.0.0" }, "devDependencies": { diff --git a/test.js b/test.js index dd75466..00c62a0 100644 --- a/test.js +++ b/test.js @@ -111,6 +111,18 @@ it('should keep the shape of original postcss nodes', function() { }); }); +it('error handling', function() { + return postcss([ + postcssCsso + ]).process('.test { color: * }').then(function() { + assert(false, 'shouldn\'t to be successful'); + }, function(error) { + assert.equal(error.name, 'CssSyntaxError'); + assert.equal(error.line, 1); + assert.equal(error.column, 16); + }); +}); + // currently works only is used as linked package // TODO: find the way to use csso compress tests try {