Adds debug all option to debug tag

pull/1640/head
Admin 6 years ago
parent 7e5f008a78
commit 622e7b0190

@ -11,15 +11,21 @@ export default class DebugTag extends Tag {
) {
const { dependencies } = this.expression;
const condition = [...dependencies].map(d => `changed.${d}`).join(' || ');
// Debug all
if (dependencies.has('_')) {
block.builders.create.addLine('debugger;');
block.builders.update.addLine('debugger;');
} else {
const condition = [...dependencies].map(d => `changed.${d}`).join(' || ');
const identifiers = [...dependencies].join(', ');
const identifiers = [...dependencies].join(', ');
block.builders.update.addBlock(deindent`
if (${condition}) {
const { ${identifiers} } = ctx;
debugger;
}
`);
block.builders.update.addBlock(deindent`
if (${condition}) {
const { ${identifiers} } = ctx;
debugger;
}
`);
}
}
}

@ -319,13 +319,11 @@ export default function mustache(parser: Parser) {
parser.allowWhitespace();
parser.eat('}', true);
// console.error(expression);
parser.current().children.push({
start,
end: parser.index,
type: 'DebugTag',
expression
expression,
});
} else {
const expression = readExpression(parser);

@ -74,6 +74,19 @@ export default function validateHtml(validator: Validator, html: Node) {
});
}
else if (node.type === 'DebugTag') {
// Only allow the `_` expression if it's by itself
// i.e. {@debug _, name } is redundantredundant-debug-all
const names = node.expression.expressions.map(e => e.name);
if (names.length > 0 && names.includes('_')) {
validator.error(node, {
code: 'redundant-debug-all',
message: `Combining other expressions with '_' is redundant`
});
}
}
if (validator.options.dev && isEmptyBlock(node)) {
validator.warn(node, {
code: `empty-block`,

@ -0,0 +1,15 @@
[{
"message": "Combining other expressions with '_' is redundant",
"start": {
"line": 1,
"column": 0,
"character": 0
},
"end":{
"line": 1,
"column": 16,
"character": 16
},
"pos": 0,
"code": "redundant-debug-all"
}]

@ -0,0 +1,12 @@
{@debug _, name}
<div>Hello {name}!</div>
<script>
export default {
data() {
return {
name: 'World'
}
}
}
</script>
Loading…
Cancel
Save