pull/10240/head
Rich Harris 3 years ago
parent a3f74b7104
commit 97261bf846

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

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

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

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

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

Loading…
Cancel
Save