|
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';
|
@@ -66,12 +72,23 @@ function validate_element(node, context) {
|
66 | 72 | }
|
67 | 73 |
|
68 | 74 | if (attribute.name.startsWith('on') && attribute.name.length > 2) {
|
| 75 | + if (!is_expression_attribute(attribute)) { |
| 76 | + error(attribute, 'invalid-event-attribute-value'); |
| 77 | + } |
| 78 | + |
| 79 | + const value = attribute.value[0].expression; |
69 | 80 | if (
|
70 |
| - attribute.value === true || |
71 |
| - is_text_attribute(attribute) || |
72 |
| - attribute.value.length > 1 |
| 81 | + value.type === 'Identifier' && |
| 82 | + value.name === attribute.name && |
| 83 | + !context.state.scope.get(value.name) |
73 | 84 | ) {
|
74 |
| - error(attribute, 'invalid-event-attribute-value'); |
| 85 | + warn( |
| 86 | + context.state.analysis.warnings, |
| 87 | + attribute, |
| 88 | + context.path, |
| 89 | + 'global-event-reference', |
| 90 | + attribute.name |
| 91 | + ); |
75 | 92 | }
|
76 | 93 | }
|
77 | 94 |
|
|
0 commit comments