Skip to content

add some missing legacy tests #10875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/svelte/src/compiler/phases/2-analyze/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,10 +753,11 @@ const legacy_scope_tweaker = {
state.scope.get(specifier.local.name)
);
if (
binding.kind === 'state' ||
binding.kind === 'frozen_state' ||
(binding.kind === 'normal' &&
(binding.declaration_kind === 'let' || binding.declaration_kind === 'var'))
binding !== null &&
(binding.kind === 'state' ||
binding.kind === 'frozen_state' ||
(binding.kind === 'normal' &&
(binding.declaration_kind === 'let' || binding.declaration_kind === 'var')))
) {
binding.kind = 'prop';
if (specifier.exported.name !== specifier.local.name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
export let a;
export const b = 2;
</script>

<p>a: {a}</p>
<p>b: {b}</p>
27 changes: 27 additions & 0 deletions packages/svelte/tests/runtime-legacy/samples/prop-const/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { test } from '../../test';

export default test({
get props() {
return { a: 3, b: 4 };
},

html: `
<p>a: 3</p>
<p>b: 2</p>
`,

async test({ assert, component, target }) {
await component.$set({
a: 5,
b: 6
});

assert.htmlEqual(
target.innerHTML,
`
<p>a: 5</p>
<p>b: 2</p>
`
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import Nested from './Nested.svelte';

export let a;
export let b;
</script>

<Nested a={a} b={b}/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { test } from '../../test';

export default test({
get props() {
return { a: 1, b: 2 };
},

html: `
<p>a: 1</p>
<p>b: 2</p>
<p>c: 3</p>
`,

async test({ assert, component, target }) {
await component.$set({ a: 4 });

assert.htmlEqual(
target.innerHTML,
`
<p>a: 4</p>
<p>b: 2</p>
<p>c: 6</p>
`
);

await component.$set({ b: 5 });

assert.htmlEqual(
target.innerHTML,
`
<p>a: 4</p>
<p>b: 5</p>
<p>c: 9</p>
`
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
export let a;
$: c = a + $$props.b;
</script>

<p>a: {a}</p>
<p>b: {$$props.b}</p>
<p>c: {c}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test } from '../../test';

export default test({
html: `
<div>
<p class="tooltip">static stuff</p>
</div>
<div>
<p class="tooltip">dynamic stuff</p>
</div>
<button>unused</button>
`
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script>
import { spread } from './spread.js';
let dynamic = 'dynamic';
</script>

<div>
<p {...spread()}>static stuff</p>
</div>

<div>
<p {...spread()}>{dynamic} stuff</p>
</div>

<button on:click={() => dynamic = ''}>unused</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function spread() {
return {
class: 'tooltip',
id: null
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
let name = 'World';
</script>

<div>Hello {name}</div>

<style>
div {
color: red;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test } from '../../test';

export default test({
skip_if_ssr: true,
compileOptions: {
cssHash: () => 'svelte-xyz'
},
async test({ assert, component, window }) {
assert.htmlEqual(
window.document.head.innerHTML,
'<style>div.svelte-xyz\n{\ncolor:\nred;\n}</style>'
);
assert.htmlEqual(component.div.innerHTML, '<div class="svelte-xyz">Hello World</div>');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
import App from './App.svelte';
import { onMount, mount, unmount } from 'svelte';

export let div;

onMount(() => {
div = document.createElement('div');

const app = mount(App, {
target: div
});

return () => {
unmount(app);
}
});
</script>
11 changes: 11 additions & 0 deletions packages/svelte/tests/runtime-legacy/samples/target-dom/App.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
let name = 'World';
</script>

<div>Hello {name}</div>

<style>
div {
color: red;
}
</style>
15 changes: 15 additions & 0 deletions packages/svelte/tests/runtime-legacy/samples/target-dom/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { test } from '../../test';

export default test({
skip_if_ssr: true,
compileOptions: {
cssHash: () => 'svelte-xyz'
},
async test({ assert, component, window }) {
assert.htmlEqual(
window.document.head.innerHTML,
'<style>div.svelte-xyz\n{\ncolor:\nred;\n}</style>'
);
assert.htmlEqual(component.div.innerHTML, '<div class="svelte-xyz">Hello World</div>');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
import App from './App.svelte';
import { onMount, mount, unmount } from 'svelte';

export let div;

onMount(() => {
const app = mount(App, {
target: div
});

return () => {
unmount(app);
}
});
</script>

<div bind:this={div} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
let name = 'World';
</script>

<div>Hello {name}</div>

<style>
div {
color: red;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test } from '../../test';

export default test({
skip_if_ssr: true,
compileOptions: {
cssHash: () => 'svelte-xyz'
},
async test({ assert, component, window }) {
assert.htmlEqual(
window.document.head.innerHTML,
'<style>div.svelte-xyz\n{\ncolor:\nred;\n}</style>'
);
assert.htmlEqual(
component.div.shadowRoot.innerHTML,
'<div class="svelte-xyz">Hello World</div>'
);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
import App from './App.svelte';
import { onMount, mount, unmount } from 'svelte';

export let div;
onMount(() => {
const root = div.attachShadow({ mode: 'open' });

const app = mount(App, {
target: root
});

return () => {
unmount(app);
}
});
</script>

<div bind:this={div} />