Skip to content

Commit c5bab8d

Browse files
committed
merge
2 parents 0d8f27e + 232bb6f commit c5bab8d

File tree

16 files changed

+416
-29
lines changed

16 files changed

+416
-29
lines changed

.changeset/dry-mails-return.md

-5
This file was deleted.

.changeset/lemon-llamas-reflect.md

-5
This file was deleted.

.changeset/sour-pots-wonder.md

-5
This file was deleted.

documentation/docs/03-template-syntax/18-class.md

+12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ The user of this component has the same flexibility to use a mixture of objects,
7171
</Button>
7272
```
7373

74+
Svelte also exposes the `ClassValue` type, which is the type of value that the `class` attribute on elements accept. This is useful if you want to use a type-safe class name in component props:
75+
76+
```svelte
77+
<script lang="ts">
78+
import type { ClassValue } from 'svelte/elements';
79+
80+
const props: { class: ClassValue } = $props();
81+
</script>
82+
83+
<div class={['original', props.class]}>...</div>
84+
```
85+
7486
## The `class:` directive
7587

7688
Prior to Svelte 5.16, the `class:` directive was the most convenient way to set classes on elements conditionally.

packages/svelte/CHANGELOG.md

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# svelte
22

3+
## 5.19.0
4+
5+
### Minor Changes
6+
7+
- feat: Expose `ClassValue` from `svelte/elements` ([#15035](https://github.com/sveltejs/svelte/pull/15035))
8+
9+
### Patch Changes
10+
11+
- fix: create fewer deriveds for concatenated strings ([#15041](https://github.com/sveltejs/svelte/pull/15041))
12+
13+
- fix: correctly parse leading comments in function binding ([#15020](https://github.com/sveltejs/svelte/pull/15020))
14+
15+
## 5.18.0
16+
17+
### Minor Changes
18+
19+
- feat: allow `<template>` elements to contain any child ([#15007](https://github.com/sveltejs/svelte/pull/15007))
20+
21+
### Patch Changes
22+
23+
- fix: ensure resume effects are scheduled in topological order ([#15012](https://github.com/sveltejs/svelte/pull/15012))
24+
25+
- fix: bump esrap ([#15015](https://github.com/sveltejs/svelte/pull/15015))
26+
27+
- fix: remove listener on `bind_current_time` teardown ([#15013](https://github.com/sveltejs/svelte/pull/15013))
28+
329
## 5.17.5
430

531
### Patch Changes

packages/svelte/elements.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ export interface HTMLAttributes<T extends EventTarget> extends AriaAttributes, D
741741
accesskey?: string | undefined | null;
742742
autocapitalize?: 'characters' | 'off' | 'on' | 'none' | 'sentences' | 'words' | undefined | null;
743743
autofocus?: boolean | undefined | null;
744-
class?: string | import('clsx').ClassArray | import('clsx').ClassDictionary | undefined | null;
744+
class?: ClassValue | undefined | null;
745745
contenteditable?: Booleanish | 'inherit' | 'plaintext-only' | undefined | null;
746746
contextmenu?: string | undefined | null;
747747
dir?: 'ltr' | 'rtl' | 'auto' | undefined | null;
@@ -1522,7 +1522,7 @@ export interface SvelteWindowAttributes extends HTMLAttributes<Window> {
15221522
export interface SVGAttributes<T extends EventTarget> extends AriaAttributes, DOMAttributes<T> {
15231523
// Attributes which also defined in HTMLAttributes
15241524
className?: string | undefined | null;
1525-
class?: string | import('clsx').ClassArray | import('clsx').ClassDictionary | undefined | null;
1525+
class?: ClassValue | undefined | null;
15261526
color?: string | undefined | null;
15271527
height?: number | string | undefined | null;
15281528
id?: string | undefined | null;
@@ -2059,3 +2059,5 @@ export interface SvelteHTMLElements {
20592059

20602060
[name: string]: { [name: string]: any };
20612061
}
2062+
2063+
export type ClassValue = string | import('clsx').ClassArray | import('clsx').ClassDictionary;

packages/svelte/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svelte",
33
"description": "Cybernetically enhanced web apps",
44
"license": "MIT",
5-
"version": "5.17.5",
5+
"version": "5.19.0",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {
@@ -155,7 +155,7 @@
155155
"axobject-query": "^4.1.0",
156156
"clsx": "^2.1.1",
157157
"esm-env": "^1.2.1",
158-
"esrap": "^1.4.2",
158+
"esrap": "^1.4.3",
159159
"is-reference": "^3.0.3",
160160
"locate-character": "^3.0.0",
161161
"magic-string": "^0.30.11",

packages/svelte/src/compiler/phases/1-parse/read/expression.js

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export default function read_expression(parser, opening_token, disallow_loose) {
3838

3939
let num_parens = 0;
4040

41+
if (node.leadingComments !== undefined && node.leadingComments.length > 0) {
42+
parser.index = node.leadingComments.at(-1).end;
43+
}
44+
4145
for (let i = parser.index; i < /** @type {number} */ (node.start); i += 1) {
4246
if (parser.template[i] === '(') num_parens += 1;
4347
}

packages/svelte/src/compiler/phases/2-analyze/visitors/BindDirective.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,19 @@ export function BindDirective(node, context) {
132132
}
133133

134134
let i = /** @type {number} */ (node.expression.start);
135+
let leading_comments_start = /**@type {any}*/ (node.expression.leadingComments?.at(0))?.start;
136+
let leading_comments_end = /**@type {any}*/ (node.expression.leadingComments?.at(-1))?.end;
135137
while (context.state.analysis.source[--i] !== '{') {
136-
if (context.state.analysis.source[i] === '(') {
138+
if (
139+
context.state.analysis.source[i] === '(' &&
140+
// if the parenthesis is in a leading comment we don't need to throw the error
141+
!(
142+
leading_comments_start &&
143+
leading_comments_end &&
144+
i <= leading_comments_end &&
145+
i >= leading_comments_start
146+
)
147+
) {
137148
e.bind_invalid_parens(node, node.name);
138149
}
139150
}

packages/svelte/src/version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* The current version, as set in package.json.
55
* @type {string}
66
*/
7-
export const VERSION = '5.17.5';
7+
export const VERSION = '5.19.0';
88
export const PUBLIC_VERSION = '5';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
let value = '';
3+
</script>
4+
5+
<input bind:value={
6+
/** ( */
7+
() => value,
8+
(v) => value = v.toLowerCase()
9+
}
10+
/>

0 commit comments

Comments
 (0)