Skip to content

Commit

Permalink
fix const declared without let: binding get ignored (#7434)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Apr 12, 2022
1 parent 1e0c10b commit e50be66
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/compiler/compile/nodes/SlotTemplate.ts
Expand Up @@ -27,10 +27,7 @@ export default class SlotTemplate extends Node {

this.validate_slot_template_placement();

const has_let = info.attributes.some((node) => node.type === 'Let');
if (has_let) {
scope = scope.child();
}
scope = scope.child();

info.attributes.forEach((node) => {
switch (node.type) {
Expand Down
@@ -0,0 +1,2 @@
<slot name="box1" />
<slot />
15 changes: 15 additions & 0 deletions test/runtime/samples/const-tag-component-without-let/_config.js
@@ -0,0 +1,15 @@
export default {
html: `
<div>static dynamic</div>
<div>static dynamic</div>
<div>static dynamic</div>
`,
async test({ component, target, assert }) {
component.props = 'xxx';
assert.htmlEqual(target.innerHTML, `
<div>static xxx</div>
<div>static xxx</div>
<div>static xxx</div>
`);
}
};
24 changes: 24 additions & 0 deletions test/runtime/samples/const-tag-component-without-let/main.svelte
@@ -0,0 +1,24 @@
<script>
import Component from './Component.svelte';
export let props = "dynamic";
</script>

<Component>
<svelte:fragment slot="box1">
{@const foo = "static"}
{@const bar = props}
<div>{foo} {bar}</div>
</svelte:fragment>

<svelte:fragment>
{@const foo = "static"}
{@const bar = props}
<div>{foo} {bar}</div>
</svelte:fragment>
</Component>

<Component>
{@const foo = "static"}
{@const bar = props}
<div>{foo} {bar}</div>
</Component>

0 comments on commit e50be66

Please sign in to comment.