From 4d5fe5dea6ab3264ed5d49b5baccd13b8fe38ca0 Mon Sep 17 00:00:00 2001 From: Alexandre Galays Date: Thu, 28 Jan 2021 12:56:40 +0100 Subject: [PATCH 1/4] Swap the order of the two derived store signatures to fix inference (#5935) --- src/runtime/store/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime/store/index.ts b/src/runtime/store/index.ts index 09040487f0..c8e2b4ff99 100644 --- a/src/runtime/store/index.ts +++ b/src/runtime/store/index.ts @@ -125,10 +125,12 @@ type StoresValues = T extends Readable ? U : * * @param stores - input stores * @param fn - function callback that aggregates the values + * @param initial_value - when used asynchronously */ export function derived( stores: S, - fn: (values: StoresValues) => T + fn: (values: StoresValues, set: (value: T) => void) => Unsubscriber | void, + initial_value?: T ): Readable; /** @@ -137,12 +139,10 @@ export function derived( * * @param stores - input stores * @param fn - function callback that aggregates the values - * @param initial_value - when used asynchronously */ export function derived( stores: S, - fn: (values: StoresValues, set: (value: T) => void) => Unsubscriber | void, - initial_value?: T + fn: (values: StoresValues) => T ): Readable; export function derived(stores: Stores, fn: Function, initial_value?: T): Readable { From b3431f9bf204cee58db751e083f3e45198379cb8 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 29 Jan 2021 10:20:06 -0500 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18387d2090..c8e3a1d181 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Svelte changelog +## Unreleased + +* Fix type inference for derived stores ([#5935](https://github.com/sveltejs/svelte/pull/5935)) + ## 3.32.0 * Allow multiple instances of the same action on an element ([#5516](https://github.com/sveltejs/svelte/issues/5516)) From acf60d88a069ee3df2eafd122106db3acc560bd0 Mon Sep 17 00:00:00 2001 From: Anders Lorentsen Date: Fri, 29 Jan 2021 16:33:40 +0100 Subject: [PATCH 3/4] error on empty name in `class:` directive (#5939) --- src/compiler/parse/state/tag.ts | 7 +++++++ .../samples/error-empty-classname-binding/error.json | 10 ++++++++++ .../samples/error-empty-classname-binding/input.svelte | 1 + 3 files changed, 18 insertions(+) create mode 100644 test/parser/samples/error-empty-classname-binding/error.json create mode 100644 test/parser/samples/error-empty-classname-binding/input.svelte diff --git a/src/compiler/parse/state/tag.ts b/src/compiler/parse/state/tag.ts index 696a47b649..aedffffe21 100644 --- a/src/compiler/parse/state/tag.ts +++ b/src/compiler/parse/state/tag.ts @@ -387,6 +387,13 @@ function read_attribute(parser: Parser, unique_names: Set) { }, start); } + if (type === 'Class' && directive_name === '') { + parser.error({ + code: 'invalid-class-directive', + message: 'Class binding name cannot be empty' + }, start + colon_index + 1); + } + if (value[0]) { if ((value as any[]).length > 1 || value[0].type === 'Text') { parser.error({ diff --git a/test/parser/samples/error-empty-classname-binding/error.json b/test/parser/samples/error-empty-classname-binding/error.json new file mode 100644 index 0000000000..edc09ff8e1 --- /dev/null +++ b/test/parser/samples/error-empty-classname-binding/error.json @@ -0,0 +1,10 @@ +{ + "code": "invalid-class-directive", + "message": "Class binding name cannot be empty", + "start": { + "line": 1, + "column": 10, + "character": 10 + }, + "pos": 10 +} diff --git a/test/parser/samples/error-empty-classname-binding/input.svelte b/test/parser/samples/error-empty-classname-binding/input.svelte new file mode 100644 index 0000000000..3a4e5980ee --- /dev/null +++ b/test/parser/samples/error-empty-classname-binding/input.svelte @@ -0,0 +1 @@ +

Hello

From f00348c14c430e23ff48ec4f3c0580fa2cf0c9a0 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 29 Jan 2021 10:34:30 -0500 Subject: [PATCH 4/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8e3a1d181..928f76bfc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +* Throw a parser error for `class:` directives with an empty class name ([#5858](https://github.com/sveltejs/svelte/issues/5858)) * Fix type inference for derived stores ([#5935](https://github.com/sveltejs/svelte/pull/5935)) ## 3.32.0