Skip to content

Commit 60aee28

Browse files
committed
add line/column
1 parent a91ba18 commit 60aee28

File tree

1 file changed

+9
-9
lines changed
  • packages/svelte/src/internal/server

1 file changed

+9
-9
lines changed

packages/svelte/src/internal/server/dev.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { current_component } from './context.js';
1010
* tag: string;
1111
* parent: null | Element;
1212
* filename: null | string;
13+
* line: number;
14+
* column: number;
1315
* }} Element
1416
*/
1517

@@ -29,14 +31,15 @@ function error_on_client(payload, message) {
2931
'which may result in content being shifted around and will likely result in a hydration mismatch.';
3032
// eslint-disable-next-line no-console
3133
console.error(message);
32-
payload.head.out += `<script>console.error(\`${message}\`)</script>`;
34+
payload.head.out += `<script>console.error(${JSON.stringify(message)})</script>`;
3335
}
3436

3537
/**
36-
* @param {string | null} file
38+
* @param {Element} element
3739
*/
38-
function print_file(file) {
39-
return file ? `(${file})` : '';
40+
function stringify(element) {
41+
if (element.filename === null) return `\`<${element.tag}>\``;
42+
return `\`<${element.tag}>\` (${element.filename}:${element.line}:${element.column})`;
4043
}
4144

4245
/**
@@ -45,10 +48,7 @@ function print_file(file) {
4548
* @param {Element} child
4649
*/
4750
function print_error(payload, parent, child) {
48-
error_on_client(
49-
payload,
50-
`<${child.tag}> ${print_file(child.filename)} is not a valid child element of <${parent.tag}> ${print_file(parent.filename)}`
51-
);
51+
error_on_client(payload, `${stringify(child)} cannot contain ${stringify(parent)}`);
5252
}
5353

5454
/**
@@ -59,7 +59,7 @@ function print_error(payload, parent, child) {
5959
*/
6060
export function push_element(payload, tag, line, column) {
6161
var filename = /** @type {import('#server').Component} */ (current_component).function.filename;
62-
var child = { tag, parent, filename };
62+
var child = { tag, parent, filename, line, column };
6363

6464
if (parent !== null && !is_tag_valid_with_parent(tag, parent.tag)) {
6565
print_error(payload, parent, child);

0 commit comments

Comments
 (0)