Repository: sveltejs/svelte
File: packages/svelte/src/internal/client/dom/elements/attributes.js (JavaScript)

Code before:
					 */
					function handle(evt) {
						current[key].call(this, evt);
					}

					current[event_handle_key] = create_event(event_name, element, handle, opts);
				} else {
					// @ts-ignore
					element[`__${event_name}`] = value;
					delegate([event_name]);
				}
			} else if (delegated) {
				// @ts-ignore
				element[`__${event_name}`] = undefined;
			}
		} else if (key === 'style' && value != null) {
			element.style.cssText = value + '';
		} else if (key === 'autofocus') {
			autofocus(/** @type {HTMLElement} */ (element), Boolean(value));
		} else if (key === '__value' || (key === 'value' && value != null)) {
			// @ts-ignore
			element.value = element[key] = element.__value = value;
		} else if (key === 'defaultValue') {
			/** @type {HTMLInputElement} */ (element).defaultValue = value;
		} else if (key === 'defaultChecked') {
			/** @type {HTMLInputElement} */ (element).defaultChecked = value;
		} else if (key === 'selected' && is_option_element) {
			set_selected(/** @type {HTMLOptionElement} */ (element), value);
		} else {
			var name = key;
			if (!preserve_attribute_case) {
				name = normalize_attribute(name);
			}
			if (value == null && !is_custom_element) {
				attributes[key] = null;
				let default_value_reset = /**@type {HTMLInputElement}*/ (element).defaultValue;
				let default_checked_reset = /**@type {HTMLInputElement}*/ (element).defaultChecked;
				element.removeAttribute(key);
				if (key === 'value') {
					/**@type {HTMLInputElement}*/ (element).defaultValue = default_value_reset;
				} else if (key === 'checked') {
					/**@type {HTMLInputElement}*/ (element).defaultChecked = default_checked_reset;
				}
			} else if (setters.includes(name) && (is_custom_element || typeof value !== 'string')) {
				// @ts-ignore
				element[name] = value;
			} else if (typeof value !== 'function') {
				if (hydrating && (name === 'src' || name === 'href' || name === 'srcset')) {
					if (!skip_warning) check_src_in_dev_hydration(element, name, value ?? '');
				} else {
					set_attribute(element, name, value);

Review comment (suggestion):
I think we can remove those in favor of doing `value == null && !is_custom_element && key !== 'defaultValue' && key === 'defaultChecked'` below

Code after:
					 */
					function handle(evt) {
						current[key].call(this, evt);
					}

					current[event_handle_key] = create_event(event_name, element, handle, opts);
				} else {
					// @ts-ignore
					element[`__${event_name}`] = value;
					delegate([event_name]);
				}
			} else if (delegated) {
				// @ts-ignore
				element[`__${event_name}`] = undefined;
			}
		} else if (key === 'style' && value != null) {
			element.style.cssText = value + '';
		} else if (key === 'autofocus') {
			autofocus(/** @type {HTMLElement} */ (element), Boolean(value));
		} else if (key === '__value' || (key === 'value' && value != null)) {
			// @ts-ignore
			element.value = element[key] = element.__value = value;
		} else if (key === 'selected' && is_option_element) {
			set_selected(/** @type {HTMLOptionElement} */ (element), value);
		} else {
			var name = key;
			if (!preserve_attribute_case) {
				name = normalize_attribute(name);
			}

			var is_default = name === 'defaultValue' || name === 'defaultChecked';

			if (value == null && !is_custom_element && !is_default) {
				attributes[key] = null;

				if (name === 'value' || name === 'checked') {
					// removing value/checked also removes defaultValue/defaultChecked — preserve
					let input = /** @type {HTMLInputElement} */ (element);

					if (name === 'value') {
						let prev = input.defaultValue;
						input.removeAttribute(name);
						input.defaultValue = prev;
					} else {
						let prev = input.defaultChecked;
						input.removeAttribute(name);
						input.defaultChecked = prev;
					}
				} else {
					element.removeAttribute(key);
				}