Add warnings for svelte:document mouse events

pull/7149/head
Henrik Giesel 5 years ago
parent bb349a9dd7
commit eb5ac64d2b

@ -6,7 +6,7 @@
export default { export default {
custom_element_no_tag: { custom_element_no_tag: {
code: 'custom-element-no-tag', code: 'custom-element-no-tag',
message: 'No custom element \'tag\' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag="my-thing"/>. To hide this warning, use <svelte:options tag={null}/>' message: 'No custom element \'tag\' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag="my-thing"/>. To hide this warning, use <svelte:options tag={null}/>'
}, },
unused_export_let: (component: string, property: string) => ({ unused_export_let: (component: string, property: string) => ({
code: 'unused-export-let', code: 'unused-export-let',
@ -143,5 +143,9 @@ export default {
redundant_event_modifier_passive: { redundant_event_modifier_passive: {
code: 'redundant-event-modifier', code: 'redundant-event-modifier',
message: 'The passive modifier only works with wheel and touch events' message: 'The passive modifier only works with wheel and touch events'
},
avoid_mouse_events_on_document: {
code: 'avoid-mouse-events-on-document',
message: 'Mouse events on the document are not supported cross-browser and should be avoided'
} }
}; };

@ -4,6 +4,7 @@ import Action from './Action';
import Component from '../Component'; import Component from '../Component';
import TemplateScope from './shared/TemplateScope'; import TemplateScope from './shared/TemplateScope';
import { Element } from '../../interfaces'; import { Element } from '../../interfaces';
import compiler_warnings from '../compiler_warnings';
export default class Document extends Node { export default class Document extends Node {
type: 'Document'; type: 'Document';
@ -22,5 +23,15 @@ export default class Document extends Node {
// TODO there shouldn't be anything else here... // TODO there shouldn't be anything else here...
} }
}); });
const handlers_map = new Set();
this.handlers.forEach(handler => (
handlers_map.add(handler.name)
));
if (handlers_map.has('mouseenter') || handlers_map.has('mouseleave')) {
component.warn(this, compiler_warnings.avoid_mouse_events_on_document);
}
} }
} }

Loading…
Cancel
Save