@marko/compiler 5.30.1 → 5.30.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,13 +6,7 @@ class MarkoFile extends _core.File {
6
6
  throw new Error("addHelper is not supported during a Marko transform");
7
7
  }
8
8
 
9
- buildCodeFrameError(node, msg, Error) {
10
- return (0, _buildCodeFrame.buildCodeFrameError)(
11
- this.opts.filename,
12
- this.code,
13
- node.loc,
14
- msg,
15
- Error);
16
-
9
+ buildCodeFrameError(node, msg) {
10
+ return (0, _buildCodeFrame.buildCodeFrameError)(this.opts.filename, this.code, node.loc, msg);
17
11
  }
18
12
  }exports.MarkoFile = MarkoFile;
@@ -2,38 +2,61 @@
2
2
  var _kleur = _interopRequireDefault(require("kleur"));
3
3
  var _codeFrame = require("@babel/code-frame");
4
4
  const CWD = process.cwd();
5
+ const indent = " ";
5
6
 
6
- function buildCodeFrameError(
7
- filename,
8
- code,
9
- loc,
10
- message,
11
- Error = SyntaxError)
12
- {
13
- const err = new Error();
14
- const codeFrame = buildCodeFrame(filename, code, loc, message);
7
+ class CompileError extends Error {
8
+ constructor(filename, code, loc, message) {
9
+ super();
10
+ const prettyMessage = buildMessage(code, loc, message);
11
+ const prettyFileName = buildFileName(filename, loc);
12
+ this.stack = loc ?
13
+ `CompileError\n${indent}at ${prettyFileName}\n${prettyMessage.replace(
14
+ /^/gm,
15
+ indent)
16
+ }` :
17
+ `CompileError: ${prettyMessage}\n${indent}at ${prettyFileName}`;
15
18
 
16
- err.loc = loc;
17
- err.label = message;
18
- err.stack = ""; // Avoid showing the stack trace for this error.
19
-
20
- // Prevent babel from changing our error message.
21
- Object.defineProperty(err, "message", {
22
- get() {
23
- return codeFrame;
24
- },
25
- set() {}
26
- });
19
+ Object.defineProperties(this, {
20
+ loc: {
21
+ value: loc,
22
+ enumerable: false,
23
+ writable: true,
24
+ configurable: true
25
+ },
26
+ label: {
27
+ value: message,
28
+ enumerable: false,
29
+ writable: true,
30
+ configurable: true
31
+ },
32
+ // Ignore some mutations from Babel.
33
+ code: {
34
+ enumerable: false,
35
+ configurable: true,
36
+ get() {
37
+ return undefined;
38
+ },
39
+ set() {}
40
+ },
41
+ message: {
42
+ configurable: true,
43
+ enumerable: false,
44
+ get() {
45
+ return `${prettyFileName}: ${message}`;
46
+ },
47
+ set() {}
48
+ }
49
+ });
50
+ }
51
+ }
27
52
 
28
- return err;
53
+ function buildCodeFrameError(filename, code, loc, message) {
54
+ return new CompileError(filename, code, loc, message);
29
55
  }
30
56
 
31
- function buildCodeFrame(filename, code, loc, message) {
32
- return `${_kleur.default.cyan(_path.default.relative(CWD, filename))}${
33
- loc ?
34
- `:${_kleur.default.yellow(loc.start.line)}:${_kleur.default.yellow(
35
- loc.start.column + 1)
36
- }\n\n${(0, _codeFrame.codeFrameColumns)(
57
+ function buildMessage(code, loc, message) {
58
+ return loc ?
59
+ (0, _codeFrame.codeFrameColumns)(
37
60
  code,
38
61
  {
39
62
  start: {
@@ -48,8 +71,15 @@ function buildCodeFrame(filename, code, loc, message) {
48
71
  } :
49
72
  undefined
50
73
  },
51
- { highlightCode: true, message })
52
- }` :
53
- `: ${message}`
74
+ { highlightCode: true, message }) :
75
+
76
+ message;
77
+ }
78
+
79
+ function buildFileName(filename, loc) {
80
+ return `${_kleur.default.cyan(_path.default.relative(CWD, filename))}${
81
+ loc ?
82
+ `:${_kleur.default.yellow(loc.start.line)}:${_kleur.default.yellow(loc.start.column + 1)}` :
83
+ ""
54
84
  }`;
55
85
  }
@@ -1,5 +1,6 @@
1
- "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = throwAggregateError;var _kleur = _interopRequireDefault(require("kleur"));
2
-
1
+ "use strict";exports.__esModule = true;exports.default = throwAggregateError;const indent = " ";
2
+ const compileErrorPrefix = `SyntaxError\n`;
3
+ const compileErrorStackTracePrefix = `${compileErrorPrefix + indent}at `;
3
4
  function throwAggregateError(errors) {
4
5
  switch (errors.length) {
5
6
  case 0:
@@ -8,21 +9,20 @@ function throwAggregateError(errors) {
8
9
  throw errors[0];}
9
10
 
10
11
 
11
- let err;
12
- const message = `${_kleur.default.red("AggregationError:")}\n${errors.
13
- map((err) => err.message).
14
- join("\n\n").
15
- replace(/^(?!\s*$)/gm, "\t")}\n`;
12
+ throw new CompileErrors(errors);
13
+ }
16
14
 
17
- if (typeof AggregateError === "function") {
18
- err = new AggregateError(errors, message);
19
- } else {
20
- err = new Error(message);
21
- err.name = "AggregateError";
22
- err.errors = errors;
15
+ class CompileErrors extends Error {
16
+ constructor(errors) {
17
+ super();
18
+ this.errors = errors;
19
+ this.stack = `CompileErrors\n${errors.
20
+ map(({ stack }) => {
21
+ if (stack.startsWith(compileErrorStackTracePrefix)) {
22
+ return stack.slice(compileErrorPrefix.length);
23
+ }
24
+ return stack.replace(/^(?!\s*$)/gm, " ");
25
+ }).
26
+ join("\n\n")}`;
23
27
  }
24
-
25
- // Remove the stack trace from the error since it is not useful.
26
- err.stack = "";
27
- throw err;
28
28
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/compiler",
3
3
  "description": "Marko template to JS compiler.",
4
- "version": "5.30.1",
4
+ "version": "5.30.3",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md",
7
7
  "dependencies": {
@@ -30,7 +30,7 @@
30
30
  "strip-json-comments": "^3.1.1"
31
31
  },
32
32
  "devDependencies": {
33
- "@marko/translator-default": "^5.28.1"
33
+ "@marko/translator-default": "^5.28.3"
34
34
  },
35
35
  "files": [
36
36
  "dist",