Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/nervous-hotels-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: attach `__svelte_meta` correctly to elements following a CSS wrapper
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @import { BlockStatement, Expression, ExpressionStatement, Identifier, MemberExpression, Pattern, Property, SequenceExpression, Statement } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../../types.js' */
import { dev, is_ignored } from '../../../../../state.js';
import { dev, is_ignored, locator } from '../../../../../state.js';
import { get_attribute_chunks, object } from '../../../../../utils/ast.js';
import * as b from '#compiler/builders';
import { build_bind_this, memoize_expression, validate_binding } from '../shared/utils.js';
Expand Down Expand Up @@ -440,6 +440,13 @@ export function build_component(node, component_name, context, anchor = context.
}

if (Object.keys(custom_css_props).length > 0) {
if (dev) {
const loc = locator(node.start);
if (loc) {
context.state.locations.push([loc.line, loc.column]);
}
}

context.state.template.push(
context.state.metadata.namespace === 'svg'
? '<g><!></g>'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h2>hello from component</h2>

<style>
h2 {
color: var(--color);
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { test } from '../../test';

export default test({
compileOptions: {
dev: true
},

html: `
<h1>hello</h1>
<svelte-css-wrapper style="display: contents; --color: red;">
<h2 class="svelte-13kae5a">hello from component</h2>
</svelte-css-wrapper>
<p>goodbye</p>
`,

async test({ target, assert }) {
const h1 = target.querySelector('h1');
const h2 = target.querySelector('h2');
const p = target.querySelector('p');

// @ts-expect-error
assert.deepEqual(h1.__svelte_meta.loc, {
file: 'main.svelte',
line: 5,
column: 0
});

// @ts-expect-error
assert.deepEqual(h2.__svelte_meta.loc, {
file: 'Component.svelte',
line: 1,
column: 0
});

// @ts-expect-error
assert.deepEqual(p.__svelte_meta.loc, {
file: 'main.svelte',
line: 7,
column: 0
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import Component from './Component.svelte';
</script>

<h1>hello</h1>
<Component --color="red" />
<p>goodbye</p>