|
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'); |
4 | 3 |
|
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) { |
19 | 5 | Error.call(this); |
20 | 6 | 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 | + } |
24 | 16 | this.hideStack = true; |
25 | 17 | } |
26 | 18 |
|
@@ -102,11 +94,7 @@ module.exports = function (source, map) { |
102 | 94 | }) |
103 | 95 | .catch(function (error) { |
104 | 96 | 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)); |
110 | 98 | } else { |
111 | 99 | callback(error); |
112 | 100 | } |
|
0 commit comments