From c18e372369cabda135d039a27cb56456f21b727a Mon Sep 17 00:00:00 2001 From: adiguba Date: Fri, 3 Mar 2023 19:00:11 +0100 Subject: [PATCH] warnings/errors --- src/compiler/compile/compiler_errors.ts | 10 +++++++--- src/compiler/compile/compiler_warnings.ts | 8 ++++---- src/compiler/compile/nodes/EventHandler.ts | 20 ++++++++++++++++++-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/compiler/compile/compiler_errors.ts b/src/compiler/compile/compiler_errors.ts index 2b8b9af9b5..64da987da1 100644 --- a/src/compiler/compile/compiler_errors.ts +++ b/src/compiler/compile/compiler_errors.ts @@ -310,8 +310,12 @@ export default { code: 'directive-conflict', message: `Cannot use ${directive1} and ${directive2} on the same element` }), - too_much_forward_event_modifiers: { - code: 'too-much-forward-event-modifiers', - message: 'Forward-event only accept one modifier (the forward alias)' + invalid_forward_event_alias_count: { + code: 'invalid-forward-event-alias-count', + message: 'Forward-event accept only one modifier (the event alias)' + }, + invalid_forward_event_alias_any: { + code: 'invalid-forward-event-alias-any', + message: 'The alias for on:* must be one of the following form: "prefix*" or "*suffix"' }, }; diff --git a/src/compiler/compile/compiler_warnings.ts b/src/compiler/compile/compiler_warnings.ts index 08ef640d90..07d288a27b 100644 --- a/src/compiler/compile/compiler_warnings.ts +++ b/src/compiler/compile/compiler_warnings.ts @@ -214,8 +214,8 @@ export default { code: 'invalid-rest-eachblock-binding', message: `...${rest_element_name} operator will create a new object and binding propogation with original object will not work` }), - incorrect_forward_event_modifier: (modifiers: Set) => ({ - code: 'incorrect-forward-event-modifier', - message: `Forward-event only accept one modifier for the forward alias. Event modifiers should not be used here : ${modifiers}` - }) + invalid_forward_event_alias: { + code: 'invalid-forward-event-alias', + message: 'Forward-event accept only one modifier : the event alias name' + } }; diff --git a/src/compiler/compile/nodes/EventHandler.ts b/src/compiler/compile/nodes/EventHandler.ts index 9e79f63406..ac759f166f 100644 --- a/src/compiler/compile/nodes/EventHandler.ts +++ b/src/compiler/compile/nodes/EventHandler.ts @@ -30,6 +30,19 @@ const passive_events = new Set([ 'touchcancel' ]); + +function is_valid_any_alias_name(alias: string) { + if (alias === '*') { + return true; + } + let idx = alias.indexOf('*'); + if (idx < 0) return false; + if (idx !== alias.lastIndexOf('*')) { + return false; + } + return idx === 0 || alias.endsWith('*'); +} + export default class EventHandler extends Node { type: 'EventHandler'; name: string; @@ -115,10 +128,13 @@ export default class EventHandler extends Node { } } else { if (this.aliasCount > 1) { - return this.component.error(this, compiler_errors.too_much_forward_event_modifiers); + return this.component.error(this, compiler_errors.invalid_forward_event_alias_count); } if (this.aliasName && valid_modifiers.has(this.aliasName)) { - this.component.warn(this, compiler_warnings.incorrect_forward_event_modifier(valid_modifiers)); + this.component.warn(this, compiler_warnings.invalid_forward_event_alias); + } + if (this.name === '*' && !is_valid_any_alias_name(this.aliasName)) { + return this.component.error(this, compiler_errors.invalid_forward_event_alias_any); } } }