@marko/compiler 5.34.4 → 5.34.6

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.
@@ -132,11 +132,13 @@ const SOURCE_FILES = new WeakMap();var _default =
132
132
  },
133
133
  ExportNamedDeclaration: {
134
134
  exit(path) {
135
+ const { node } = path;
135
136
  // The babel typescript plugin will add an empty export declaration
136
137
  // if there are no other imports/exports in the file.
137
138
  // This is not needed for Marko file outputs since there is always
138
139
  // a default export.
139
- if (path.node.specifiers.length === 0) path.remove();
140
+ if (!(node.declaration || node.specifiers.length))
141
+ path.remove();
140
142
  }
141
143
  }
142
144
  } :
@@ -1,21 +1,25 @@
1
1
  "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.buildCodeFrameError = buildCodeFrameError;var _path = _interopRequireDefault(require("path"));
2
2
  var _codeFrame = require("@babel/code-frame");
3
3
  var _kleur = _interopRequireDefault(require("kleur"));
4
+ var _stripAnsi = require("./strip-ansi");
4
5
  const CWD = process.cwd();
5
6
  const indent = " ";
6
7
 
7
8
  class CompileError extends Error {
8
- constructor(filename, code, loc, message) {
9
- super();
10
- const prettyMessage = buildMessage(code, loc, message);
9
+ constructor(filename, code, loc, label) {
10
+ const prettyMessage = buildMessage(code, loc, label);
11
11
  const prettyFileName = buildFileName(filename, loc);
12
- this.stack = loc ?
13
- `CompileError\n${indent}at ${prettyFileName}\n${prettyMessage.replace(
12
+ const message = loc ?
13
+ `\n${indent}at ${prettyFileName}\n${prettyMessage.replace(
14
14
  /^/gm,
15
15
  indent
16
16
  )}` :
17
- `CompileError: ${prettyMessage}\n${indent}at ${prettyFileName}`;
18
-
17
+ `${prettyMessage}\n${indent}at ${prettyFileName}`;
18
+ const { stackTraceLimit } = Error;
19
+ Error.stackTraceLimit = 0;
20
+ super(message);
21
+ this.name = "CompileError";
22
+ Error.stackTraceLimit = stackTraceLimit;
19
23
  Object.defineProperties(this, {
20
24
  loc: {
21
25
  value: loc,
@@ -24,7 +28,7 @@ class CompileError extends Error {
24
28
  configurable: true
25
29
  },
26
30
  label: {
27
- value: message,
31
+ value: label,
28
32
  enumerable: false,
29
33
  writable: true,
30
34
  configurable: true
@@ -33,25 +37,38 @@ class CompileError extends Error {
33
37
  code: {
34
38
  enumerable: false,
35
39
  configurable: true,
36
- get() {
37
- return undefined;
38
- },
39
- set() {}
40
+ get: noop,
41
+ set: noop
40
42
  },
41
43
  message: {
44
+ enumerable: true,
42
45
  configurable: true,
43
- enumerable: false,
44
46
  get() {
45
- return `${prettyFileName}: ${message}`;
47
+ return message;
46
48
  },
47
- set() {}
49
+ set() {
50
+ Object.defineProperty(this, "message", {
51
+ value: message,
52
+ enumerable: true,
53
+ writable: true,
54
+ configurable: true
55
+ });
56
+ }
48
57
  }
49
58
  });
50
59
  }
60
+
61
+ toJSON() {
62
+ return this.toString();
63
+ }
64
+
65
+ toString() {
66
+ return `${this.name}: ${(0, _stripAnsi.stripAnsi)(this.message)}`;
67
+ }
51
68
  }
52
69
 
53
- function buildCodeFrameError(filename, code, loc, message) {
54
- return new CompileError(filename, code, loc, message);
70
+ function buildCodeFrameError(filename, code, loc, label) {
71
+ return new CompileError(filename, code, loc, label);
55
72
  }
56
73
 
57
74
  function buildMessage(code, loc, message) {
@@ -82,4 +99,6 @@ function buildFileName(filename, loc) {
82
99
  `:${_kleur.default.yellow(loc.start.line)}:${_kleur.default.yellow(loc.start.column + 1)}` :
83
100
  ""
84
101
  }`;
85
- }
102
+ }
103
+
104
+ function noop() {}
@@ -1,5 +1,7 @@
1
- "use strict";exports.__esModule = true;exports.default = throwAggregateError;const indent = " ";
2
- const compileErrorPrefix = `SyntaxError\n`;
1
+ "use strict";exports.__esModule = true;exports.default = throwAggregateError;var _stripAnsi = require("./strip-ansi");
2
+
3
+ const indent = " ";
4
+ const compileErrorPrefix = `CompileError: \n`;
3
5
  const compileErrorStackTracePrefix = `${compileErrorPrefix + indent}at `;
4
6
  function throwAggregateError(errors) {
5
7
  switch (errors.length) {
@@ -14,9 +16,7 @@ function throwAggregateError(errors) {
14
16
 
15
17
  class CompileErrors extends Error {
16
18
  constructor(errors) {
17
- super();
18
- this.errors = errors;
19
- this.stack = `CompileErrors\n${errors.
19
+ const message = `\n${errors.
20
20
  map(({ stack }) => {
21
21
  if (stack.startsWith(compileErrorStackTracePrefix)) {
22
22
  return stack.slice(compileErrorPrefix.length);
@@ -24,5 +24,19 @@ class CompileErrors extends Error {
24
24
  return stack.replace(/^(?!\s*$)/gm, " ");
25
25
  }).
26
26
  join("\n\n")}`;
27
+ const { stackTraceLimit } = Error;
28
+ Error.stackTraceLimit = 0;
29
+ super(message);
30
+ this.name = "CompileErrors";
31
+ this.errors = errors;
32
+ Error.stackTraceLimit = stackTraceLimit;
33
+ }
34
+
35
+ toJSON() {
36
+ return this.toString();
37
+ }
38
+
39
+ toString() {
40
+ return `${this.name}: ${(0, _stripAnsi.stripAnsi)(this.message)}`;
27
41
  }
28
42
  }
@@ -0,0 +1,7 @@
1
+ "use strict";exports.__esModule = true;exports.stripAnsi = stripAnsi;const ansiReg =
2
+ // eslint-disable-next-line no-control-regex
3
+ /([\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><])/g;
4
+
5
+ function stripAnsi(str) {
6
+ return str.replace(ansiReg, "");
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marko/compiler",
3
- "version": "5.34.4",
3
+ "version": "5.34.6",
4
4
  "description": "Marko template to JS compiler.",
5
5
  "keywords": [
6
6
  "babel",
@@ -60,7 +60,7 @@
60
60
  "source-map-support": "^0.5.21"
61
61
  },
62
62
  "devDependencies": {
63
- "@marko/translator-default": "^5.31.11"
63
+ "@marko/translator-default": "^5.31.13"
64
64
  },
65
65
  "publishConfig": {
66
66
  "access": "public"