Merge commit from fork

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/17741/head
Elliott Johnson 8 months ago committed by GitHub
parent b8f2b86105
commit f89c7ddd7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: replace usage of `for in` with `for of Object.keys`

@ -138,7 +138,7 @@ export function attributes(attrs, css_hash, classes, styles, flags = 0) {
const lowercase = (flags & ELEMENT_PRESERVE_ATTRIBUTE_CASE) === 0; const lowercase = (flags & ELEMENT_PRESERVE_ATTRIBUTE_CASE) === 0;
const is_input = (flags & ELEMENT_IS_INPUT) !== 0; const is_input = (flags & ELEMENT_IS_INPUT) !== 0;
for (name in attrs) { for (name of Object.keys(attrs)) {
// omit functions, internal svelte properties and invalid attribute names // omit functions, internal svelte properties and invalid attribute names
if (typeof attrs[name] === 'function') continue; if (typeof attrs[name] === 'function') continue;
if (name[0] === '$' && name[1] === '$') continue; // faster than name.startsWith('$$') if (name[0] === '$' && name[1] === '$') continue; // faster than name.startsWith('$$')
@ -174,7 +174,8 @@ export function spread_props(props) {
for (let i = 0; i < props.length; i++) { for (let i = 0; i < props.length; i++) {
const obj = props[i]; const obj = props[i];
for (key in obj) { if (obj == null) continue;
for (key of Object.keys(obj)) {
const desc = Object.getOwnPropertyDescriptor(obj, key); const desc = Object.getOwnPropertyDescriptor(obj, key);
if (desc) { if (desc) {
Object.defineProperty(merged_props, key, desc); Object.defineProperty(merged_props, key, desc);
@ -302,7 +303,7 @@ export function update_store_pre(store_values, store_name, store, d = 1) {
/** @param {Record<string, [any, any, any]>} store_values */ /** @param {Record<string, [any, any, any]>} store_values */
export function unsubscribe_stores(store_values) { export function unsubscribe_stores(store_values) {
for (const store_name in store_values) { for (const store_name of Object.keys(store_values)) {
store_values[store_name][1](); store_values[store_name][1]();
} }
} }
@ -338,7 +339,7 @@ export function rest_props(props, rest) {
/** @type {Record<string, unknown>} */ /** @type {Record<string, unknown>} */
const rest_props = {}; const rest_props = {};
let key; let key;
for (key in props) { for (key of Object.keys(props)) {
if (!rest.includes(key)) { if (!rest.includes(key)) {
rest_props[key] = props[key]; rest_props[key] = props[key];
} }
@ -363,7 +364,7 @@ export function sanitize_slots(props) {
/** @type {Record<string, boolean>} */ /** @type {Record<string, boolean>} */
const sanitized = {}; const sanitized = {};
if (props.children) sanitized.default = true; if (props.children) sanitized.default = true;
for (const key in props.$$slots) { for (const key of Object.keys(props.$$slots || {})) {
sanitized[key] = true; sanitized[key] = true;
} }
return sanitized; return sanitized;
@ -376,7 +377,7 @@ export function sanitize_slots(props) {
* @param {Record<string, unknown>} props_now * @param {Record<string, unknown>} props_now
*/ */
export function bind_props(props_parent, props_now) { export function bind_props(props_parent, props_now) {
for (const key in props_now) { for (const key of Object.keys(props_now)) {
const initial_value = props_parent[key]; const initial_value = props_parent[key];
const value = props_now[key]; const value = props_now[key];
if ( if (

@ -267,7 +267,7 @@ export class Renderer {
* @param {{ head?: string, body: any }} content * @param {{ head?: string, body: any }} content
*/ */
const close = (renderer, value, { head, body }) => { const close = (renderer, value, { head, body }) => {
if ('value' in attrs) { if (Object.hasOwn(attrs, 'value')) {
value = attrs.value; value = attrs.value;
} }

@ -27,7 +27,7 @@ export function attr(name, value, is_boolean = false) {
is_boolean = true; is_boolean = true;
} }
if (value == null || (!value && is_boolean)) return ''; if (value == null || (!value && is_boolean)) return '';
const normalized = (name in replacements && replacements[name].get(value)) || value; const normalized = (Object.hasOwn(replacements, name) && replacements[name].get(value)) || value;
const assignment = is_boolean ? `=""` : `="${escape_html(normalized, true)}"`; const assignment = is_boolean ? `=""` : `="${escape_html(normalized, true)}"`;
return ` ${name}${assignment}`; return ` ${name}${assignment}`;
} }
@ -61,7 +61,7 @@ export function to_class(value, hash, directives) {
} }
if (directives) { if (directives) {
for (var key in directives) { for (var key of Object.keys(directives)) {
if (directives[key]) { if (directives[key]) {
classname = classname ? classname + ' ' + key : key; classname = classname ? classname + ' ' + key : key;
} else if (classname.length) { } else if (classname.length) {
@ -96,7 +96,7 @@ function append_styles(styles, important = false) {
var separator = important ? ' !important;' : ';'; var separator = important ? ' !important;' : ';';
var css = ''; var css = '';
for (var key in styles) { for (var key of Object.keys(styles)) {
var value = styles[key]; var value = styles[key];
if (value != null && value !== '') { if (value != null && value !== '') {
css += ' ' + key + ': ' + value + separator; css += ' ' + key + ': ' + value + separator;

@ -89,7 +89,7 @@ function clone(value, cloned, path, paths, original = null, no_tojson = false) {
cloned.set(original, copy); cloned.set(original, copy);
} }
for (var key in value) { for (var key of Object.keys(value)) {
copy[key] = clone( copy[key] = clone(
// @ts-expect-error // @ts-expect-error
value[key], value[key],

Loading…
Cancel
Save