From dfb675551413e9ac8bcaedebf736a73cecb94116 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 12 Aug 2024 15:42:33 -0400 Subject: [PATCH] feat: add compiler error when encountering a $-prefixed store value outside a `.svelte` file (#12799) * feat: add compiler error when encountering a $-prefixed store value outside a .svelte file * add fromState/toState APIs * another test, update types * rename fromState to toStore, and toState to fromStore * docs * add docs * separate client/server entry points for svelte/store --- .changeset/curvy-papayas-pretend.md | 5 + .../svelte/messages/compile-errors/script.md | 6 + packages/svelte/package.json | 3 +- packages/svelte/src/compiler/errors.js | 9 + .../src/compiler/phases/2-analyze/index.js | 6 + packages/svelte/src/motion/spring.js | 2 +- packages/svelte/src/motion/tweened.js | 2 +- packages/svelte/src/store/index-client.js | 165 ++++++++++++++++++ packages/svelte/src/store/index-server.js | 101 +++++++++++ packages/svelte/src/store/public.d.ts | 2 +- .../svelte/src/store/{ => shared}/index.js | 10 +- .../_config.js | 8 + .../main.svelte.js | 3 + packages/svelte/tests/store/test.ts | 108 +++++++++++- packages/svelte/types/index.d.ts | 11 ++ .../routes/docs/content/01-api/05-imports.md | 41 +++++ 16 files changed, 472 insertions(+), 10 deletions(-) create mode 100644 .changeset/curvy-papayas-pretend.md create mode 100644 packages/svelte/src/store/index-client.js create mode 100644 packages/svelte/src/store/index-server.js rename packages/svelte/src/store/{ => shared}/index.js (95%) create mode 100644 packages/svelte/tests/compiler-errors/samples/runes-module-store-subscription/_config.js create mode 100644 packages/svelte/tests/compiler-errors/samples/runes-module-store-subscription/main.svelte.js diff --git a/.changeset/curvy-papayas-pretend.md b/.changeset/curvy-papayas-pretend.md new file mode 100644 index 0000000000..d5357dc5bc --- /dev/null +++ b/.changeset/curvy-papayas-pretend.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +feat: add compiler error when encountering a $-prefixed store value outside a .svelte file diff --git a/packages/svelte/messages/compile-errors/script.md b/packages/svelte/messages/compile-errors/script.md index d31c04b99c..6e15fa06d5 100644 --- a/packages/svelte/messages/compile-errors/script.md +++ b/packages/svelte/messages/compile-errors/script.md @@ -149,3 +149,9 @@ ## store_invalid_subscription > Cannot reference store value inside `