Skip to content

Commit 0a82796

Browse files
committed
merge main
2 parents fe64b20 + e1448f2 commit 0a82796

File tree

23 files changed

+217
-338
lines changed

23 files changed

+217
-338
lines changed

.changeset/heavy-cars-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure $host rune correctly compiles in variable declarations

.changeset/hip-beers-shake.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/metal-cameras-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: ensure types are easier to follow for TypeScript

.changeset/pre.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
"dirty-donuts-yell",
129129
"dirty-eyes-itch",
130130
"dirty-garlics-design",
131+
"dirty-jars-tap",
131132
"dirty-pens-look",
132133
"dirty-pianos-eat",
133134
"dirty-tips-add",
@@ -306,6 +307,7 @@
306307
"healthy-mangos-brush",
307308
"healthy-planes-vanish",
308309
"healthy-zebras-accept",
310+
"heavy-cars-ring",
309311
"heavy-comics-move",
310312
"heavy-doors-applaud",
311313
"heavy-ducks-leave",
@@ -344,6 +346,7 @@
344346
"itchy-kings-deliver",
345347
"itchy-lemons-punch",
346348
"itchy-lions-wash",
349+
"itchy-oranges-behave",
347350
"itchy-panthers-shave",
348351
"itchy-peaches-compare",
349352
"itchy-pianos-marry",
@@ -508,6 +511,7 @@
508511
"orange-yaks-protect",
509512
"orange-zoos-heal",
510513
"perfect-actors-bake",
514+
"perfect-cooks-shop",
511515
"perfect-hairs-matter",
512516
"perfect-hats-dance",
513517
"perfect-pugs-shake",
@@ -542,6 +546,7 @@
542546
"popular-roses-teach",
543547
"popular-walls-hunt",
544548
"pretty-ties-help",
549+
"proud-lobsters-lie",
545550
"proud-pets-hang",
546551
"proud-queens-sniff",
547552
"purple-dragons-peel",

.changeset/proud-lobsters-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: Ensure imports are above other statements

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"bench:debug": "node --allow-natives-syntax --inspect-brk ./benchmarking/run.js"
3030
},
3131
"devDependencies": {
32-
"@changesets/cli": "^2.27.6",
32+
"@changesets/cli": "^2.27.8",
3333
"@sveltejs/eslint-config": "^8.0.1",
3434
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
3535
"@types/node": "^20.11.5",

packages/svelte/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# svelte
22

3+
## 5.0.0-next.244
4+
5+
### Patch Changes
6+
7+
- fix: error on duplicate style and class directive ([#13097](https://github.com/sveltejs/svelte/pull/13097))
8+
9+
- fix: ensure $host rune correctly compiles in variable declarations ([#13127](https://github.com/sveltejs/svelte/pull/13127))
10+
11+
- fix: remove unnecessary update assignments ([#13113](https://github.com/sveltejs/svelte/pull/13113))
12+
13+
- fix: error at compile time on unsupported TypeScript language features ([#12982](https://github.com/sveltejs/svelte/pull/12982))
14+
15+
- fix: Ensure imports are above other statements ([#13132](https://github.com/sveltejs/svelte/pull/13132))
16+
317
## 5.0.0-next.243
418

519
### Patch Changes

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svelte",
33
"description": "Cybernetically enhanced web apps",
44
"license": "MIT",
5-
"version": "5.0.0-next.243",
5+
"version": "5.0.0-next.244",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/scripts/generate-types.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,14 @@ if (bad_links.length > 0) {
6060

6161
process.exit(1);
6262
}
63+
64+
if (types.includes('\texport { ')) {
65+
// eslint-disable-next-line no-console
66+
console.error(
67+
`The generated types file should not contain 'export { ... }' statements. ` +
68+
`TypeScript is bad at following these: when creating d.ts files through @sveltejs/package, and one of these types is used, ` +
69+
`TypeScript will likely fail at generating a d.ts file. ` +
70+
`To prevent this, do 'export interface Foo {}' instead of 'interface Foo {}' and then 'export { Foo }'`
71+
);
72+
process.exit(1);
73+
}

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,22 @@ export function client_component(analysis, options) {
457457
analysis.uses_slots ||
458458
analysis.slot_names.size > 0;
459459

460-
// we hoist all the import declarations to the top of the file
461-
const body = [...module.body, ...state.hoisted].sort((body_a, body_b) =>
462-
body_a.type === 'ImportDeclaration' && body_b.type !== 'ImportDeclaration' ? -1 : 1
463-
);
460+
// Merge hoisted statements into module body.
461+
// Ensure imports are on top, with the order preserved, then module body, then hoisted statements
462+
/** @type {ESTree.ImportDeclaration[]} */
463+
const imports = [];
464+
/** @type {ESTree.Program['body']} */
465+
let body = [];
466+
467+
for (const entry of [...module.body, ...state.hoisted]) {
468+
if (entry.type === 'ImportDeclaration') {
469+
imports.push(entry);
470+
} else {
471+
body.push(entry);
472+
}
473+
}
474+
475+
body = [...imports, ...body];
464476

465477
const component = b.function_declaration(
466478
b.id(analysis.name),

packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function VariableDeclaration(node, context) {
2828
rune === '$effect.tracking' ||
2929
rune === '$effect.root' ||
3030
rune === '$inspect' ||
31-
rune === '$state.snapshot'
31+
rune === '$state.snapshot' ||
32+
rune === '$host'
3233
) {
3334
if (init != null && is_hoisted_function(init)) {
3435
context.state.hoisted.push(

packages/svelte/src/reactivity/index-client.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,3 @@ export { SvelteSet } from './set.js';
33
export { SvelteMap } from './map.js';
44
export { SvelteURL } from './url.js';
55
export { SvelteURLSearchParams } from './url-search-params.js';
6-
7-
/** @deprecated Use `SvelteDate` instead */
8-
export function Date() {
9-
throw new Error('Date has been removed, use SvelteDate instead.');
10-
}
11-
12-
/** @deprecated Use `SvelteSet` instead */
13-
export function Set() {
14-
throw new Error('Set has been removed, use SvelteSet instead.');
15-
}
16-
17-
/** @deprecated Use `SvelteMap` instead */
18-
export function Map() {
19-
throw new Error('Map has been removed, use SvelteMap instead.');
20-
}
21-
22-
/** @deprecated Use `SvelteURL` instead */
23-
export function URL() {
24-
throw new Error('URL has been removed, use SvelteURL instead.');
25-
}
26-
27-
/** @deprecated Use `SvelteURLSearchParams` instead */
28-
export function URLSearchParams() {
29-
throw new Error('URLSearchParams has been removed, use SvelteURLSearchParams instead.');
30-
}

packages/svelte/src/reactivity/index-server.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,3 @@ export const SvelteSet = globalThis.Set;
33
export const SvelteMap = globalThis.Map;
44
export const SvelteURL = globalThis.URL;
55
export const SvelteURLSearchParams = globalThis.URLSearchParams;
6-
7-
/** @deprecated Use `SvelteDate` instead */
8-
export function Date() {
9-
throw new Error('Date has been removed, use SvelteDate instead.');
10-
}
11-
12-
/** @deprecated Use `SvelteSet` instead */
13-
export function Set() {
14-
throw new Error('Set has been removed, use SvelteSet instead.');
15-
}
16-
17-
/** @deprecated Use `SvelteMap` instead */
18-
export function Map() {
19-
throw new Error('Map has been removed, use SvelteMap instead.');
20-
}
21-
22-
/** @deprecated Use `SvelteURL` instead */
23-
export function URL() {
24-
throw new Error('URL has been removed, use SvelteURL instead.');
25-
}
26-
27-
/** @deprecated Use `SvelteURLSearchParams` instead */
28-
export function URLSearchParams() {
29-
throw new Error('URLSearchParams has been removed, use SvelteURLSearchParams instead.');
30-
}

packages/svelte/src/store/public.d.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/** Callback to inform of a value updates. */
2-
type Subscriber<T> = (value: T) => void;
2+
export type Subscriber<T> = (value: T) => void;
33

44
/** Unsubscribes from value updates. */
5-
type Unsubscriber = () => void;
5+
export type Unsubscriber = () => void;
66

77
/** Callback to update a value. */
8-
type Updater<T> = (value: T) => T;
8+
export type Updater<T> = (value: T) => T;
99

1010
/**
1111
* Start and stop notification callbacks.
@@ -16,13 +16,13 @@ type Updater<T> = (value: T) => T;
1616
* @returns {void | (() => void)} Optionally, a cleanup function that is called when the last remaining
1717
* subscriber unsubscribes.
1818
*/
19-
type StartStopNotifier<T> = (
19+
export type StartStopNotifier<T> = (
2020
set: (value: T) => void,
2121
update: (fn: Updater<T>) => void
2222
) => void | (() => void);
2323

2424
/** Readable interface for subscribing. */
25-
interface Readable<T> {
25+
export interface Readable<T> {
2626
/**
2727
* Subscribe on value changes.
2828
* @param run subscription callback
@@ -32,7 +32,7 @@ interface Readable<T> {
3232
}
3333

3434
/** Writable interface for both updating and subscribing. */
35-
interface Writable<T> extends Readable<T> {
35+
export interface Writable<T> extends Readable<T> {
3636
/**
3737
* Set value and inform subscribers.
3838
* @param value to set
@@ -46,6 +46,4 @@ interface Writable<T> extends Readable<T> {
4646
update(this: void, updater: Updater<T>): void;
4747
}
4848

49-
export { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable };
50-
5149
export * from './index-client.js';
Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
type EasingFunction = (t: number) => number;
1+
export type EasingFunction = (t: number) => number;
22

3-
interface TransitionConfig {
3+
export interface TransitionConfig {
44
delay?: number;
55
duration?: number;
66
easing?: EasingFunction;
77
css?: (t: number, u: number) => string;
88
tick?: (t: number, u: number) => void;
99
}
1010

11-
interface BlurParams {
11+
export interface BlurParams {
1212
delay?: number;
1313
duration?: number;
1414
easing?: EasingFunction;
1515
amount?: number | string;
1616
opacity?: number;
1717
}
1818

19-
interface FadeParams {
19+
export interface FadeParams {
2020
delay?: number;
2121
duration?: number;
2222
easing?: EasingFunction;
2323
}
2424

25-
interface FlyParams {
25+
export interface FlyParams {
2626
delay?: number;
2727
duration?: number;
2828
easing?: EasingFunction;
@@ -31,44 +31,32 @@ interface FlyParams {
3131
opacity?: number;
3232
}
3333

34-
interface SlideParams {
34+
export interface SlideParams {
3535
delay?: number;
3636
duration?: number;
3737
easing?: EasingFunction;
3838
axis?: 'x' | 'y';
3939
}
4040

41-
interface ScaleParams {
41+
export interface ScaleParams {
4242
delay?: number;
4343
duration?: number;
4444
easing?: EasingFunction;
4545
start?: number;
4646
opacity?: number;
4747
}
4848

49-
interface DrawParams {
49+
export interface DrawParams {
5050
delay?: number;
5151
speed?: number;
5252
duration?: number | ((len: number) => number);
5353
easing?: EasingFunction;
5454
}
5555

56-
interface CrossfadeParams {
56+
export interface CrossfadeParams {
5757
delay?: number;
5858
duration?: number | ((len: number) => number);
5959
easing?: EasingFunction;
6060
}
6161

62-
export {
63-
EasingFunction,
64-
TransitionConfig,
65-
BlurParams,
66-
FadeParams,
67-
FlyParams,
68-
SlideParams,
69-
ScaleParams,
70-
DrawParams,
71-
CrossfadeParams
72-
};
73-
7462
export * from './index.js';

packages/svelte/src/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
* https://svelte.dev/docs/svelte-compiler#svelte-version
77
* @type {string}
88
*/
9-
export const VERSION = '5.0.0-next.243';
9+
export const VERSION = '5.0.0-next.244';
1010
export const PUBLIC_VERSION = '5';

packages/svelte/tests/runtime-browser/custom-elements-samples/host-rune/_config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ export default test({
1616

1717
el.shadowRoot.querySelectorAll('button')[0].click();
1818
el.shadowRoot.querySelectorAll('button')[1].click();
19-
assert.deepEqual(events, ['greeting', 'hello', 'greeting', 'welcome']);
19+
el.shadowRoot.querySelectorAll('button')[2].click();
20+
assert.deepEqual(events, ['greeting', 'hello', 'greeting', 'welcome', 'greeting', 'bonjour']);
2021

2122
el.removeEventListener('greeting', handle_evt);
2223
el.shadowRoot.querySelectorAll('button')[0].click();
2324
el.shadowRoot.querySelectorAll('button')[1].click();
24-
assert.deepEqual(events, ['greeting', 'hello', 'greeting', 'welcome']);
25+
el.shadowRoot.querySelectorAll('button')[2].click();
26+
assert.deepEqual(events, ['greeting', 'hello', 'greeting', 'welcome', 'greeting', 'bonjour']);
2527
}
2628
});

packages/svelte/tests/runtime-browser/custom-elements-samples/host-rune/main.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
function welcome() {
99
$host().dispatchEvent(new CustomEvent('greeting', { detail: 'welcome' }))
1010
}
11+
function bonjour() {
12+
const element = $host();
13+
element.dispatchEvent(new CustomEvent('greeting', { detail: 'bonjour' }))
14+
}
1115
</script>
1216

1317
<button onclick={() => greet('hello')}>say hello</button>
1418
<button onclick={welcome}>say welcome</button>
19+
<button onclick={bonjour}>say bonjour</button>

0 commit comments

Comments
 (0)