Skip to content

Commit 0bae144

Browse files
committed
tweak
1 parent 36171ab commit 0bae144

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

packages/svelte/src/internal/client/dev/equality.js

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,56 @@ import { get_proxied_value } from '../proxy.js';
33

44
export function init_array_prototype_warnings() {
55
const array_prototype = Array.prototype;
6+
const { indexOf, lastIndexOf, includes } = array_prototype;
67

7-
const original_index_of = array_prototype.indexOf;
8+
array_prototype.indexOf = function (item, from_index) {
9+
const index = indexOf.call(this, item, from_index);
810

9-
array_prototype.indexOf = function (search_element, from_index) {
10-
const index = original_index_of.call(this, search_element, from_index);
1111
if (index === -1) {
12-
if (
13-
original_index_of.call(
14-
get_proxied_value(this),
15-
get_proxied_value(search_element),
16-
from_index
17-
) !== -1
18-
) {
12+
const test = indexOf.call(get_proxied_value(this), get_proxied_value(item), from_index);
13+
14+
if (test !== -1) {
1915
w.state_proxy_equality_mismatch('Array.indexOf');
2016

2117
// eslint-disable-next-line no-console
2218
console.trace();
2319
}
2420
}
21+
2522
return index;
2623
};
2724

28-
const original_last_index_of = array_prototype.lastIndexOf;
25+
array_prototype.lastIndexOf = function (item, from_index) {
26+
const index = lastIndexOf.call(this, item, from_index);
2927

30-
array_prototype.lastIndexOf = function (search_element, from_index) {
31-
const index = original_last_index_of.call(this, search_element, from_index);
3228
if (index === -1) {
33-
if (
34-
original_last_index_of.call(
35-
get_proxied_value(this),
36-
get_proxied_value(search_element),
37-
from_index
38-
) !== -1
39-
) {
29+
const test = lastIndexOf.call(get_proxied_value(this), get_proxied_value(item), from_index);
30+
31+
if (test !== -1) {
4032
w.state_proxy_equality_mismatch('Array.lastIndexOf');
4133

4234
// eslint-disable-next-line no-console
4335
console.trace();
4436
}
4537
}
38+
4639
return index;
4740
};
4841

49-
const original_includes = array_prototype.includes;
42+
array_prototype.includes = function (item, from_index) {
43+
const has = includes.call(this, item, from_index);
5044

51-
array_prototype.includes = function (search_element, from_index) {
52-
const has = original_includes.call(this, search_element, from_index);
5345
if (!has) {
54-
if (
55-
original_includes.call(
56-
get_proxied_value(this),
57-
get_proxied_value(search_element),
58-
from_index
59-
)
60-
) {
46+
const test = includes.call(get_proxied_value(this), get_proxied_value(item), from_index);
47+
48+
if (test) {
6149
w.state_proxy_equality_mismatch('Array.includes');
6250

6351
// eslint-disable-next-line no-console
6452
console.trace();
6553
}
6654
}
55+
6756
return has;
6857
};
6958
}

0 commit comments

Comments
 (0)