svelte 5.53.1 → 5.53.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -9,17 +9,26 @@ import * as b from '#compiler/builders';
|
|
|
9
9
|
export function UpdateExpression(node, context) {
|
|
10
10
|
const argument = node.argument;
|
|
11
11
|
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
if (argument.type === 'Identifier') {
|
|
13
|
+
const binding = context.state.scope.get(argument.name);
|
|
14
|
+
|
|
15
|
+
if (binding?.kind === 'store_sub') {
|
|
16
|
+
return b.call(
|
|
17
|
+
node.prefix ? '$.update_store_pre' : '$.update_store',
|
|
18
|
+
b.assignment('??=', b.id('$$store_subs'), b.object([])),
|
|
19
|
+
b.literal(argument.name),
|
|
20
|
+
b.id(argument.name.slice(1)),
|
|
21
|
+
node.operator === '--' && b.literal(-1)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (binding?.kind === 'derived') {
|
|
26
|
+
return b.call(
|
|
27
|
+
node.prefix ? '$.update_derived_pre' : '$.update_derived',
|
|
28
|
+
binding.node,
|
|
29
|
+
node.operator === '--' && b.literal(-1)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
return context.next();
|
|
@@ -4,6 +4,9 @@ let text_encoder;
|
|
|
4
4
|
// TODO - remove this and use global `crypto` when we drop Node 18
|
|
5
5
|
let crypto;
|
|
6
6
|
|
|
7
|
+
/** @param {string} module_name */
|
|
8
|
+
const obfuscated_import = (module_name) => import(/* @vite-ignore */ module_name);
|
|
9
|
+
|
|
7
10
|
/** @param {string} data */
|
|
8
11
|
export async function sha256(data) {
|
|
9
12
|
text_encoder ??= new TextEncoder();
|
|
@@ -12,8 +15,8 @@ export async function sha256(data) {
|
|
|
12
15
|
crypto ??= globalThis.crypto?.subtle?.digest
|
|
13
16
|
? globalThis.crypto
|
|
14
17
|
: // @ts-ignore - we don't install node types in the prod build
|
|
15
|
-
// don't use 'node:crypto' because static analysers will think we rely on node when we don't
|
|
16
|
-
(await
|
|
18
|
+
// don't use import('node:crypto') directly because static analysers will think we rely on node when we don't
|
|
19
|
+
(await obfuscated_import('node:crypto')).webcrypto;
|
|
17
20
|
|
|
18
21
|
const hash_buffer = await crypto.subtle.digest('SHA-256', text_encoder.encode(data));
|
|
19
22
|
|
|
@@ -504,6 +504,35 @@ export function derived(fn) {
|
|
|
504
504
|
};
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
+
/**
|
|
508
|
+
* @template {number | bigint} T
|
|
509
|
+
* @param {(value?: T) => T} derived
|
|
510
|
+
* @param {1 | -1} [d]
|
|
511
|
+
* @returns {T}
|
|
512
|
+
*/
|
|
513
|
+
export function update_derived(derived, d = 1) {
|
|
514
|
+
const value = derived();
|
|
515
|
+
let increase = typeof value === 'bigint' ? BigInt(d) : d;
|
|
516
|
+
// for some reason TS is mad even if T is always number or bigint
|
|
517
|
+
derived(value + /** @type {*} */ (increase));
|
|
518
|
+
return value;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* @template {number | bigint} T
|
|
523
|
+
* @param {(value?: T) => T} derived
|
|
524
|
+
* @param {1 | -1} [d]
|
|
525
|
+
* @returns {T}
|
|
526
|
+
*/
|
|
527
|
+
export function update_derived_pre(derived, d = 1) {
|
|
528
|
+
const old_value = derived();
|
|
529
|
+
let increase = typeof old_value === 'bigint' ? BigInt(d) : d;
|
|
530
|
+
// for some reason TS is mad even if T is always number or bigint
|
|
531
|
+
const value = old_value + /** @type {*} */ (increase);
|
|
532
|
+
derived(value);
|
|
533
|
+
return value;
|
|
534
|
+
}
|
|
535
|
+
|
|
507
536
|
/**
|
|
508
537
|
* @template T
|
|
509
538
|
* @param {()=>T} fn
|
package/src/version.js
CHANGED