Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eight-carrots-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

feat: error on imports to `svelte/internal/*`
4 changes: 4 additions & 0 deletions packages/svelte/messages/compile-errors/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions packages/svelte/src/compiler/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions packages/svelte/src/compiler/phases/2-analyze/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,11 @@ function ensure_no_module_import_conflict(node, state) {
* @type {import('zimmerframe').Visitors<import('#compiler').SvelteNode, import('./types.js').AnalysisState>}
*/
export const validation_runes_js = {
ImportDeclaration(node) {
if (typeof node.source.value === 'string' && node.source.value.startsWith('svelte/internal')) {
e.import_svelte_internal_forbidden(node);
}
},
ExportSpecifier(node, { state }) {
validate_export(node, state.scope, node.local.name);
},
Expand Down Expand Up @@ -1077,6 +1082,11 @@ function validate_assignment(node, argument, state) {
}

export const validation_runes = merge(validation, a11y_validators, {
ImportDeclaration(node) {
if (typeof node.source.value === 'string' && node.source.value.startsWith('svelte/internal')) {
e.import_svelte_internal_forbidden(node);
}
},
Identifier(node, { path, state }) {
let i = path.length;
let parent = /** @type {import('estree').Expression} */ (path[--i]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { test } from '../../test';

export default test({
error: {
code: 'import_svelte_internal_forbidden',
message:
"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"
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<svelte:options runes={true} />

<script>
import { something } from 'svelte/internal/client';
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { something } from 'svelte/internal/server';