Skip to content

Commit e55c891

Browse files
committed
Merge branch 'master' into const
2 parents 73586aa + fc7c777 commit e55c891

File tree

30 files changed

+733
-562
lines changed

30 files changed

+733
-562
lines changed

.changeset/clever-ghosts-laugh.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 `svelte:component` evaluates props once

.changeset/lucky-knives-crash.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: handle destructured primitive literals

documentation/blog/2022-12-01-whats-new-in-svelte-december-2022.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ For all the changes to the Svelte compiler, including unreleased changes, check
4747

4848
**Apps & Sites built with Svelte**
4949

50-
- [Appwrite's new console](https://github.com/appwrite/console) makes its secure backend server for web, mobile & Flutter developers avaiable in the browser
50+
- [Appwrite's new console](https://github.com/appwrite/console) makes its secure backend server for web, mobile & Flutter developers available in the browser
5151
- [RepoMagic](https://www.repomagic.com/) is a search and analytics tool for GitHub
5252
- [Podman Desktop](https://github.com/containers/podman-desktop) is a graphical tool for developing on containers and Kubernetes
5353
- [Ballerine](https://github.com/ballerine-io/ballerine) is a Know Your Customer (KYC) UX for any vertical or geography using modular building blocks, components, and 3rd party integrations

documentation/docs/05-misc/03-typescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To use TypeScript within Svelte components, you need to add a preprocessor that
1010

1111
### Using SvelteKit or Vite
1212

13-
The easiest way to get started is scaffolding a new SvelteKit project by typing `npm create svelte@latest`, following the prompts and chosing the TypeScript option.
13+
The easiest way to get started is scaffolding a new SvelteKit project by typing `npm create svelte@latest`, following the prompts and choosing the TypeScript option.
1414

1515
```ts
1616
/// file: svelte.config.js

documentation/docs/05-misc/04-v4-migration-guide.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ If you're a library author, consider whether to only support Svelte 4 or if it's
1717

1818
## Browser conditions for bundlers
1919

20-
Bundlers must now specify the browser condition when building a frontend bundle for the browser. SvelteKit and Vite will handle this automatically for you. For Rollup or webpack you may need to adjust your config to ensure it matches what is shown in the [`rollup-plugin-svelte`](https://github.com/sveltejs/rollup-plugin-svelte/#usage) and [`svelte-loader`](https://github.com/sveltejs/svelte-loader#usage) documentation. ([#8516](https://github.com/sveltejs/svelte/issues/8516))
20+
Bundlers must now specify the `browser` condition when building a frontend bundle for the browser. SvelteKit and Vite will handle this automatically for you. If you're using any others, you may observe lifecycle callbacks such as `onMount` not get called and you'll need to update the module resolution configuration.
21+
- For Rollup this is done within the `@rollup/plugin-node-resolve` plugin by setting `browser: true` in its options. See the [`rollup-plugin-svelte`](https://github.com/sveltejs/rollup-plugin-svelte/#usage) documentation for more details
22+
- For wepback this is done by adding `"browser"` to the `conditionNames` array. You may also have to update your `alias` config, if you have set it. See the [`svelte-loader`](https://github.com/sveltejs/svelte-loader#usage) documentation for more details
23+
24+
([#8516](https://github.com/sveltejs/svelte/issues/8516))
2125

2226
## Removal of CJS related output
2327

documentation/tutorial/11-animations/01-animate/app-a/App.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
}
105105
106106
label {
107+
display: block;
107108
position: relative;
108109
line-height: 1.2;
109110
padding: 0.5em 2.5em 0.5em 2em;

documentation/tutorial/11-animations/01-animate/app-b/App.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
}
106106
107107
label {
108+
display: block;
108109
position: relative;
109110
line-height: 1.2;
110111
padding: 0.5em 2.5em 0.5em 2em;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"@changesets/cli": "^2.26.1",
2424
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
2525
"@typescript-eslint/eslint-plugin": "^5.60.0",
26-
"eslint": "^8.43.0",
27-
"eslint-plugin-svelte": "^2.31.0",
26+
"eslint": "^8.44.0",
27+
"eslint-plugin-svelte": "^2.32.2",
2828
"eslint-plugin-unicorn": "^47.0.0",
2929
"playwright": "^1.35.1",
3030
"prettier": "^2.8.8",

packages/playground/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ To prevent any changes you make in this directory from being accidentally commit
44

55
If you would actually like to make some changes to the files here for everyone then run `git update-index --no-skip-worktree ./**/*.*` before committing.
66

7-
If you're using VS Code, you can use the "Playground: Full" launch configuration to run the playground and attach the debugger to both the compiler and the browser.
7+
If you're using VS Code, you can use the "Playground: Full" launch configuration to run the playground and attach the debugger to both the compiler and the browser. This will SSR the component and then also hydrate it on the client side using rollup to bundle any other imports.
8+
9+
You can also just compile the `App.svelte` file by running `node compile.js` if you'd like to check some compiler behaviour in isolation.

packages/playground/compile.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { readFileSync } from 'node:fs';
2+
import { compile } from '../svelte/src/compiler/index.js';
3+
4+
const code = readFileSync('src/App.svelte', 'utf8');
5+
6+
console.log(compile(code));

packages/svelte/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@
127127
"@types/node": "^14.18.51",
128128
"agadoo": "^3.0.0",
129129
"dts-buddy": "^0.1.7",
130-
"esbuild": "^0.17.19",
130+
"esbuild": "^0.18.11",
131131
"happy-dom": "^9.20.3",
132132
"jsdom": "^21.1.2",
133133
"kleur": "^4.1.5",
134-
"rollup": "^3.25.1",
134+
"rollup": "^3.26.2",
135135
"source-map": "^0.7.4",
136136
"tiny-glob": "^0.2.9",
137137
"typescript": "^5.1.3",
138-
"vitest": "^0.31.4"
138+
"vitest": "^0.33.0"
139139
}
140140
}

packages/svelte/src/compiler/compile/Component.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,26 +1290,22 @@ export default class Component {
12901290
// everything except const values can be changed by e.g. svelte devtools
12911291
// which means we can't hoist it
12921292
if (node.kind !== 'const' && this.compile_options.dev) return false;
1293-
const { name } = /** @type {import('estree').Identifier} */ (d.id);
1294-
const v = this.var_lookup.get(name);
1295-
if (v.reassigned) return false;
1296-
if (v.export_name) return false;
1297-
if (this.var_lookup.get(name).reassigned) return false;
1298-
if (
1299-
this.vars.find(
1300-
/** @param {any} variable */ (variable) => variable.name === name && variable.module
1301-
)
1302-
) {
1303-
return false;
1293+
for (const name of extract_names(d.id)) {
1294+
const v = this.var_lookup.get(name);
1295+
if (v.reassigned) return false;
1296+
if (v.export_name) return false;
1297+
1298+
if (this.vars.find((variable) => variable.name === name && variable.module)) {
1299+
return false;
1300+
}
13041301
}
13051302
return true;
13061303
});
13071304
if (all_hoistable) {
13081305
node.declarations.forEach((d) => {
1309-
const variable = this.var_lookup.get(
1310-
/** @type {import('estree').Identifier} */ (d.id).name
1311-
);
1312-
variable.hoistable = true;
1306+
for (const name of extract_names(d.id)) {
1307+
this.var_lookup.get(name).hoistable = true;
1308+
}
13131309
});
13141310
hoistable_nodes.add(node);
13151311
body.splice(i--, 1);

packages/svelte/src/compiler/compile/render_dom/wrappers/InlineComponent/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,6 @@ export default class InlineComponentWrapper extends Wrapper {
436436
b`if (${name}) @claim_component(${name}.$$.fragment, ${claim_nodes});`
437437
);
438438
}
439-
if (updates.length) {
440-
block.chunks.update.push(b`
441-
${updates}
442-
`);
443-
}
444439
const tmp_anchor = this.get_or_create_anchor(block, parent_node, parent_nodes);
445440
const anchor = has_css_custom_properties ? 'null' : tmp_anchor;
446441
const update_mount_node = has_css_custom_properties
@@ -481,6 +476,7 @@ export default class InlineComponentWrapper extends Wrapper {
481476
${name} = null;
482477
}
483478
} else if (${switch_value}) {
479+
${updates}
484480
${updates.length > 0 && b`${name}.$set(${name_changes});`}
485481
}
486482
`);

packages/svelte/test/hydration/hydration.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// @vitest-environment jsdom
2-
// TODO: https://github.com/capricorn86/happy-dom/issues/916
32

43
import * as fs from 'node:fs';
54
import * as path from 'node:path';

packages/svelte/test/js/samples/hoisted-const/expected.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function create_fragment(ctx) {
1515
return {
1616
c() {
1717
b = element("b");
18-
b.textContent = `${get_answer()}`;
18+
b.textContent = `${get_answer()} ${length}`;
1919
},
2020
m(target, anchor) {
2121
insert(target, b, anchor);
@@ -32,6 +32,7 @@ function create_fragment(ctx) {
3232
}
3333

3434
const ANSWER = 42;
35+
const { length } = 'abc';
3536

3637
function get_answer() {
3738
return ANSWER;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
const ANSWER = 42;
3+
const { length } = 'abc';
34
function get_answer() { return ANSWER; }
45
</script>
56

6-
<b>{get_answer()}</b>
7+
<b>{get_answer()} {length}</b>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
export let value;
3+
</script>
4+
5+
<p>value(1) = {value}</p>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
export let value;
3+
</script>
4+
5+
<p>value(2) = {value}</p>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export default {
2+
html: `
3+
<p>value(1) = 1</p>
4+
<button>Toggle Component</button>
5+
`,
6+
7+
async test({ assert, component, window, target }) {
8+
const button = target.querySelector('button');
9+
await button.dispatchEvent(new window.Event('click'));
10+
assert.htmlEqual(
11+
target.innerHTML,
12+
`
13+
<p>value(2) = 2</p>
14+
<button>Toggle Component</button>
15+
`
16+
);
17+
assert.equal(component.n, 2);
18+
await button.dispatchEvent(new window.Event('click'));
19+
assert.htmlEqual(
20+
target.innerHTML,
21+
`
22+
<p>value(1) = 3</p>
23+
<button>Toggle Component</button>
24+
`
25+
);
26+
assert.equal(component.n, 3);
27+
}
28+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Comp1 from './Comp1.svelte';
3+
import Comp2 from './Comp2.svelte';
4+
5+
export let n = 0;
6+
let view = { comp: Comp1, fn: () => ++n };
7+
</script>
8+
9+
<svelte:component this={view.comp} value={view.fn()}/>
10+
11+
<button on:click={e => view.comp = view.comp === Comp1 ? Comp2 : Comp1}>Toggle Component</button>
12+

0 commit comments

Comments
 (0)