Skip to content

Commit 2cabc88

Browse files
authored
add some missing legacy tests (#10875)
1 parent 6822dec commit 2cabc88

File tree

18 files changed

+261
-4
lines changed

18 files changed

+261
-4
lines changed

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,11 @@ const legacy_scope_tweaker = {
753753
state.scope.get(specifier.local.name)
754754
);
755755
if (
756-
binding.kind === 'state' ||
757-
binding.kind === 'frozen_state' ||
758-
(binding.kind === 'normal' &&
759-
(binding.declaration_kind === 'let' || binding.declaration_kind === 'var'))
756+
binding !== null &&
757+
(binding.kind === 'state' ||
758+
binding.kind === 'frozen_state' ||
759+
(binding.kind === 'normal' &&
760+
(binding.declaration_kind === 'let' || binding.declaration_kind === 'var')))
760761
) {
761762
binding.kind = 'prop';
762763
if (specifier.exported.name !== specifier.local.name) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
export let a;
3+
export const b = 2;
4+
</script>
5+
6+
<p>a: {a}</p>
7+
<p>b: {b}</p>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
get props() {
5+
return { a: 3, b: 4 };
6+
},
7+
8+
html: `
9+
<p>a: 3</p>
10+
<p>b: 2</p>
11+
`,
12+
13+
async test({ assert, component, target }) {
14+
await component.$set({
15+
a: 5,
16+
b: 6
17+
});
18+
19+
assert.htmlEqual(
20+
target.innerHTML,
21+
`
22+
<p>a: 5</p>
23+
<p>b: 2</p>
24+
`
25+
);
26+
}
27+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import Nested from './Nested.svelte';
3+
4+
export let a;
5+
export let b;
6+
</script>
7+
8+
<Nested a={a} b={b}/>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
get props() {
5+
return { a: 1, b: 2 };
6+
},
7+
8+
html: `
9+
<p>a: 1</p>
10+
<p>b: 2</p>
11+
<p>c: 3</p>
12+
`,
13+
14+
async test({ assert, component, target }) {
15+
await component.$set({ a: 4 });
16+
17+
assert.htmlEqual(
18+
target.innerHTML,
19+
`
20+
<p>a: 4</p>
21+
<p>b: 2</p>
22+
<p>c: 6</p>
23+
`
24+
);
25+
26+
await component.$set({ b: 5 });
27+
28+
assert.htmlEqual(
29+
target.innerHTML,
30+
`
31+
<p>a: 4</p>
32+
<p>b: 5</p>
33+
<p>c: 9</p>
34+
`
35+
);
36+
}
37+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
export let a;
3+
$: c = a + $$props.b;
4+
</script>
5+
6+
<p>a: {a}</p>
7+
<p>b: {$$props.b}</p>
8+
<p>c: {c}</p>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `
5+
<div>
6+
<p class="tooltip">static stuff</p>
7+
</div>
8+
<div>
9+
<p class="tooltip">dynamic stuff</p>
10+
</div>
11+
<button>unused</button>
12+
`
13+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script>
2+
import { spread } from './spread.js';
3+
let dynamic = 'dynamic';
4+
</script>
5+
6+
<div>
7+
<p {...spread()}>static stuff</p>
8+
</div>
9+
10+
<div>
11+
<p {...spread()}>{dynamic} stuff</p>
12+
</div>
13+
14+
<button on:click={() => dynamic = ''}>unused</button>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export function spread() {
2+
return {
3+
class: 'tooltip',
4+
id: null
5+
};
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
let name = 'World';
3+
</script>
4+
5+
<div>Hello {name}</div>
6+
7+
<style>
8+
div {
9+
color: red;
10+
}
11+
</style>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
skip_if_ssr: true,
5+
compileOptions: {
6+
cssHash: () => 'svelte-xyz'
7+
},
8+
async test({ assert, component, window }) {
9+
assert.htmlEqual(
10+
window.document.head.innerHTML,
11+
'<style>div.svelte-xyz\n{\ncolor:\nred;\n}</style>'
12+
);
13+
assert.htmlEqual(component.div.innerHTML, '<div class="svelte-xyz">Hello World</div>');
14+
}
15+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import App from './App.svelte';
3+
import { onMount, mount, unmount } from 'svelte';
4+
5+
export let div;
6+
7+
onMount(() => {
8+
div = document.createElement('div');
9+
10+
const app = mount(App, {
11+
target: div
12+
});
13+
14+
return () => {
15+
unmount(app);
16+
}
17+
});
18+
</script>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
let name = 'World';
3+
</script>
4+
5+
<div>Hello {name}</div>
6+
7+
<style>
8+
div {
9+
color: red;
10+
}
11+
</style>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
skip_if_ssr: true,
5+
compileOptions: {
6+
cssHash: () => 'svelte-xyz'
7+
},
8+
async test({ assert, component, window }) {
9+
assert.htmlEqual(
10+
window.document.head.innerHTML,
11+
'<style>div.svelte-xyz\n{\ncolor:\nred;\n}</style>'
12+
);
13+
assert.htmlEqual(component.div.innerHTML, '<div class="svelte-xyz">Hello World</div>');
14+
}
15+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
import App from './App.svelte';
3+
import { onMount, mount, unmount } from 'svelte';
4+
5+
export let div;
6+
7+
onMount(() => {
8+
const app = mount(App, {
9+
target: div
10+
});
11+
12+
return () => {
13+
unmount(app);
14+
}
15+
});
16+
</script>
17+
18+
<div bind:this={div} />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
let name = 'World';
3+
</script>
4+
5+
<div>Hello {name}</div>
6+
7+
<style>
8+
div {
9+
color: red;
10+
}
11+
</style>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
skip_if_ssr: true,
5+
compileOptions: {
6+
cssHash: () => 'svelte-xyz'
7+
},
8+
async test({ assert, component, window }) {
9+
assert.htmlEqual(
10+
window.document.head.innerHTML,
11+
'<style>div.svelte-xyz\n{\ncolor:\nred;\n}</style>'
12+
);
13+
assert.htmlEqual(
14+
component.div.shadowRoot.innerHTML,
15+
'<div class="svelte-xyz">Hello World</div>'
16+
);
17+
}
18+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script>
2+
import App from './App.svelte';
3+
import { onMount, mount, unmount } from 'svelte';
4+
5+
export let div;
6+
onMount(() => {
7+
const root = div.attachShadow({ mode: 'open' });
8+
9+
const app = mount(App, {
10+
target: root
11+
});
12+
13+
return () => {
14+
unmount(app);
15+
}
16+
});
17+
</script>
18+
19+
<div bind:this={div} />

0 commit comments

Comments
 (0)