breaking: prevent usage of arguments keyword in certain places (#12191)

* breaking: prevent usage of arguments keyword in certain places

* build

* build

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

Co-authored-by: Rich Harris <rich.harris@vercel.com>

* build

* build

* lint

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/12195/head
Dominic Gannaway 6 days ago committed by GitHub
parent 09479c4fe9
commit 23484d6875
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
breaking: prevent usage of arguments keyword in certain places

@ -50,6 +50,10 @@
> 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
## invalid_arguments_usage
> The arguments keyword cannot be used within the template or at the top level of a component
## legacy_export_invalid
> Cannot use `export let` in runes mode — use `$props()` instead

@ -213,6 +213,15 @@ 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");
}
/**
* The arguments keyword cannot be used within the template or at the top level of a component
* @param {null | number | NodeLike} node
* @returns {never}
*/
export function invalid_arguments_usage(node) {
e(node, "invalid_arguments_usage", "The arguments keyword cannot be used within the template or at the top level of a component");
}
/**
* Cannot use `export let` in runes mode use `$props()` instead
* @param {null | number | NodeLike} node

@ -1238,6 +1238,14 @@ const common_visitors = {
return;
}
// If we are using arguments outside of a function, then throw an error
if (
node.name === 'arguments' &&
context.path.every((n) => n.type !== 'FunctionDeclaration' && n.type !== 'FunctionExpression')
) {
e.invalid_arguments_usage(node);
}
const binding = context.state.scope.get(node.name);
// if no binding, means some global variable

@ -0,0 +1,9 @@
import { test } from '../../test';
export default test({
error: {
code: 'invalid_arguments_usage',
message:
'The arguments keyword cannot be used within the template or at the top level of a component'
}
});
Loading…
Cancel
Save