mirror of https://github.com/sveltejs/svelte
pull/8569/head
parent
00c69ab317
commit
c01d8427bc
@ -1,38 +1,50 @@
|
||||
import Component from '../../../Component';
|
||||
import { INode } from '../../../nodes/interfaces';
|
||||
import { regex_whitespace_characters } from '../../../../utils/patterns';
|
||||
import { regex_whitespace_characters } from '../../../../utils/patterns.js';
|
||||
|
||||
export default function create_debugging_comment(node: INode, component: Component) {
|
||||
/**
|
||||
* @param {import('../../../nodes/interfaces.js').INode} node
|
||||
* @param {import('../../../Component.js').default} component
|
||||
*/
|
||||
export default function create_debugging_comment(node, component) {
|
||||
const { locate, source } = component;
|
||||
|
||||
let c = node.start;
|
||||
if (node.type === 'ElseBlock') {
|
||||
while (source[c - 1] !== '{') c -= 1;
|
||||
while (source[c - 1] === '{') c -= 1;
|
||||
while (source[c - 1] !== '{')
|
||||
c -= 1;
|
||||
while (source[c - 1] === '{')
|
||||
c -= 1;
|
||||
}
|
||||
|
||||
let d: number;
|
||||
|
||||
/** @type {number} */
|
||||
let d;
|
||||
if (node.type === 'InlineComponent' || node.type === 'Element' || node.type === 'SlotTemplate') {
|
||||
if (node.children.length) {
|
||||
d = node.children[0].start;
|
||||
while (source[d - 1] !== '>') d -= 1;
|
||||
} else {
|
||||
while (source[d - 1] !== '>')
|
||||
d -= 1;
|
||||
}
|
||||
else {
|
||||
d = node.start;
|
||||
while (source[d] !== '>') d += 1;
|
||||
while (source[d] !== '>')
|
||||
d += 1;
|
||||
d += 1;
|
||||
}
|
||||
} else if (node.type === 'Text' || node.type === 'Comment') {
|
||||
}
|
||||
else if (node.type === 'Text' || node.type === 'Comment') {
|
||||
d = node.end;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// @ts-ignore
|
||||
d = node.expression ? node.expression.node.end : c;
|
||||
while (source[d] !== '}' && d <= source.length) d += 1;
|
||||
while (source[d] === '}') d += 1;
|
||||
while (source[d] !== '}' && d <= source.length)
|
||||
d += 1;
|
||||
while (source[d] === '}')
|
||||
d += 1;
|
||||
}
|
||||
|
||||
const start = locate(c);
|
||||
const loc = `(${start.line}:${start.column})`;
|
||||
|
||||
return `${loc} ${source.slice(c, d)}`.replace(regex_whitespace_characters, ' ');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in new issue