-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not expose default slot let bindings to named slots (#6049)
* should not extend scope for across slots * disallow named slots inheriting let: scope from default slots * fix tests * fix test * fix * add runtime tests * rename test since it doesn't inherit anymore * fix lint * remove warnings * add compile script * document script * improve warning * fix test * handle renames * fix lint * gather names from all parents instead of just the nearest * remove unused import * add reminder --------- Co-authored-by: gtmnayan <gtmnayan@gmail.com>
- Loading branch information
Showing
29 changed files
with
228 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Compile all Svelte files in a directory to JS and CSS files | ||
// Usage: node scripts/compile-test.js <directory> | ||
|
||
import { mkdirSync, readFileSync, writeFileSync } from 'fs'; | ||
import path from 'path'; | ||
import glob from 'tiny-glob/sync.js'; | ||
import { compile } from '../src/compiler/index.js'; | ||
|
||
const cwd = path.resolve(process.argv[2]); | ||
|
||
const options = [ | ||
['normal', {}], | ||
['hydrate', { hydratable: true }], | ||
['ssr', { generate: 'ssr' }] | ||
]; | ||
for (const file of glob('**/*.svelte', { cwd })) { | ||
const contents = readFileSync(`${cwd}/${file}`, 'utf-8').replace(/\r/g, ''); | ||
let w; | ||
for (const [name, opts] of options) { | ||
const dir = `${cwd}/_output/${name}`; | ||
|
||
const { js, css, warnings } = compile(contents, { | ||
...opts, | ||
filename: file | ||
}); | ||
|
||
if (warnings.length) { | ||
w = warnings; | ||
} | ||
|
||
mkdirSync(dir, { recursive: true }); | ||
js.code && writeFileSync(`${dir}/${file.replace(/\.svelte$/, '.js')}`, js.code); | ||
css.code && writeFileSync(`${dir}/${file.replace(/\.svelte$/, '.css')}`, css.code); | ||
} | ||
|
||
if (w) { | ||
console.log(`Warnings for ${file}:`); | ||
console.log(w); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
test/runtime/samples/component-slot-default-in-each/Nested.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script> | ||
let promise = new Promise(resolve => resolve(10)); | ||
</script> | ||
|
||
{#each {length: 3} as _, i} | ||
<slot item={i}/> | ||
{/each} | ||
|
||
{#await promise then value} | ||
<slot {value}/> | ||
{/await} |
7 changes: 7 additions & 0 deletions
7
test/runtime/samples/component-slot-default-in-each/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default { | ||
html: ` | ||
<div>0 - undefined</div> | ||
<div>1 - undefined</div> | ||
<div>2 - undefined</div> | ||
` | ||
}; |
7 changes: 7 additions & 0 deletions
7
test/runtime/samples/component-slot-default-in-each/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
import Nested from './Nested.svelte'; | ||
</script> | ||
|
||
<Nested let:item let:value> | ||
<div>{item} - {value}</div> | ||
</Nested> |
3 changes: 3 additions & 0 deletions
3
test/runtime/samples/component-slot-let-scope-2/Nested.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<slot /> | ||
<slot thing={2} name="thing"/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
html: '<span>undefined</span><span>2</span>' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script> | ||
import Nested from './Nested.svelte'; | ||
</script> | ||
|
||
<Nested let:thing> | ||
<span>{thing}</span> | ||
<svelte:fragment slot="thing" let:thing><span>{thing}</span></svelte:fragment> | ||
</Nested> |
2 changes: 0 additions & 2 deletions
2
...named-inherits-default-lets/Nested.svelte → .../component-slot-let-scope-3/Nested.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
<script> | ||
import { onDestroy } from 'svelte'; | ||
let count = 0; | ||
function increment() { | ||
|
Oops, something went wrong.