Skip to content

Commit 39a855a

Browse files
committed
Use PostCSS 5.2 CSS highlight
1 parent 4cd23e3 commit 39a855a

File tree

2 files changed

+16
-29
lines changed

2 files changed

+16
-29
lines changed

index.js

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
var formatCodeFrame = require('babel-code-frame');
2-
var loaderUtils = require('loader-utils');
3-
var postcss = require('postcss');
1+
var loaderUtils = require('loader-utils');
2+
var postcss = require('postcss');
43

5-
function formatMessage(message, loc, source) {
6-
var formatted = message;
7-
if (loc) {
8-
formatted = formatted +
9-
' (' + loc.line + ':' + loc.column + ')';
10-
}
11-
if (loc && source) {
12-
formatted = formatted +
13-
'\n\n' + formatCodeFrame(source, loc.line, loc.column) + '\n';
14-
}
15-
return formatted;
16-
}
17-
18-
function PostCSSLoaderError(name, message, loc, source, error) {
4+
function PostCSSLoaderError(error) {
195
Error.call(this);
206
Error.captureStackTrace(this, PostCSSLoaderError);
21-
this.name = name;
22-
this.error = error;
23-
this.message = formatMessage(message, loc, source);
7+
this.name = 'Syntax Error';
8+
this.error = error.input.source;
9+
this.message = error.reason;
10+
if ( error.line ) {
11+
this.message += ' (' + error.line + ':' + error.column + ')';
12+
}
13+
if ( error.line && error.input.source ) {
14+
this.message += '\n\n' + error.showSourceCode() + '\n';
15+
}
2416
this.hideStack = true;
2517
}
2618

@@ -102,11 +94,7 @@ module.exports = function (source, map) {
10294
})
10395
.catch(function (error) {
10496
if ( error.name === 'CssSyntaxError' ) {
105-
callback(new PostCSSLoaderError(
106-
'Syntax Error',
107-
error.reason,
108-
{ line: error.line, column: error.column },
109-
error.input.source));
97+
callback(new PostCSSLoaderError(error));
11098
} else {
11199
callback(error);
112100
}

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
"license": "MIT",
88
"repository": "postcss/postcss-loader",
99
"dependencies": {
10-
"babel-code-frame": "^6.11.0",
11-
"loader-utils": "^0.2.15",
12-
"postcss": "^5.1.2"
10+
"loader-utils": "^0.2.15",
11+
"postcss": "^5.2.0"
1312
},
1413
"devDependencies": {
1514
"eslint-config-postcss": "2.0.2",
16-
"postcss-safe-parser": "1.0.7",
15+
"postcss-safe-parser": "2.0.0",
1716
"webpack-stream": "3.2.0",
1817
"gulp-eslint": "3.0.1",
1918
"json-loader": "0.5.4",

0 commit comments

Comments
 (0)