Skip to content

Commit

Permalink
Use PostCSS 5.2 CSS highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Sep 8, 2016
1 parent 4cd23e3 commit 39a855a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
38 changes: 13 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
var formatCodeFrame = require('babel-code-frame');
var loaderUtils = require('loader-utils');
var postcss = require('postcss');
var loaderUtils = require('loader-utils');
var postcss = require('postcss');

function formatMessage(message, loc, source) {
var formatted = message;
if (loc) {
formatted = formatted +
' (' + loc.line + ':' + loc.column + ')';
}
if (loc && source) {
formatted = formatted +
'\n\n' + formatCodeFrame(source, loc.line, loc.column) + '\n';
}
return formatted;
}

function PostCSSLoaderError(name, message, loc, source, error) {
function PostCSSLoaderError(error) {
Error.call(this);
Error.captureStackTrace(this, PostCSSLoaderError);
this.name = name;
this.error = error;
this.message = formatMessage(message, loc, source);
this.name = 'Syntax Error';
this.error = error.input.source;
this.message = error.reason;
if ( error.line ) {
this.message += ' (' + error.line + ':' + error.column + ')';
}
if ( error.line && error.input.source ) {
this.message += '\n\n' + error.showSourceCode() + '\n';
}
this.hideStack = true;
}

Expand Down Expand Up @@ -102,11 +94,7 @@ module.exports = function (source, map) {
})
.catch(function (error) {
if ( error.name === 'CssSyntaxError' ) {
callback(new PostCSSLoaderError(
'Syntax Error',
error.reason,
{ line: error.line, column: error.column },
error.input.source));
callback(new PostCSSLoaderError(error));
} else {
callback(error);
}
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
"license": "MIT",
"repository": "postcss/postcss-loader",
"dependencies": {
"babel-code-frame": "^6.11.0",
"loader-utils": "^0.2.15",
"postcss": "^5.1.2"
"loader-utils": "^0.2.15",
"postcss": "^5.2.0"
},
"devDependencies": {
"eslint-config-postcss": "2.0.2",
"postcss-safe-parser": "1.0.7",
"postcss-safe-parser": "2.0.0",
"webpack-stream": "3.2.0",
"gulp-eslint": "3.0.1",
"json-loader": "0.5.4",
Expand Down

0 comments on commit 39a855a

Please sign in to comment.