diff --git a/src/compiler/compile/nodes/Binding.ts b/src/compiler/compile/nodes/Binding.ts index f826df4828..71e51960db 100644 --- a/src/compiler/compile/nodes/Binding.ts +++ b/src/compiler/compile/nodes/Binding.ts @@ -101,11 +101,10 @@ export default class Binding extends Node { validate_binding_rest_properties(scope: TemplateScope) { this.expression.references.forEach(name => { const each_block = scope.get_owner(name); - if (each_block && each_block.type === 'EachBlock') { - const rest_node = each_block.context_rest_properties.get(name); - if (rest_node) { - this.component.warn(rest_node as any, compiler_warnings.invalid_rest_eachblock_binding(name)); - } + if (!each_block || each_block.type !== 'EachBlock') return; + const rest_node = each_block.context_rest_properties.get(name); + if (rest_node) { + this.component.warn(rest_node as any, compiler_warnings.invalid_rest_eachblock_binding(name)); } }); } diff --git a/src/compiler/compile/nodes/ConstTag.ts b/src/compiler/compile/nodes/ConstTag.ts index 44a50aa005..4bcf3bd62f 100644 --- a/src/compiler/compile/nodes/ConstTag.ts +++ b/src/compiler/compile/nodes/ConstTag.ts @@ -23,7 +23,7 @@ export default class ConstTag extends Node { context_rest_properties: Map = new Map(); assignees: Set = new Set(); - dependencies: Set = new Set(); + dependencies: Set = new Set(); constructor(component: Component, parent: INodeAllowConstTag, scope: TemplateScope, info: ConstTagType) { super(component, parent, scope, info); @@ -37,22 +37,22 @@ export default class ConstTag extends Node { const { assignees, dependencies } = this; extract_identifiers(info.expression.left).forEach(({ name }) => { - assignees.add(name); + assignees.add(name); const owner = this.scope.get_owner(name); if (owner === parent) { component.error(info, compiler_errors.invalid_const_declaration(name)); } - }); + }); - walk(info.expression.right, { - enter(node, parent) { - if (is_reference(node as NodeWithPropertyDefinition, parent as NodeWithPropertyDefinition)) { - const identifier = get_object(node as any); - const { name } = identifier; - dependencies.add(name); - } - } - }); + walk(info.expression.right, { + enter(node, parent) { + if (is_reference(node as NodeWithPropertyDefinition, parent as NodeWithPropertyDefinition)) { + const identifier = get_object(node as any); + const { name } = identifier; + dependencies.add(name); + } + } + }); } parse_expression() { @@ -66,7 +66,7 @@ export default class ConstTag extends Node { this.expression = new Expression(this.component, this, this.scope, this.node.expression.right); this.contexts.forEach(context => { const owner = this.scope.get_owner(context.key.name); - if (owner && owner.type === 'ConstTag' && owner.parent === this.parent) { + if (owner?.type === 'ConstTag' && owner?.parent === this.parent) { this.component.error(this.node, compiler_errors.invalid_const_declaration(context.key.name)); } this.scope.add(context.key.name, this.expression.dependencies, this); diff --git a/src/compiler/compile/nodes/DebugTag.ts b/src/compiler/compile/nodes/DebugTag.ts index 88e8dd90e6..fe71a19972 100644 --- a/src/compiler/compile/nodes/DebugTag.ts +++ b/src/compiler/compile/nodes/DebugTag.ts @@ -13,8 +13,6 @@ export default class DebugTag extends Node { constructor(component: Component, parent: INode, scope: TemplateScope, info: TemplateNode) { super(component, parent, scope, info); - this.expressions = info.identifiers.map((node: EsTreeNode) => { - return new Expression(component, parent, scope, node); - }); + this.expressions = info.identifiers.map((node: EsTreeNode) => new Expression(component, parent, scope, node)); } } diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 303b2e9122..702b6530a3 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -261,24 +261,22 @@ export default class Element extends Node { } } - if (this.name === 'textarea') { - if (info.children.length > 0) { - const value_attribute = info.attributes.find(node => node.name === 'value'); - if (value_attribute) { - component.error(value_attribute, compiler_errors.textarea_duplicate_value); - return; - } + if (this.name === 'textarea' && info.children.length) { + const value_attribute = info.attributes.find(node => node.name === 'value'); + if (value_attribute) { + component.error(value_attribute, compiler_errors.textarea_duplicate_value); + return; + } - // this is an egregious hack, but it's the easiest way to get