File tree Expand file tree Collapse file tree 5 files changed +21
-8
lines changed
reactive-module-variable-2 Expand file tree Collapse file tree 5 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -1192,6 +1192,7 @@ export default class Component {
1192
1192
const assignees = new Set < string > ( ) ;
1193
1193
const assignee_nodes = new Set ( ) ;
1194
1194
const dependencies = new Set < string > ( ) ;
1195
+ const module_dependencies = new Set < string > ( ) ;
1195
1196
1196
1197
let scope = this . instance_scope ;
1197
1198
const map = this . instance_scope_map ;
@@ -1228,7 +1229,7 @@ export default class Component {
1228
1229
variable . is_reactive_dependency = true ;
1229
1230
if ( variable . module ) {
1230
1231
should_add_as_dependency = false ;
1231
- component . warn ( node as any , compiler_warnings . module_script_variable_reactive_declaration ( name ) ) ;
1232
+ module_dependencies . add ( name ) ;
1232
1233
}
1233
1234
}
1234
1235
const is_writable_or_mutated =
@@ -1253,6 +1254,10 @@ export default class Component {
1253
1254
}
1254
1255
} ) ;
1255
1256
1257
+ if ( module_dependencies . size > 0 && dependencies . size === 0 ) {
1258
+ component . warn ( node . body as any , compiler_warnings . module_script_variable_reactive_declaration ( Array . from ( module_dependencies ) ) ) ;
1259
+ }
1260
+
1256
1261
const { expression } = node . body as ExpressionStatement ;
1257
1262
const declaration = expression && ( expression as AssignmentExpression ) . left ;
1258
1263
Original file line number Diff line number Diff line change @@ -20,9 +20,9 @@ export default {
20
20
code : 'non-top-level-reactive-declaration' ,
21
21
message : '$: has no effect outside of the top-level'
22
22
} ,
23
- module_script_variable_reactive_declaration : ( name : string ) => ( {
23
+ module_script_variable_reactive_declaration : ( names : string [ ] ) => ( {
24
24
code : 'module-script-reactive-declaration' ,
25
- message : `"${ name } " is declared in a module script and will not be reactive`
25
+ message : `${ names . map ( name => ` "${ name } "` ) . join ( ', ' ) } ${ names . length > 1 ? 'are' : 'is' } declared in a module script and will not be reactive`
26
26
} ) ,
27
27
missing_declaration : ( name : string , has_script : boolean ) => ( {
28
28
code : 'missing-declaration' ,
Original file line number Diff line number Diff line change
1
+ <script context =" module" >
2
+ let PI = 3.14 ;
3
+ </script >
4
+ <script >
5
+ let r;
6
+ $: area = PI * r * r;
7
+ </script >
Original file line number Diff line number Diff line change
1
+ []
Original file line number Diff line number Diff line change 2
2
{
3
3
"code" : " module-script-reactive-declaration" ,
4
4
"message" : " \" foo\" is declared in a module script and will not be reactive" ,
5
- "pos" : 65 ,
5
+ "pos" : 59 ,
6
6
"start" : {
7
- "character" : 65 ,
8
- "column" : 10 ,
7
+ "character" : 59 ,
8
+ "column" : 4 ,
9
9
"line" : 5
10
10
},
11
11
"end" : {
12
- "character" : 68 ,
13
- "column" : 13 ,
12
+ "character" : 69 ,
13
+ "column" : 14 ,
14
14
"line" : 5
15
15
}
16
16
}
You can’t perform that action at this time.
0 commit comments