diff --git a/src/compiler/compile/compiler_warnings.ts b/src/compiler/compile/compiler_warnings.ts index 86ec98cb8b..83e90da29d 100644 --- a/src/compiler/compile/compiler_warnings.ts +++ b/src/compiler/compile/compiler_warnings.ts @@ -6,7 +6,7 @@ export default { 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. . To hide this warning, use ' + message: 'No custom element \'tag\' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. . To hide this warning, use ' }, unused_export_let: (component: string, property: string) => ({ code: 'unused-export-let', @@ -143,5 +143,9 @@ export default { redundant_event_modifier_passive: { code: 'redundant-event-modifier', 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' } }; diff --git a/src/compiler/compile/nodes/Document.ts b/src/compiler/compile/nodes/Document.ts index 6c792e3e11..daa687da24 100644 --- a/src/compiler/compile/nodes/Document.ts +++ b/src/compiler/compile/nodes/Document.ts @@ -4,6 +4,7 @@ import Action from './Action'; import Component from '../Component'; import TemplateScope from './shared/TemplateScope'; import { Element } from '../../interfaces'; +import compiler_warnings from '../compiler_warnings'; export default class Document extends Node { type: 'Document'; @@ -22,5 +23,15 @@ export default class Document extends Node { // 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); + } } }