warnings/errors

pull/8356/head
adiguba 4 years ago
parent 14609492d1
commit c18e372369

@ -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"'
},
};

@ -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<string>) => ({
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'
}
};

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

Loading…
Cancel
Save