Skip to content

Commit be3a8a8

Browse files
committed
feat: error on imports to svelte/internal/*
closes #11622
1 parent 87a420f commit be3a8a8

File tree

7 files changed

+43
-0
lines changed

7 files changed

+43
-0
lines changed

.changeset/eight-carrots-hunt.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
feat: error on imports to `svelte/internal/*`

packages/svelte/messages/compile-errors/script.md

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646

4747
> `$host()` can only be used inside custom element component instances
4848
49+
## import_svelte_internal_forbidden
50+
51+
> 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
52+
4953
## legacy_export_invalid
5054

5155
> Cannot use `export let` in runes mode — use `$props()` instead

packages/svelte/src/compiler/errors.js

+9
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,15 @@ export function store_invalid_subscription(node) {
404404
e(node, "store_invalid_subscription", "Cannot reference store value inside `<script context=\"module\">`");
405405
}
406406

407+
/**
408+
* 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
409+
* @param {null | number | NodeLike} node
410+
* @returns {never}
411+
*/
412+
export function import_svelte_internal_forbidden(node) {
413+
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");
414+
}
415+
407416
/**
408417
* Declaration cannot be empty
409418
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/phases/2-analyze/validation.js

+10
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,11 @@ function ensure_no_module_import_conflict(node, state) {
905905
* @type {import('zimmerframe').Visitors<import('#compiler').SvelteNode, import('./types.js').AnalysisState>}
906906
*/
907907
export const validation_runes_js = {
908+
ImportDeclaration(node) {
909+
if (typeof node.source.value === 'string' && node.source.value.startsWith('svelte/internal/')) {
910+
e.import_svelte_internal_forbidden(node);
911+
}
912+
},
908913
ExportSpecifier(node, { state }) {
909914
validate_export(node, state.scope, node.local.name);
910915
},
@@ -1077,6 +1082,11 @@ function validate_assignment(node, argument, state) {
10771082
}
10781083

10791084
export const validation_runes = merge(validation, a11y_validators, {
1085+
ImportDeclaration(node) {
1086+
if (typeof node.source.value === 'string' && node.source.value.startsWith('svelte/internal/')) {
1087+
e.import_svelte_internal_forbidden(node);
1088+
}
1089+
},
10801090
Identifier(node, { path, state }) {
10811091
let i = path.length;
10821092
let parent = /** @type {import('estree').Expression} */ (path[--i]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
error: {
5+
code: 'import_svelte_internal_forbidden',
6+
message:
7+
"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"
8+
}
9+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<svelte:options runes={true} />
2+
3+
<script>
4+
import { something } from 'svelte/internal/client';
5+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { something } from 'svelte/internal/server';

0 commit comments

Comments
 (0)