diff --git a/src/compile/nodes/DebugTag.ts b/src/compile/nodes/DebugTag.ts index ac12928e58..e56eba171f 100644 --- a/src/compile/nodes/DebugTag.ts +++ b/src/compile/nodes/DebugTag.ts @@ -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; + } + `); + } } } \ No newline at end of file diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index 211ca2a349..f3fb0c530b 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -315,17 +315,15 @@ export default function mustache(parser: Parser) { }); } else if (parser.eat('@debug')) { const expression = readExpression(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); diff --git a/src/validate/html/index.ts b/src/validate/html/index.ts index ed4eaf4d38..f4f8827785 100644 --- a/src/validate/html/index.ts +++ b/src/validate/html/index.ts @@ -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`, diff --git a/test/validator/samples/redundant-debug-all/errors.json b/test/validator/samples/redundant-debug-all/errors.json new file mode 100644 index 0000000000..e7d9d783bd --- /dev/null +++ b/test/validator/samples/redundant-debug-all/errors.json @@ -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" +}] \ No newline at end of file diff --git a/test/validator/samples/redundant-debug-all/input.html b/test/validator/samples/redundant-debug-all/input.html new file mode 100644 index 0000000000..fc4f79832e --- /dev/null +++ b/test/validator/samples/redundant-debug-all/input.html @@ -0,0 +1,12 @@ +{@debug _, name} +
Hello {name}!
+ + \ No newline at end of file