feat: error on imports to `svelte/internal/*` (#11632)

* feat: error on imports to `svelte/internal/*`

closes #11622

* regenerate

* also error on svelte/internal
pull/11617/head
Simon H 2 months ago committed by GitHub
parent 13ce43a0a8
commit 4bedd0e4fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
feat: error on imports to `svelte/internal/*`

@ -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

@ -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

@ -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);
},
@ -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]);

@ -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"
}
});

@ -0,0 +1,5 @@
<svelte:options runes={true} />
<script>
import { something } from 'svelte/internal/client';
</script>
Loading…
Cancel
Save