Skip to content

Commit

Permalink
chore: tidy up is_capture_event (#12693)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Aug 1, 2024
1 parent 4aa815f commit f984307
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 1,8 @@
/** @import { ArrowFunctionExpression, Expression, FunctionDeclaration, FunctionExpression } from 'estree' */
/** @import { Attribute, DelegatedEvent, RegularElement } from '#compiler' */
/** @import { Context } from '../types' */
import { DelegatedEvents, is_capture_event } from '../../../../constants.js';
import { DelegatedEvents } from '../../../../constants.js';
import { is_capture_event } from '../../../../utils.js';
import {
get_attribute_chunks,
get_attribute_expression,
Expand Down Expand Up @@ -205,9 206,9 @@ function get_delegated_event(event_name, handler, context) {
* @param {string} event_name
*/
function get_attribute_event_name(event_name) {
if (is_capture_event(event_name, 'include-on')) {
event_name = event_name.slice(2);
if (is_capture_event(event_name)) {
event_name = event_name.slice(0, -7);
}
event_name = event_name.slice(2);
return event_name;
}
Original file line number Diff line number Diff line change
@@ -1,18 1,13 @@
/** @import { Expression, Identifier } from 'estree' */
/** @import { Attribute, ClassDirective, DelegatedEvent, ExpressionMetadata, ExpressionTag, Namespace, OnDirective, RegularElement, StyleDirective, SvelteElement, SvelteNode } from '#compiler' */
/** @import { ComponentContext } from '../../types' */
import { AttributeAliases, is_capture_event } from '../../../../../../constants.js';
import { is_ignored } from '../../../../../state.js';
import { AttributeAliases } from '../../../../../../constants.js';
import { is_capture_event } from '../../../../../../utils.js';
import { get_attribute_expression } from '../../../../../utils/ast.js';
import * as b from '../../../../../utils/builders.js';
import { DOMProperties, PassiveEvents } from '../../../../constants.js';
import { PassiveEvents } from '../../../../constants.js';
import { serialize_get_binding } from '../../utils.js';
import {
serialize_event_handler,
serialize_template_literal,
serialize_update,
serialize_update_assignment
} from './utils.js';
import { serialize_event_handler, serialize_template_literal, serialize_update } from './utils.js';

/**
* Serializes each style directive into something like `$.set_style(element, style_property, value)`
Expand Down
13 changes: 0 additions & 13 deletions packages/svelte/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 116,6 @@ export const DOMBooleanAttributes = [
export const namespace_svg = 'http://www.w3.org/2000/svg';
export const namespace_mathml = 'http://www.w3.org/1998/Math/MathML';

/**
* @param {string} name
* @param {"include-on" | "exclude-on"} [mode] - wether if name starts with `on` or `on` is excluded at this point
*/
export function is_capture_event(name, mode = 'exclude-on') {
if (!name.endsWith('capture')) {
return false;
}
return mode == 'exclude-on'
? name !== 'gotpointercapture' && name !== 'lostpointercapture'
: name !== 'ongotpointercapture' && name !== 'onlostpointercapture';
}

// we use a list of ignorable runtime warnings because not every runtime warning
// can be ignored and we want to keep the validation for svelte-ignore in place
export const IGNORABLE_RUNTIME_WARNINGS = /** @type {const} */ ([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 1,13 @@
import { DEV } from 'esm-env';
import { hydrating } from '../hydration.js';
import { get_descriptors, get_prototype_of } from '../../../shared/utils.js';
import {
AttributeAliases,
DelegatedEvents,
is_capture_event,
namespace_svg
} from '../../../../constants.js';
import { AttributeAliases, DelegatedEvents, namespace_svg } from '../../../../constants.js';
import { create_event, delegate } from './events.js';
import { add_form_reset_listener, autofocus } from './misc.js';
import * as w from '../../warnings.js';
import { LOADING_ATTR_SYMBOL } from '../../constants.js';
import { queue_idle_task, queue_micro_task } from '../task.js';
import { is_capture_event } from '../../../../utils.js';

/**
* The value/checked attribute in the template actually corresponds to the defaultValue property, so we need
Expand Down
7 changes: 7 additions & 0 deletions packages/svelte/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 98,10 @@ const RESERVED_WORDS = [
export function is_reserved(word) {
return RESERVED_WORDS.includes(word);
}

/**
* @param {string} name
*/
export function is_capture_event(name) {
return name.endsWith('capture') && name !== 'gotpointercapture' && name !== 'lostpointercapture';
}

0 comments on commit f984307

Please sign in to comment.