|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -var formatCodeFrame = require("babel-code-frame"); |
6 | 5 | var postcss = require("postcss"); |
7 | 6 | var plugin = require("./plugin"); |
| 7 | +var CssLoaderError = require("./CssLoaderError"); |
8 | 8 |
|
9 | 9 | module.exports = function processCss(inputSource, inputMap, options, callback) { |
10 | 10 | var query = options.query; |
@@ -41,43 +41,19 @@ module.exports = function processCss(inputSource, inputMap, options, callback) { |
41 | 41 | urlItemRegExp: /___CSS_LOADER_URL___([0-9]+)___/ |
42 | 42 | }); |
43 | 43 | }) |
44 | | - .catch(function(err) { |
45 | | - if (err.name === "CssSyntaxError") { |
46 | | - var wrappedError = new CSSLoaderError( |
47 | | - "Syntax Error", |
48 | | - err.reason, |
49 | | - err.line != null && err.column != null |
50 | | - ? { line: err.line, column: err.column } |
51 | | - : null, |
52 | | - err.input.source |
53 | | - ); |
54 | | - callback(wrappedError); |
55 | | - } else { |
56 | | - callback(err); |
57 | | - } |
| 44 | + .catch(function(error) { |
| 45 | + const preparedError = |
| 46 | + error.name === "CssSyntaxError" |
| 47 | + ? new CssLoaderError( |
| 48 | + "Syntax Error", |
| 49 | + error.reason, |
| 50 | + error.line != null && error.column != null |
| 51 | + ? { line: error.line, column: error.column } |
| 52 | + : null, |
| 53 | + error.input.source |
| 54 | + ) |
| 55 | + : error; |
| 56 | + |
| 57 | + callback(preparedError); |
58 | 58 | }); |
59 | 59 | }; |
60 | | - |
61 | | -function formatMessage(message, loc, source) { |
62 | | - var formatted = message; |
63 | | - if (loc) { |
64 | | - formatted = formatted + " (" + loc.line + ":" + loc.column + ")"; |
65 | | - } |
66 | | - if (loc && source) { |
67 | | - formatted = |
68 | | - formatted + "\n\n" + formatCodeFrame(source, loc.line, loc.column) + "\n"; |
69 | | - } |
70 | | - return formatted; |
71 | | -} |
72 | | - |
73 | | -function CSSLoaderError(name, message, loc, source, error) { |
74 | | - Error.call(this); |
75 | | - Error.captureStackTrace(this, CSSLoaderError); |
76 | | - this.name = name; |
77 | | - this.error = error; |
78 | | - this.message = formatMessage(message, loc, source); |
79 | | - this.hideStack = true; |
80 | | -} |
81 | | - |
82 | | -CSSLoaderError.prototype = Object.create(Error.prototype); |
83 | | -CSSLoaderError.prototype.constructor = CSSLoaderError; |
0 commit comments