@@ -715,10 +715,10 @@ function validate_call_expression(node, scope, path) {
715715 error ( node , 'invalid-props-location' ) ;
716716 }
717717
718- if ( rune === '$state' || rune === '$derived' ) {
718+ if ( rune === '$state' || rune === '$derived' || rune === '$derived.call' ) {
719719 if ( parent . type === 'VariableDeclarator' ) return ;
720720 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 ) ;
722722 }
723723
724724 if ( rune === '$effect' || rune === '$effect.pre' ) {
@@ -786,10 +786,10 @@ export const validation_runes_js = {
786786
787787 const args = /** @type {import('estree').CallExpression } */ ( init ) . arguments ;
788788
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 ] ) ;
791791 } 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 ] ) ;
793793 } else if ( rune === '$props' ) {
794794 error ( node , 'invalid-props-location' ) ;
795795 }
@@ -811,7 +811,7 @@ export const validation_runes_js = {
811811 definition . value ?. type === 'CallExpression'
812812 ) {
813813 const rune = get_rune ( definition . value , context . state . scope ) ;
814- if ( rune === '$derived' ) {
814+ if ( rune === '$derived' || rune === '$derived.call' ) {
815815 private_derived_state . push ( definition . key . name ) ;
816816 }
817817 }
@@ -938,25 +938,23 @@ export const validation_runes = merge(validation, a11y_validators, {
938938 context . type === 'Identifier' &&
939939 ( context . name === '$state' || context . name === '$derived' )
940940 ) {
941- error (
942- node ,
943- context . name === '$derived' ? 'invalid-derived-location' : 'invalid-state-location'
944- ) ;
941+ error ( node , 'invalid-state-location' , context . name ) ;
945942 }
946943 next ( { ...state } ) ;
947944 } ,
948- VariableDeclarator ( node , { state } ) {
945+ VariableDeclarator ( node , { state, path } ) {
949946 const init = unwrap_ts_expression ( node . init ) ;
950947 const rune = get_rune ( init , state . scope ) ;
951948
952949 if ( rune === null ) return ;
953950
954951 const args = /** @type {import('estree').CallExpression } */ ( init ) . arguments ;
955952
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 ] ) ;
958956 } 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 ] ) ;
960958 } else if ( rune === '$props' ) {
961959 if ( state . has_props_rune ) {
962960 error ( node , 'duplicate-props-rune' ) ;
@@ -991,6 +989,16 @@ export const validation_runes = merge(validation, a11y_validators, {
991989 }
992990 }
993991 }
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+ }
9941002 } ,
9951003 // TODO this is a code smell. need to refactor this stuff
9961004 ClassBody : validation_runes_js . ClassBody ,
0 commit comments