diff --git a/src/compile/nodes/DebugTag.ts b/src/compile/nodes/DebugTag.ts index e56eba171f..7bd2742c4f 100644 --- a/src/compile/nodes/DebugTag.ts +++ b/src/compile/nodes/DebugTag.ts @@ -1,21 +1,34 @@ import Node from './shared/Node'; import Tag from './shared/Tag'; import Block from '../dom/Block'; +import Expression from './shared/Expression'; import deindent from '../../utils/deindent'; -export default class DebugTag extends Tag { +export default class DebugTag extends Node { + expression: Expression; + + constructor(compiler, parent, scope, info) { + super(compiler, parent, scope, info); + if (info.expression !== null) + // Debug when expression nodes change + this.expression = new Expression(compiler, parent, scope, info.expression); + else + // "Debug all" + this.expression = info.expression + } + build( block: Block, parentNode: string, parentNodes: string, ) { - const { dependencies } = this.expression; - // Debug all - if (dependencies.has('_')) { + if (this.expression === null) { block.builders.create.addLine('debugger;'); block.builders.update.addLine('debugger;'); } else { + const { dependencies } = this.expression; + const condition = [...dependencies].map(d => `changed.${d}`).join(' || '); const identifiers = [...dependencies].join(', '); diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index f3fb0c530b..8450074c66 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -314,7 +314,13 @@ export default function mustache(parser: Parser) { expression, }); } else if (parser.eat('@debug')) { - const expression = readExpression(parser); + let expression; + + // Implies {@debug} which indicates "debug all" + if (/\s*}/.test(parser.template[parser.index])) + expression = null; + else + expression = readExpression(parser); parser.allowWhitespace(); parser.eat('}', true); diff --git a/src/validate/html/index.ts b/src/validate/html/index.ts index f4f8827785..ed4eaf4d38 100644 --- a/src/validate/html/index.ts +++ b/src/validate/html/index.ts @@ -74,19 +74,6 @@ 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 deleted file mode 100644 index e7d9d783bd..0000000000 --- a/test/validator/samples/redundant-debug-all/errors.json +++ /dev/null @@ -1,15 +0,0 @@ -[{ - "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 deleted file mode 100644 index fc4f79832e..0000000000 --- a/test/validator/samples/redundant-debug-all/input.html +++ /dev/null @@ -1,12 +0,0 @@ -{@debug _, name} -