|
1 | 1 | import { error } from '../../errors.js';
|
2 |
| -import { extract_identifiers, get_parent, is_text_attribute, object } from '../../utils/ast.js'; |
| 2 | +import { |
| 3 | + extract_identifiers, |
| 4 | + get_parent, |
| 5 | + is_expression_attribute, |
| 6 | + is_text_attribute, |
| 7 | + object |
| 8 | +} from '../../utils/ast.js'; |
3 | 9 | import { warn } from '../../warnings.js';
|
4 | 10 | import fuzzymatch from '../1-parse/utils/fuzzymatch.js';
|
5 | 11 | import { disallowed_parapgraph_contents, interactive_elements } from '../1-parse/utils/html.js';
|
6 | 12 | import { binding_properties } from '../bindings.js';
|
7 |
| -import { ContentEditableBindings, EventModifiers, SVGElements } from '../constants.js'; |
| 13 | +import { |
| 14 | + ContentEditableBindings, |
| 15 | + EventModifiers, |
| 16 | + SVGElements, |
| 17 | + global_events |
| 18 | +} from '../constants.js'; |
8 | 19 | import { is_custom_element_node } from '../nodes.js';
|
9 | 20 | import {
|
10 | 21 | regex_illegal_attribute_character,
|
@@ -66,12 +77,24 @@ function validate_element(node, context) {
|
66 | 77 | }
|
67 | 78 |
|
68 | 79 | if (attribute.name.startsWith('on') && attribute.name.length > 2) {
|
69 |
| - if ( |
70 |
| - attribute.value === true || |
71 |
| - is_text_attribute(attribute) || |
72 |
| - attribute.value.length > 1 |
73 |
| - ) { |
| 80 | + if (!is_expression_attribute(attribute)) { |
74 | 81 | error(attribute, 'invalid-event-attribute-value');
|
| 82 | + } else { |
| 83 | + const value = attribute.value[0].expression; |
| 84 | + if ( |
| 85 | + value.type === 'Identifier' && |
| 86 | + value.name === attribute.name && |
| 87 | + !context.state.scope.get(value.name) && |
| 88 | + global_events.has(attribute.name) |
| 89 | + ) { |
| 90 | + warn( |
| 91 | + context.state.analysis.warnings, |
| 92 | + attribute, |
| 93 | + context.path, |
| 94 | + 'global-event-reference', |
| 95 | + attribute.name |
| 96 | + ); |
| 97 | + } |
75 | 98 | }
|
76 | 99 | }
|
77 | 100 |
|
|
0 commit comments