Skip to content

Commit 6563b0f

Browse files
committed
disallow beforeUpdate/afterUpdate imports in runes mode
1 parent 081dc55 commit 6563b0f

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

packages/svelte/src/compiler/errors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ const runes = {
200200
`${rune} can only be called with ${list(args, 'or')} ${
201201
args.length === 1 && args[0] === 1 ? 'argument' : 'arguments'
202202
}`,
203+
/** @param {string} name */
204+
'invalid-runes-mode-import': (name) => `${name} cannot be used in runes mode`,
203205
'duplicate-props-rune': () => `Cannot use $props() more than once`
204206
};
205207

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,20 @@ const validation = {
492492
error(node, 'invalid-const-placement');
493493
}
494494
},
495+
ImportDeclaration(node, context) {
496+
if (context.state.analysis.runes) {
497+
for (const specifier of node.specifiers) {
498+
if (specifier.type === 'ImportSpecifier') {
499+
if (
500+
specifier.imported.name === 'beforeUpdate' ||
501+
specifier.imported.name === 'afterUpdate'
502+
) {
503+
error(specifier, 'invalid-runes-mode-import', specifier.imported.name);
504+
}
505+
}
506+
}
507+
}
508+
},
495509
LetDirective(node, context) {
496510
const parent = context.path.at(-1);
497511
if (
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
error: {
5+
code: 'invalid-runes-mode-import',
6+
message: 'beforeUpdate cannot be used in runes mode'
7+
}
8+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<svelte:options runes />
2+
3+
<script>
4+
import { beforeUpdate, afterUpdate } from 'svelte';
5+
</script>

0 commit comments

Comments
 (0)