Skip to content

Commit a87006e

Browse files
committed
simplify
1 parent dcb6e2c commit a87006e

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,13 @@ export function analyze_component(root, source, options) {
496496
analysis.reactive_statements = order_reactive_statements(analysis.reactive_statements);
497497
}
498498

499+
if (analysis.event_directive_node && analysis.uses_event_attributes) {
500+
e.mixed_event_handler_syntaxes(
501+
analysis.event_directive_node,
502+
analysis.event_directive_node.name
503+
);
504+
}
505+
499506
if (analysis.uses_render_tags && (analysis.uses_slots || analysis.slot_names.size > 0)) {
500507
e.slot_snippet_conflict(analysis.slot_names.values().next().value);
501508
}

packages/svelte/src/compiler/phases/2-analyze/validation.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,6 @@ function validate_element(node, context) {
105105

106106
for (const attribute of node.attributes) {
107107
if (attribute.type === 'Attribute') {
108-
const parent_type = node.type;
109-
110-
// Don't warn on component events; these might not be under the author's control so the warning would be unactionable
111-
if (
112-
(parent_type === 'RegularElement' || parent_type === 'SvelteElement') &&
113-
is_event_attribute(attribute) &&
114-
context.state.analysis.event_directive_node
115-
) {
116-
const { event_directive_node } = context.state.analysis;
117-
e.mixed_event_handler_syntaxes(event_directive_node, event_directive_node.name);
118-
}
119-
120108
const is_expression = is_expression_attribute(attribute);
121109

122110
if (context.state.analysis.runes && is_expression) {
@@ -1217,13 +1205,10 @@ export const validation_runes = merge(validation, a11y_validators, {
12171205
w.slot_element_deprecated(node);
12181206
}
12191207
},
1220-
OnDirective(node, { state, path }) {
1208+
OnDirective(node, { path }) {
12211209
const parent_type = path.at(-1)?.type;
12221210
// Don't warn on component events; these might not be under the author's control so the warning would be unactionable
12231211
if (parent_type === 'RegularElement' || parent_type === 'SvelteElement') {
1224-
if (state.analysis.uses_event_attributes) {
1225-
e.mixed_event_handler_syntaxes(node, node.name);
1226-
}
12271212
w.event_directive_deprecated(node, node.name);
12281213
}
12291214
},

packages/svelte/src/compiler/phases/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export interface ComponentAnalysis extends Analysis {
6060
uses_render_tags: boolean;
6161
needs_context: boolean;
6262
needs_props: boolean;
63+
/** Set to the first event directive (on:x) found on a DOM element in the code */
6364
event_directive_node: OnDirective | null;
65+
/** true if uses event attributes (onclick) */
6466
uses_event_attributes: boolean;
6567
custom_element: boolean | SvelteOptions['customElement'];
6668
/** If `true`, should append styles through JavaScript */

0 commit comments

Comments
 (0)