Skip to content

Commit a36f530

Browse files
committed
feat: improved the "mixing-events-handling-syntax" warning description
1 parent 2f0b3e5 commit a36f530

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,13 @@ function validate_element(node, context) {
107107
is_event_attribute(attribute) &&
108108
context.state.analysis.event_directive_node
109109
) {
110+
const node = context.state.analysis.event_directive_node;
110111
warn(
111112
context.state.analysis.warnings,
112-
context.state.analysis.event_directive_node,
113+
node,
113114
context.path,
114-
'mixing-events-handling-syntax'
115+
'mixing-events-handling-syntax',
116+
node.name
115117
);
116118
}
117119

@@ -1232,7 +1234,7 @@ export const validation_runes = merge(validation, a11y_validators, {
12321234
// Don't warn on component events; these might not be under the author's control so the warning would be unactionable
12331235
if (parent_type === 'RegularElement' || parent_type === 'SvelteElement') {
12341236
if (state.analysis.uses_event_attributes) {
1235-
warn(state.analysis.warnings, node, path, 'mixing-events-handling-syntax');
1237+
warn(state.analysis.warnings, node, path, 'mixing-events-handling-syntax', node.name);
12361238
}
12371239
warn(state.analysis.warnings, node, path, 'deprecated-event-handler', node.name);
12381240
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import type {
22
Binding,
33
Css,
44
Fragment,
5+
OnDirective,
56
RegularElement,
67
SlotElement,
78
SvelteElement,
89
SvelteNode,
910
SvelteOptions
1011
} from '#compiler';
11-
import type { BaseNode, Identifier, LabeledStatement, Program } from 'estree';
12+
import type { Identifier, LabeledStatement, Program } from 'estree';
1213
import type { Scope, ScopeRoot } from './scope.js';
1314

1415
export interface Js {
@@ -63,7 +64,7 @@ export interface ComponentAnalysis extends Analysis {
6364
uses_slots: boolean;
6465
uses_component_bindings: boolean;
6566
uses_render_tags: boolean;
66-
event_directive_node: BaseNode | null;
67+
event_directive_node: OnDirective | null;
6768
uses_event_attributes: boolean;
6869
custom_element: boolean | SvelteOptions['customElement'];
6970
/** If `true`, should append styles through JavaScript */

packages/svelte/src/compiler/warnings.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ const legacy = {
239239
/** @param {string} name */
240240
'deprecated-event-handler': (name) =>
241241
`Using on:${name} to listen to the ${name} event is is deprecated. Use the event attribute on${name} instead.`,
242-
'mixing-events-handling-syntax': () =>
243-
`Do not mix old and new event handling syntaxes in the same component. Use only standard event attributes.`
242+
/** @param {string} name */
243+
'mixing-events-handling-syntax': (name) =>
244+
`Mixing old (on:${name}) and new syntaxes for event handling is not recommended. Use only the on${name} syntax.`
244245
};
245246

246247
const block = {

0 commit comments

Comments
 (0)