Skip to content

Commit 60148d3

Browse files
fix: order of arguments for push_element in svelte:element (#12763)
* fix: order of arguments for `push_element` in `svelte:element` * chore: move test to runtime * fix: add line and column to function call
1 parent 1942f87 commit 60148d3

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

.changeset/six-apes-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: order of arguments for `push_element` in `svelte:element`

packages/svelte/src/compiler/phases/3-transform/server/visitors/SvelteElement.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/** @import { Location } from 'locate-character' */
12
/** @import { BlockStatement, Expression } from 'estree' */
23
/** @import { SvelteElement } from '#compiler' */
34
/** @import { ComponentContext } from '../types.js' */
4-
import { dev } from '../../../../state.js';
5+
import { dev, locator } from '../../../../state.js';
56
import * as b from '../../../../utils/builders.js';
67
import { determine_namespace_for_children } from '../../utils.js';
78
import { build_element_attributes } from './shared/element.js';
@@ -36,7 +37,18 @@ export function SvelteElement(node, context) {
3637
build_element_attributes(node, { ...context, state });
3738

3839
if (dev) {
39-
context.state.template.push(b.stmt(b.call('$.push_element', tag, b.id('$$payload'))));
40+
const location = /** @type {Location} */ (locator(node.start));
41+
context.state.template.push(
42+
b.stmt(
43+
b.call(
44+
'$.push_element',
45+
b.id('$$payload'),
46+
tag,
47+
b.literal(location.line),
48+
b.literal(location.column)
49+
)
50+
)
51+
);
4052
}
4153

4254
const attributes = b.block([...state.init, ...build_template(state.template)]);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
compileOptions: {
5+
dev: true
6+
}
7+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!--[--><!----><p ><!----><p ><!----></p><!----><!----></p><!----><!--]-->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script>console.error("node_invalid_placement_ssr: `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:1:0) cannot contain `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:2:1)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.")</script>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<svelte:element this={'p'}>
2+
<svelte:element this={'p'}></svelte:element>
3+
</svelte:element>

0 commit comments

Comments
 (0)