Skip to content

Commit

Permalink
Merge branch 'main' into merge-x
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Jan 22, 2024
2 parents ace9e86 + 0814254 commit 53c61ee
Show file tree
Hide file tree
Showing 367 changed files with 565 additions and 463 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions packages/compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## 5.34.6

### Patch Changes

- [#2085](https://github.com/marko-js/marko/pull/2085) [`d82b21e`](https://github.com/marko-js/marko/commit/d82b21e8f505c5006d3781cf9056743dd9972fe1) Thanks [@DylanPiercey](https://github.com/DylanPiercey)! - Improve compile error output.

## 5.34.5

### Patch Changes

- [#2079](https://github.com/marko-js/marko/pull/2079) [`2976dfa`](https://github.com/marko-js/marko/commit/2976dfac56c592dfd80ea79c6ea0e1389346f44c) Thanks [@DylanPiercey](https://github.com/DylanPiercey)! - Fix issue where additional exports were being removed when stripping typescript types.

## 5.34.4

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marko/compiler",
"version": "5.34.4",
"version": "5.34.6",
"description": "Marko template to JS compiler.",
"keywords": [
"babel",
Expand Down Expand Up @@ -60,7 +60,7 @@
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@marko/translator-default": "^5.31.11"
"@marko/translator-default": "^5.31.13"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler/src/babel-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ export default (api, markoOpts) => {
},
ExportNamedDeclaration: {
exit(path) {
const { node } = path;
// The babel typescript plugin will add an empty export declaration
// if there are no other imports/exports in the file.
// This is not needed for Marko file outputs since there is always
// a default export.
if (path.node.specifiers.length === 0) path.remove();
if (!(node.declaration || node.specifiers.length))
path.remove();
},
},
}
Expand Down
53 changes: 36 additions & 17 deletions packages/compiler/src/util/build-code-frame.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import path from "path";
import { codeFrameColumns } from "@babel/code-frame";
import color from "kleur";
import { stripAnsi } from "./strip-ansi";
const CWD = process.cwd();
const indent = " ";

class CompileError extends Error {
constructor(filename, code, loc, message) {
super();
const prettyMessage = buildMessage(code, loc, message);
constructor(filename, code, loc, label) {
const prettyMessage = buildMessage(code, loc, label);
const prettyFileName = buildFileName(filename, loc);
this.stack = loc
? `CompileError\n${indent}at ${prettyFileName}\n${prettyMessage.replace(
const message = loc
? `\n${indent}at ${prettyFileName}\n${prettyMessage.replace(
/^/gm,
indent,
)}`
: `CompileError: ${prettyMessage}\n${indent}at ${prettyFileName}`;

: `${prettyMessage}\n${indent}at ${prettyFileName}`;
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
super(message);
this.name = "CompileError";
Error.stackTraceLimit = stackTraceLimit;
Object.defineProperties(this, {
loc: {
value: loc,
Expand All @@ -24,7 +28,7 @@ class CompileError extends Error {
configurable: true,
},
label: {
value: message,
value: label,
enumerable: false,
writable: true,
configurable: true,
Expand All @@ -33,25 +37,38 @@ class CompileError extends Error {
code: {
enumerable: false,
configurable: true,
get() {
return undefined;
},
set() {},
get: noop,
set: noop,
},
message: {
enumerable: true,
configurable: true,
enumerable: false,
get() {
return `${prettyFileName}: ${message}`;
return message;
},
set() {
Object.defineProperty(this, "message", {
value: message,
enumerable: true,
writable: true,
configurable: true,
});
},
set() {},
},
});
}

toJSON() {
return this.toString();
}

toString() {
return `${this.name}: ${stripAnsi(this.message)}`;
}
}

export function buildCodeFrameError(filename, code, loc, message) {
return new CompileError(filename, code, loc, message);
export function buildCodeFrameError(filename, code, loc, label) {
return new CompileError(filename, code, loc, label);
}

function buildMessage(code, loc, message) {
Expand Down Expand Up @@ -83,3 +100,5 @@ function buildFileName(filename, loc) {
: ""
}`;
}

function noop() {}
22 changes: 18 additions & 4 deletions packages/compiler/src/util/merge-errors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { stripAnsi } from "./strip-ansi";

const indent = " ";
const compileErrorPrefix = `SyntaxError\n`;
const compileErrorPrefix = `CompileError: \n`;
const compileErrorStackTracePrefix = `${compileErrorPrefix + indent}at `;
export default function throwAggregateError(errors) {
switch (errors.length) {
Expand All @@ -14,15 +16,27 @@ export default function throwAggregateError(errors) {

class CompileErrors extends Error {
constructor(errors) {
super();
this.errors = errors;
this.stack = `CompileErrors\n${errors
const message = `\n${errors
.map(({ stack }) => {
if (stack.startsWith(compileErrorStackTracePrefix)) {
return stack.slice(compileErrorPrefix.length);
}
return stack.replace(/^(?!\s*$)/gm, " ");
})
.join("\n\n")}`;
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
super(message);
this.name = "CompileErrors";
this.errors = errors;
Error.stackTraceLimit = stackTraceLimit;
}

toJSON() {
return this.toString();
}

toString() {
return `${this.name}: ${stripAnsi(this.message)}`;
}
}
7 changes: 7 additions & 0 deletions packages/compiler/src/util/strip-ansi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const ansiReg =
// eslint-disable-next-line no-control-regex
/([\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><])/g;

export function stripAnsi(str) {
return str.replace(ansiReg, "");
}
20 changes: 20 additions & 0 deletions packages/marko/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Change Log

## 5.32.7

### Patch Changes

- [#2085](https://github.com/marko-js/marko/pull/2085) [`d82b21e`](https://github.com/marko-js/marko/commit/d82b21e8f505c5006d3781cf9056743dd9972fe1) Thanks [@DylanPiercey](https://github.com/DylanPiercey)! - Improve compile error output.

- Updated dependencies [[`d82b21e`](https://github.com/marko-js/marko/commit/d82b21e8f505c5006d3781cf9056743dd9972fe1)]:
- @marko/translator-default@5.31.13
- @marko/compiler@5.34.6

## 5.32.6

### Patch Changes

- [#2079](https://github.com/marko-js/marko/pull/2079) [`2976dfa`](https://github.com/marko-js/marko/commit/2976dfac56c592dfd80ea79c6ea0e1389346f44c) Thanks [@DylanPiercey](https://github.com/DylanPiercey)! - Fix issue where additional exports were being removed when stripping typescript types.

- Updated dependencies [[`2976dfa`](https://github.com/marko-js/marko/commit/2976dfac56c592dfd80ea79c6ea0e1389346f44c)]:
- @marko/compiler@5.34.5
- @marko/translator-default@5.31.12

## 5.32.5

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/marko/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marko",
"version": "5.32.5",
"version": "5.32.7",
"description": "UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.",
"keywords": [
"front-end",
Expand Down Expand Up @@ -64,8 +64,8 @@
"build": "babel ./src --out-dir ./dist --delete-dir-on-start --copy-files --config-file ../../babel.config.js --env-name=production"
},
"dependencies": {
"@marko/compiler": "^5.34.4",
"@marko/translator-default": "^5.31.11",
"@marko/compiler": "^5.34.6",
"@marko/translator-default": "^5.31.13",
"app-module-path": "^2.2.0",
"argly": "^1.2.0",
"browser-refresh-client": "1.1.4",
Expand Down
12 changes: 12 additions & 0 deletions packages/translator-default/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## 5.31.13

### Patch Changes

- [#2085](https://github.com/marko-js/marko/pull/2085) [`d82b21e`](https://github.com/marko-js/marko/commit/d82b21e8f505c5006d3781cf9056743dd9972fe1) Thanks [@DylanPiercey](https://github.com/DylanPiercey)! - Improve compile error output.

## 5.31.12

### Patch Changes

- [#2079](https://github.com/marko-js/marko/pull/2079) [`2976dfa`](https://github.com/marko-js/marko/commit/2976dfac56c592dfd80ea79c6ea0e1389346f44c) Thanks [@DylanPiercey](https://github.com/DylanPiercey)! - Fix issue where additional exports were being removed when stripping typescript types.

## 5.31.11

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/translator-default/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marko/translator-default",
"version": "5.31.11",
"version": "5.31.13",
"description": "Translates Marko templates to the default Marko runtime.",
"keywords": [
"babel",
Expand Down Expand Up @@ -34,8 +34,8 @@
"self-closing-tags": "^1.0.1"
},
"devDependencies": {
"@marko/compiler": "^5.34.4",
"marko": "^5.32.5"
"@marko/compiler": "^5.34.6",
"marko": "^5.32.7"
},
"peerDependencies": {
"@marko/compiler": "^5.16.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-arguments-on-non-event-attribute/template.marko:1:6
> 1 | <div hello('a')/>
| ^^^^^^^^^^ Unsupported arguments on the "hello" attribute.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-arguments-on-non-event-attribute/template.marko:1:6
> 1 | <div hello('a')/>
| ^^^^^^^^^^ Unsupported arguments on the "hello" attribute.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-arguments-on-non-event-attribute/template.marko:1:6
> 1 | <div hello('a')/>
| ^^^^^^^^^^ Unsupported arguments on the "hello" attribute.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-arguments-on-non-event-attribute/template.marko:1:6
> 1 | <div hello('a')/>
| ^^^^^^^^^^ Unsupported arguments on the "hello" attribute.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-arguments-on-non-event-attribute/template.marko:1:6
> 1 | <div hello('a')/>
| ^^^^^^^^^^ Unsupported arguments on the "hello" attribute.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-at-tags-native-tag-parent/template.marko:9:6
7 | Body content
8 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-at-tags-native-tag-parent/template.marko:9:6
7 | Body content
8 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-at-tags-native-tag-parent/template.marko:9:6
7 | Body content
8 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-at-tags-native-tag-parent/template.marko:9:6
7 | Body content
8 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-at-tags-native-tag-parent/template.marko:9:6
7 | Body content
8 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CompileError
CompileError:
at packages/translator-default/test/fixtures/error-at-tags-top-level/template.marko:1:2
> 1 | <@header class="my-header">
| ^^^^^^^ @tags must be nested within another element.
Expand Down
Loading

0 comments on commit 53c61ee

Please sign in to comment.