Skip to content

Commit ca846b4

Browse files
refactor: comment
1 parent 1554d66 commit ca846b4

File tree

8 files changed

+207
-1827
lines changed

8 files changed

+207
-1827
lines changed

package-lock.json

Lines changed: 181 additions & 1741 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"webpack": "^4.0.0"
4343
},
4444
"dependencies": {
45-
"babel-code-frame": "^6.26.0",
4645
"loader-utils": "^1.0.2",
4746
"postcss": "^7.0.2",
4847
"postcss-value-parser": "^3.3.0",

src/SyntaxError.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1-
import formatCodeFrame from 'babel-code-frame';
2-
31
export default class SyntaxError extends Error {
42
constructor(error) {
53
super(error);
64

7-
const { reason, message, line, column, source } = error;
5+
const { reason, line, column } = error;
86

97
this.name = 'SyntaxError';
10-
this.message = reason || message;
8+
this.message = reason;
119

1210
if (line && column) {
1311
this.message += ` (${line}:${column})`;
12+
}
13+
14+
const code = error.showSourceCode();
1415

15-
if (source) {
16-
this.message += `\n\n${formatCodeFrame(source, line, column)}\n`;
17-
}
16+
if (code) {
17+
this.message += `\n\n${code}\n`;
1818
}
1919

20-
Error.captureStackTrace(this, this.constructor);
20+
// We don't need stack https://github.com/postcss/postcss/blob/ebaa53640657fb028803d624395ea76a8df11cbe/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
21+
this.stack = false;
2122
}
2223
}

src/Warning.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ export default class Warning extends Error {
55
this.name = 'Warning';
66
this.message = warning.toString();
77

8-
if (Error.captureStackTrace) {
9-
Error.captureStackTrace(this, this.constructor);
10-
}
8+
// We don't need stack https://github.com/postcss/postcss/blob/ebaa53640657fb028803d624395ea76a8df11cbe/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
9+
this.stack = false;
1110
}
1211
}

src/runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable */
22

3-
// CSS (Loader) Runtime
3+
// CSS Loader (Runtime)
44
module.exports = function(useSourceMap) {
55
const list = [];
66

test/SyntaxError.test.js

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
1-
import SyntaxError from '../src/SyntaxError';
2-
31
import webpack from './helpers/compiler';
42
import { normalizeErrors } from './helpers/utils';
53

64
describe('SyntaxError', () => {
7-
test('basic', () => {
8-
expect(new SyntaxError(new Error()).toString()).toMatchSnapshot();
9-
expect(new SyntaxError(new Error('message')).toString()).toMatchSnapshot();
10-
expect(
11-
new SyntaxError(new Error('message', 'test.css')).toString()
12-
).toMatchSnapshot();
13-
expect(
14-
new SyntaxError(new Error('message', 'test.css', 100)).toString()
15-
).toMatchSnapshot();
16-
17-
const errorWithReasong = new Error();
18-
19-
errorWithReasong.reason = 'reason';
20-
21-
expect(new SyntaxError(errorWithReasong).toString()).toMatchSnapshot();
22-
23-
const errorWithLineAndColumn = new Error('message');
24-
25-
errorWithLineAndColumn.line = 1;
26-
errorWithLineAndColumn.column = 1;
27-
28-
expect(
29-
new SyntaxError(errorWithLineAndColumn).toString()
30-
).toMatchSnapshot();
31-
32-
const errorWithLineAndColumnAndSource = new Error('message');
33-
34-
errorWithLineAndColumnAndSource.line = 1;
35-
errorWithLineAndColumnAndSource.column = 1;
36-
errorWithLineAndColumnAndSource.source = '.class { invalid }';
37-
38-
expect(
39-
new SyntaxError(errorWithLineAndColumnAndSource).toString()
40-
).toMatchSnapshot();
41-
});
42-
43-
test('integration', async () => {
5+
test('basic', async () => {
446
const stats = await webpack('broken.js');
457

468
expect(normalizeErrors(stats.compilation.warnings)).toMatchSnapshot(
Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`SyntaxError basic 1`] = `"SyntaxError"`;
4-
5-
exports[`SyntaxError basic 2`] = `"SyntaxError: message"`;
6-
7-
exports[`SyntaxError basic 3`] = `"SyntaxError: message"`;
8-
9-
exports[`SyntaxError basic 4`] = `"SyntaxError: message"`;
10-
11-
exports[`SyntaxError basic 5`] = `"SyntaxError: reason"`;
12-
13-
exports[`SyntaxError basic 6`] = `"SyntaxError: message (1:1)"`;
14-
15-
exports[`SyntaxError basic 7`] = `
16-
"SyntaxError: message (1:1)
17-
18-
> 1 | .class { invalid }
19-
| ^
20-
"
21-
`;
22-
23-
exports[`SyntaxError integration: errors 1`] = `
3+
exports[`SyntaxError basic: errors 1`] = `
244
Array [
255
[ModuleBuildError: Module build failed (from \`replaced original path\`):
26-
SyntaxError: Unknown word (2:3)
6+
Unknown word (2:3)
277
28-
1 | .some {
29-
> 2 | invalid css;
30-
| ^
31-
3 | }
32-
4 |
8+
[90m 1 | [39m[33m.some[39m [33m{[39m
9+
[31m[1m>[22m[39m[90m 2 | [39m invalid css[33m;[39m
10+
[90m | [39m [31m[1m^[22m[39m
11+
[90m 3 | [39m[33m}[39m
12+
[90m 4 | [39m
3313
],
3414
]
3515
`;
3616
37-
exports[`SyntaxError integration: warnings 1`] = `Array []`;
17+
exports[`SyntaxError basic: warnings 1`] = `Array []`;

test/__snapshots__/import-option.test.js.snap

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,12 @@ exports[`import true from modules: warnings 1`] = `Array []`;
225225
exports[`import true invalid: errors 1`] = `
226226
Array [
227227
[ModuleBuildError: Module build failed (from \`replaced original path\`):
228-
SyntaxError: Unexpected format (\`replaced original path\`)
228+
Unexpected format (\`replaced original path\`)
229229
230-
> 1 | @import;
231-
| ^
232-
2 |
233-
3 | .class {
234-
4 | a: b c d;
230+
> 1 | @import;
231+
 | ^
232+
 2 | 
233+
 3 | .class {
235234
],
236235
]
237236
`;

0 commit comments

Comments
 (0)