Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clever-stingrays-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: support `array.lastIndexOf` without second argument
12 changes: 10 additions & 2 deletions packages/svelte/src/internal/client/dev/equality.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ export function init_array_prototype_warnings() {
};

array_prototype.lastIndexOf = function (item, from_index) {
const index = lastIndexOf.call(this, item, from_index);
// we need to specify this.length - 1 because it's probably using something like
// `arguments` inside so passing undefined is different from not passing anything
const index = lastIndexOf.call(this, item, from_index ?? this.length - 1);

if (index === -1) {
const test = lastIndexOf.call(get_proxied_value(this), get_proxied_value(item), from_index);
// we need to specify this.length - 1 because it's probably using something like
// `arguments` inside so passing undefined is different from not passing anything
const test = lastIndexOf.call(
get_proxied_value(this),
get_proxied_value(item),
from_index ?? this.length - 1
);

if (test !== -1) {
w.state_proxy_equality_mismatch('array.lastIndexOf(...)');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ok, test } from '../../test';
import { flushSync } from 'svelte';

export default test({
mode: ['client'],
async test({ assert, logs }) {
assert.equal(logs[0], logs[1]);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
const arr = [0, 1, 2];
console.log(arr.lastIndexOf(2));
console.log(arr.lastIndexOf(2, arr.length - 1));
</script>