0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Changes {@debug _ } to {@debug}

This commit is contained in:
Admin 2018-08-08 18:21:33 -05:00
parent 79c023e604
commit a3c71af5c5
5 changed files with 24 additions and 45 deletions

View File

@ -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(', ');

View File

@ -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);

View File

@ -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`,

View File

@ -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"
}]

View File

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