Skip to content

Commit f111cf6

Browse files
authored
deconflict anchor variable name (#4769)
1 parent a658fed commit f111cf6

File tree

12 files changed

+24
-13
lines changed

12 files changed

+24
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Do not display a11y warning about missing `href` for `<a>` with `name` or `id` ([#4697](https://github.com/sveltejs/svelte/issues/4697))
88
* Disable infinite loop guard inside generators ([#4698](https://github.com/sveltejs/svelte/issues/4698))
99
* Display a11y warning for `href="javascript:..."` ([#4733](https://github.com/sveltejs/svelte/pull/4733))
10+
* Fix variable name conflict with component called `<Anchor>` ([#4768](https://github.com/sveltejs/svelte/issues/4768))
1011

1112
## 3.21.0
1213

src/compiler/compile/render_dom/Block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export default class Block {
185185
this.chunks.mount.push(b`@append(${parent_node}, ${id});`);
186186
if (is_head(parent_node) && !no_detach) this.chunks.destroy.push(b`@detach(${id});`);
187187
} else {
188-
this.chunks.mount.push(b`@insert(#target, ${id}, anchor);`);
188+
this.chunks.mount.push(b`@insert(#target, ${id}, #anchor);`);
189189
if (!no_detach) this.chunks.destroy.push(b`if (detaching) @detach(${id});`);
190190
}
191191
}
@@ -295,11 +295,11 @@ export default class Block {
295295
if (this.chunks.mount.length === 0) {
296296
properties.mount = noop;
297297
} else if (this.event_listeners.length === 0) {
298-
properties.mount = x`function #mount(#target, anchor) {
298+
properties.mount = x`function #mount(#target, #anchor) {
299299
${this.chunks.mount}
300300
}`;
301301
} else {
302-
properties.mount = x`function #mount(#target, anchor, #remount) {
302+
properties.mount = x`function #mount(#target, #anchor, #remount) {
303303
${this.chunks.mount}
304304
}`;
305305
}

src/compiler/compile/render_dom/wrappers/AwaitBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export default class AwaitBlockWrapper extends Wrapper {
200200
}
201201

202202
const initial_mount_node = parent_node || '#target';
203-
const anchor_node = parent_node ? 'null' : 'anchor';
203+
const anchor_node = parent_node ? 'null' : '#anchor';
204204

205205
const has_transitions = this.pending.block.has_intro_method || this.pending.block.has_outro_method;
206206

src/compiler/compile/render_dom/wrappers/EachBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export default class EachBlockWrapper extends Wrapper {
219219
}
220220
`);
221221

222-
const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : 'anchor' };
222+
const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : '#anchor' };
223223
const initial_mount_node: Identifier = parent_node || { type: 'Identifier', name: '#target' };
224224
const update_anchor_node = needs_anchor
225225
? block.get_unique_name(`${this.var.name}_anchor`)

src/compiler/compile/render_dom/wrappers/Element/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export default class ElementWrapper extends Wrapper {
320320
block.chunks.destroy.push(b`@detach(${node});`);
321321
}
322322
} else {
323-
block.chunks.mount.push(b`@insert(#target, ${node}, anchor);`);
323+
block.chunks.mount.push(b`@insert(#target, ${node}, #anchor);`);
324324

325325
// TODO we eventually need to consider what happens to elements
326326
// that belong to the same outgroup as an outroing element...

src/compiler/compile/render_dom/wrappers/IfBlock.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export default class IfBlockWrapper extends Wrapper {
293293
`);
294294

295295
const initial_mount_node = parent_node || '#target';
296-
const anchor_node = parent_node ? 'null' : 'anchor';
296+
const anchor_node = parent_node ? 'null' : '#anchor';
297297

298298
if (if_exists_condition) {
299299
block.chunks.mount.push(
@@ -423,7 +423,7 @@ export default class IfBlockWrapper extends Wrapper {
423423
}
424424

425425
const initial_mount_node = parent_node || '#target';
426-
const anchor_node = parent_node ? 'null' : 'anchor';
426+
const anchor_node = parent_node ? 'null' : '#anchor';
427427

428428
block.chunks.mount.push(
429429
if_current_block_type_index(
@@ -519,7 +519,7 @@ export default class IfBlockWrapper extends Wrapper {
519519
`);
520520

521521
const initial_mount_node = parent_node || '#target';
522-
const anchor_node = parent_node ? 'null' : 'anchor';
522+
const anchor_node = parent_node ? 'null' : '#anchor';
523523

524524
block.chunks.mount.push(
525525
b`if (${name}) ${name}.m(${initial_mount_node}, ${anchor_node});`

src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ export default class InlineComponentWrapper extends Wrapper {
435435

436436
block.chunks.mount.push(b`
437437
if (${name}) {
438-
@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : 'anchor'});
438+
@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});
439439
}
440440
`);
441441

@@ -509,7 +509,7 @@ export default class InlineComponentWrapper extends Wrapper {
509509
}
510510

511511
block.chunks.mount.push(
512-
b`@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : 'anchor'});`
512+
b`@mount_component(${name}, ${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});`
513513
);
514514

515515
block.chunks.intro.push(b`

src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class RawMustacheTagWrapper extends Tag {
5454
const update_anchor = in_head ? 'null' : needs_anchor ? html_anchor : this.next ? this.next.var : 'null';
5555

5656
block.chunks.hydrate.push(b`${html_tag} = new @HtmlTag(${init}, ${update_anchor});`);
57-
block.chunks.mount.push(b`${html_tag}.m(${parent_node || '#target'}, ${parent_node ? null : 'anchor'});`);
57+
block.chunks.mount.push(b`${html_tag}.m(${parent_node || '#target'}, ${parent_node ? null : '#anchor'});`);
5858

5959
if (needs_anchor) {
6060
block.add_element(html_anchor, x`@empty()`, x`@empty()`, parent_node);

src/compiler/compile/render_dom/wrappers/Slot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default class SlotWrapper extends Wrapper {
145145

146146
block.chunks.mount.push(b`
147147
if (${slot_or_fallback}) {
148-
${slot_or_fallback}.m(${parent_node || '#target'}, ${parent_node ? 'null' : 'anchor'});
148+
${slot_or_fallback}.m(${parent_node || '#target'}, ${parent_node ? 'null' : '#anchor'});
149149
}
150150
`);
151151

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>Anchor</p>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
preserveIdentifiers: true,
3+
html: `<p>Anchor</p>`
4+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
import Anchor from './Anchor.svelte';
3+
</script>
4+
5+
<Anchor/>

0 commit comments

Comments
 (0)