Lint and format src/compiler/compile/render_dom/wrappers/shared/create_debugging_comment.js

pull/8569/head
Simon Holthausen 3 years ago
parent 79bb20a09e
commit 766165d210

@ -5,46 +5,33 @@ import { regex_whitespace_characters } from '../../../../utils/patterns.js';
* @param {import('../../../Component.js').default} component * @param {import('../../../Component.js').default} component
*/ */
export default function create_debugging_comment(node, component) { export default function create_debugging_comment(node, component) {
const { locate, source } = component; const { locate, source } = component;
let c = node.start; let c = node.start;
if (node.type === 'ElseBlock') { if (node.type === 'ElseBlock') {
while (source[c - 1] !== '{') while (source[c - 1] !== '{') c -= 1;
c -= 1; while (source[c - 1] === '{') c -= 1;
while (source[c - 1] === '{') }
c -= 1;
}
/** @type {number} */ /** @type {number} */
let d; let d;
if (node.type === 'InlineComponent' || node.type === 'Element' || node.type === 'SlotTemplate') { if (node.type === 'InlineComponent' || node.type === 'Element' || node.type === 'SlotTemplate') {
if (node.children.length) { if (node.children.length) {
d = node.children[0].start; d = node.children[0].start;
while (source[d - 1] !== '>') while (source[d - 1] !== '>') d -= 1;
d -= 1; } else {
} d = node.start;
else { while (source[d] !== '>') d += 1;
d = node.start; d += 1;
while (source[d] !== '>') }
d += 1; } else if (node.type === 'Text' || node.type === 'Comment') {
d += 1; d = node.end;
} } else {
} // @ts-ignore
else if (node.type === 'Text' || node.type === 'Comment') { d = node.expression ? node.expression.node.end : c;
d = node.end; while (source[d] !== '}' && d <= source.length) d += 1;
} while (source[d] === '}') d += 1;
else { }
// @ts-ignore const start = locate(c);
d = node.expression ? node.expression.node.end : c; const loc = `(${start.line}:${start.column})`;
while (source[d] !== '}' && d <= source.length) return `${loc} ${source.slice(c, d)}`.replace(regex_whitespace_characters, ' ');
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…
Cancel
Save