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 { 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` block.builders.update.addBlock(deindent`
if (${condition}) { if (${condition}) {
const { ${identifiers} } = ctx; const { ${identifiers} } = ctx;
debugger; debugger;
} }
`); `);
}
} }
} }

@ -315,17 +315,15 @@ export default function mustache(parser: Parser) {
}); });
} else if (parser.eat('@debug')) { } else if (parser.eat('@debug')) {
const expression = readExpression(parser); const expression = readExpression(parser);
parser.allowWhitespace(); parser.allowWhitespace();
parser.eat('}', true); parser.eat('}', true);
// console.error(expression);
parser.current().children.push({ parser.current().children.push({
start, start,
end: parser.index, end: parser.index,
type: 'DebugTag', type: 'DebugTag',
expression expression,
}); });
} else { } else {
const expression = readExpression(parser); 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)) { if (validator.options.dev && isEmptyBlock(node)) {
validator.warn(node, { validator.warn(node, {
code: `empty-block`, 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