Add warnings for svelte:document mouse events

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

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