fix: correctly handle SvelteDate methods with arguments (#12738)

* fix: correctly handle SvelteDate methods with arguments

* tweak

* Update packages/svelte/src/reactivity/date.js

* Update packages/svelte/src/reactivity/date.js

Co-authored-by: Rich Harris <rich.harris@vercel.com>

* Update packages/svelte/src/reactivity/date.test.ts

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/12718/head
Dominic Gannaway 3 months ago committed by GitHub
parent 8bde2d5710
commit e78cfd393e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly handle SvelteDate methods with arguments

@ -32,6 +32,14 @@ export class SvelteDate extends Date {
if (method.startsWith('get') || method.startsWith('to')) {
// @ts-ignore
proto[method] = function (...args) {
// don't memoize if there are arguments
// @ts-ignore
if (args.length > 0) {
get(this.#time);
// @ts-ignore
return date_proto[method].apply(this, args);
}
var d = this.#deriveds.get(method);
if (d === undefined) {

@ -555,6 +555,30 @@ test('Date fine grained tests', () => {
cleanup();
});
test('Date.toLocaleString', () => {
const date = new SvelteDate(initial_date);
const log: any = [];
const cleanup = effect_root(() => {
render_effect(() => {
log.push(date.toLocaleString(undefined, { month: 'long', year: 'numeric' }));
});
render_effect(() => {
log.push(date.toLocaleString(undefined, { month: 'long' }));
});
});
flushSync();
assert.deepEqual(log, [
initial_date.toLocaleString(undefined, { month: 'long', year: 'numeric' }),
initial_date.toLocaleString(undefined, { month: 'long' })
]);
cleanup();
});
test('Date.instanceOf', () => {
assert.equal(new SvelteDate() instanceof Date, true);
});

Loading…
Cancel
Save