From 97261bf84626bc51b762681e3e3aeb602790f9a9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 29 Jan 2024 12:23:39 -0500 Subject: [PATCH] fix tests --- .../compiler/phases/2-analyze/validation.js | 20 +++++++++---------- .../class-state-field-static/_config.js | 2 +- .../samples/runes-no-rune-each/_config.js | 2 +- .../runes-wrong-derived-placement/_config.js | 4 ++-- .../runes-wrong-state-placement/_config.js | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index 5ac6e651f4..6ba5149fbf 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -950,16 +950,6 @@ export const validation_runes = merge(validation, a11y_validators, { const args = /** @type {import('estree').CallExpression} */ (init).arguments; - if (rune === '$derived') { - const arg = args[0]; - if ( - arg.type === 'CallExpression' && - (arg.callee.type === 'ArrowFunctionExpression' || arg.callee.type === 'FunctionExpression') - ) { - warn(state.analysis.warnings, node, path, 'derived-iife'); - } - } - // TODO some of this is duplicated with above, seems off if ((rune === '$derived' || rune === '$derived.call') && args.length !== 1) { error(node, 'invalid-rune-args-length', rune, [1]); @@ -999,6 +989,16 @@ export const validation_runes = merge(validation, a11y_validators, { } } } + + if (rune === '$derived') { + const arg = args[0]; + if ( + arg.type === 'CallExpression' && + (arg.callee.type === 'ArrowFunctionExpression' || arg.callee.type === 'FunctionExpression') + ) { + warn(state.analysis.warnings, node, path, 'derived-iife'); + } + } }, // TODO this is a code smell. need to refactor this stuff ClassBody: validation_runes_js.ClassBody, diff --git a/packages/svelte/tests/compiler-errors/samples/class-state-field-static/_config.js b/packages/svelte/tests/compiler-errors/samples/class-state-field-static/_config.js index 27991ba427..dca19b4606 100644 --- a/packages/svelte/tests/compiler-errors/samples/class-state-field-static/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/class-state-field-static/_config.js @@ -3,7 +3,7 @@ import { test } from '../../test'; export default test({ error: { code: 'invalid-state-location', - message: '$state() can only be used as a variable declaration initializer or a class field', + message: '$state(...) can only be used as a variable declaration initializer or a class field', position: [33, 41] } }); diff --git a/packages/svelte/tests/compiler-errors/samples/runes-no-rune-each/_config.js b/packages/svelte/tests/compiler-errors/samples/runes-no-rune-each/_config.js index 86c28248a0..9089b6acca 100644 --- a/packages/svelte/tests/compiler-errors/samples/runes-no-rune-each/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/runes-no-rune-each/_config.js @@ -3,6 +3,6 @@ import { test } from '../../test'; export default test({ error: { code: 'invalid-state-location', - message: '$state() can only be used as a variable declaration initializer or a class field' + message: '$state(...) can only be used as a variable declaration initializer or a class field' } }); diff --git a/packages/svelte/tests/compiler-errors/samples/runes-wrong-derived-placement/_config.js b/packages/svelte/tests/compiler-errors/samples/runes-wrong-derived-placement/_config.js index a11c307ece..73c8bf1299 100644 --- a/packages/svelte/tests/compiler-errors/samples/runes-wrong-derived-placement/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/runes-wrong-derived-placement/_config.js @@ -2,7 +2,7 @@ import { test } from '../../test'; export default test({ error: { - code: 'invalid-derived-location', - message: '$derived() can only be used as a variable declaration initializer or a class field' + code: 'invalid-state-location', + message: '$derived(...) can only be used as a variable declaration initializer or a class field' } }); diff --git a/packages/svelte/tests/compiler-errors/samples/runes-wrong-state-placement/_config.js b/packages/svelte/tests/compiler-errors/samples/runes-wrong-state-placement/_config.js index 86c28248a0..9089b6acca 100644 --- a/packages/svelte/tests/compiler-errors/samples/runes-wrong-state-placement/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/runes-wrong-state-placement/_config.js @@ -3,6 +3,6 @@ import { test } from '../../test'; export default test({ error: { code: 'invalid-state-location', - message: '$state() can only be used as a variable declaration initializer or a class field' + message: '$state(...) can only be used as a variable declaration initializer or a class field' } });