From be3a8a82fbb22cc3ae1d54aa80c2418bdbb02a79 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Wed, 15 May 2024 12:04:21 +0200 Subject: [PATCH 1/3] feat: error on imports to `svelte/internal/*` closes #11622 --- .changeset/eight-carrots-hunt.md | 5 +++++ packages/svelte/messages/compile-errors/script.md | 4 ++++ packages/svelte/src/compiler/errors.js | 9 +++++++++ .../svelte/src/compiler/phases/2-analyze/validation.js | 10 ++++++++++ .../samples/svelte-internal-import/_config.js | 9 +++++++++ .../samples/svelte-internal-import/main.svelte | 5 +++++ .../samples/svelte-internal-import/main.svelte.js | 1 + 7 files changed, 43 insertions(+) create mode 100644 .changeset/eight-carrots-hunt.md create mode 100644 packages/svelte/tests/compiler-errors/samples/svelte-internal-import/_config.js create mode 100644 packages/svelte/tests/compiler-errors/samples/svelte-internal-import/main.svelte create mode 100644 packages/svelte/tests/compiler-errors/samples/svelte-internal-import/main.svelte.js diff --git a/.changeset/eight-carrots-hunt.md b/.changeset/eight-carrots-hunt.md new file mode 100644 index 000000000000..a220e13080e7 --- /dev/null +++ b/.changeset/eight-carrots-hunt.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +feat: error on imports to `svelte/internal/*` diff --git a/packages/svelte/messages/compile-errors/script.md b/packages/svelte/messages/compile-errors/script.md index 861ac2f56d39..dbce3403d41a 100644 --- a/packages/svelte/messages/compile-errors/script.md +++ b/packages/svelte/messages/compile-errors/script.md @@ -46,6 +46,10 @@ > `$host()` can only be used inside custom element component instances +## import_svelte_internal_forbidden + +> Imports of `svelte/internal/*` are forbidden. It contains private runtime code which is subject to change without notice. If you're importing from `svelte/internal/*` to work around a limitation of Svelte, please open an issue at https://github.com/sveltejs/svelte and explain your use case + ## legacy_export_invalid > Cannot use `export let` in runes mode — use `$props()` instead diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index ab7197b06b8d..f6da8165fbf2 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -404,6 +404,15 @@ export function store_invalid_subscription(node) { e(node, "store_invalid_subscription", "Cannot reference store value inside ` \ No newline at end of file diff --git a/packages/svelte/tests/compiler-errors/samples/svelte-internal-import/main.svelte.js b/packages/svelte/tests/compiler-errors/samples/svelte-internal-import/main.svelte.js new file mode 100644 index 000000000000..8047b01e681e --- /dev/null +++ b/packages/svelte/tests/compiler-errors/samples/svelte-internal-import/main.svelte.js @@ -0,0 +1 @@ +import { something } from 'svelte/internal/server'; From 2afafea120a837aaa5cd8ca830f57589aab6981f Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Wed, 15 May 2024 12:16:04 +0200 Subject: [PATCH 2/3] regenerate --- packages/svelte/src/compiler/errors.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index f6da8165fbf2..8a2832df1bd6 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -198,6 +198,15 @@ export function host_invalid_placement(node) { e(node, "host_invalid_placement", "`$host()` can only be used inside custom element component instances"); } +/** + * Imports of `svelte/internal/*` are forbidden. It contains private runtime code which is subject to change without notice. If you're importing from `svelte/internal/*` to work around a limitation of Svelte, please open an issue at https://github.com/sveltejs/svelte and explain your use case + * @param {null | number | NodeLike} node + * @returns {never} + */ +export function import_svelte_internal_forbidden(node) { + e(node, "import_svelte_internal_forbidden", "Imports of `svelte/internal/*` are forbidden. It contains private runtime code which is subject to change without notice. If you're importing from `svelte/internal/*` to work around a limitation of Svelte, please open an issue at https://github.com/sveltejs/svelte and explain your use case"); +} + /** * Cannot use `export let` in runes mode — use `$props()` instead * @param {null | number | NodeLike} node @@ -404,15 +413,6 @@ export function store_invalid_subscription(node) { e(node, "store_invalid_subscription", "Cannot reference store value inside `