@@ -715,10 +715,10 @@ function validate_call_expression(node, scope, path) {
715
715
error ( node , 'invalid-props-location' ) ;
716
716
}
717
717
718
- if ( rune === '$state' || rune === '$derived' ) {
718
+ if ( rune === '$state' || rune === '$derived' || rune === '$derived.call' ) {
719
719
if ( parent . type === 'VariableDeclarator' ) return ;
720
720
if ( parent . type === 'PropertyDefinition' && ! parent . static && ! parent . computed ) return ;
721
- error ( node , rune === '$derived' ? ' invalid-derived-location' : 'invalid- state-location') ;
721
+ error ( node , ' invalid-state-location', rune ) ;
722
722
}
723
723
724
724
if ( rune === '$effect' || rune === '$effect.pre' ) {
@@ -786,10 +786,10 @@ export const validation_runes_js = {
786
786
787
787
const args = /** @type {import('estree').CallExpression } */ ( init ) . arguments ;
788
788
789
- if ( rune === '$derived' && args . length !== 1 ) {
790
- error ( node , 'invalid-rune-args-length' , '$derived' , [ 1 ] ) ;
789
+ if ( ( rune === '$derived' || rune === '$derived.call' ) && args . length !== 1 ) {
790
+ error ( node , 'invalid-rune-args-length' , rune , [ 1 ] ) ;
791
791
} else if ( rune === '$state' && args . length > 1 ) {
792
- error ( node , 'invalid-rune-args-length' , '$state' , [ 0 , 1 ] ) ;
792
+ error ( node , 'invalid-rune-args-length' , rune , [ 0 , 1 ] ) ;
793
793
} else if ( rune === '$props' ) {
794
794
error ( node , 'invalid-props-location' ) ;
795
795
}
@@ -811,7 +811,7 @@ export const validation_runes_js = {
811
811
definition . value ?. type === 'CallExpression'
812
812
) {
813
813
const rune = get_rune ( definition . value , context . state . scope ) ;
814
- if ( rune === '$derived' ) {
814
+ if ( rune === '$derived' || rune === '$derived.call' ) {
815
815
private_derived_state . push ( definition . key . name ) ;
816
816
}
817
817
}
@@ -938,25 +938,23 @@ export const validation_runes = merge(validation, a11y_validators, {
938
938
context . type === 'Identifier' &&
939
939
( context . name === '$state' || context . name === '$derived' )
940
940
) {
941
- error (
942
- node ,
943
- context . name === '$derived' ? 'invalid-derived-location' : 'invalid-state-location'
944
- ) ;
941
+ error ( node , 'invalid-state-location' , context . name ) ;
945
942
}
946
943
next ( { ...state } ) ;
947
944
} ,
948
- VariableDeclarator ( node , { state } ) {
945
+ VariableDeclarator ( node , { state, path } ) {
949
946
const init = unwrap_ts_expression ( node . init ) ;
950
947
const rune = get_rune ( init , state . scope ) ;
951
948
952
949
if ( rune === null ) return ;
953
950
954
951
const args = /** @type {import('estree').CallExpression } */ ( init ) . arguments ;
955
952
956
- if ( rune === '$derived' && args . length !== 1 ) {
957
- error ( node , 'invalid-rune-args-length' , '$derived' , [ 1 ] ) ;
953
+ // TODO some of this is duplicated with above, seems off
954
+ if ( ( rune === '$derived' || rune === '$derived.call' ) && args . length !== 1 ) {
955
+ error ( node , 'invalid-rune-args-length' , rune , [ 1 ] ) ;
958
956
} else if ( rune === '$state' && args . length > 1 ) {
959
- error ( node , 'invalid-rune-args-length' , '$state' , [ 0 , 1 ] ) ;
957
+ error ( node , 'invalid-rune-args-length' , rune , [ 0 , 1 ] ) ;
960
958
} else if ( rune === '$props' ) {
961
959
if ( state . has_props_rune ) {
962
960
error ( node , 'duplicate-props-rune' ) ;
@@ -991,6 +989,16 @@ export const validation_runes = merge(validation, a11y_validators, {
991
989
}
992
990
}
993
991
}
992
+
993
+ if ( rune === '$derived' ) {
994
+ const arg = args [ 0 ] ;
995
+ if (
996
+ arg . type === 'CallExpression' &&
997
+ ( arg . callee . type === 'ArrowFunctionExpression' || arg . callee . type === 'FunctionExpression' )
998
+ ) {
999
+ warn ( state . analysis . warnings , node , path , 'derived-iife' ) ;
1000
+ }
1001
+ }
994
1002
} ,
995
1003
// TODO this is a code smell. need to refactor this stuff
996
1004
ClassBody : validation_runes_js . ClassBody ,
0 commit comments