@@ -35,12 +35,10 @@ function sort_const_tags(nodes, state) {
35
35
/**
36
36
* @typedef {{
37
37
* node: import('#compiler').ConstTag;
38
- * ids: import('#compiler').Binding[];
39
38
* deps: Set<import('#compiler').Binding>;
40
39
* }} Tag
41
40
*/
42
41
43
- const const_tags = [ ] ;
44
42
const other = [ ] ;
45
43
46
44
/** @type {Map<import('#compiler').Binding, Tag> } */
@@ -52,19 +50,12 @@ function sort_const_tags(nodes, state) {
52
50
if ( node . type === 'ConstTag' ) {
53
51
const declaration = node . declaration . declarations [ 0 ] ;
54
52
55
- /** @type {Tag } */
56
- const tag = {
57
- node,
58
- ids : extract_identifiers ( declaration . id ) . map ( ( id ) => {
59
- return /** @type {import('#compiler').Binding } */ ( state . scope . get ( id . name ) ) ;
60
- } ) ,
61
- /** @type {Set<import('#compiler').Binding> } */
62
- deps : new Set ( )
63
- } ;
64
-
65
- for ( const id of tag . ids ) {
66
- tags . set ( id , tag ) ;
67
- }
53
+ const bindings = extract_identifiers ( declaration . id ) . map ( ( id ) => {
54
+ return /** @type {import('#compiler').Binding } */ ( state . scope . get ( id . name ) ) ;
55
+ } ) ;
56
+
57
+ /** @type {Set<import('#compiler').Binding> } */
58
+ const deps = new Set ( ) ;
68
59
69
60
walk ( declaration . init , state , {
70
61
_,
@@ -73,30 +64,30 @@ function sort_const_tags(nodes, state) {
73
64
74
65
if ( is_reference ( node , parent ) ) {
75
66
const binding = context . state . scope . get ( node . name ) ;
76
- if ( binding ) tag . deps . add ( binding ) ;
67
+ if ( binding ) deps . add ( binding ) ;
77
68
}
78
69
}
79
70
} ) ;
80
71
81
- const_tags . push ( tag ) ;
72
+ for ( const binding of bindings ) {
73
+ tags . set ( binding , { node, deps } ) ;
74
+ }
82
75
} else {
83
76
other . push ( node ) ;
84
77
}
85
78
}
86
79
87
- if ( const_tags . length === 0 ) {
80
+ if ( tags . size === 0 ) {
88
81
return nodes ;
89
82
}
90
83
91
84
/** @type {Array<[import('#compiler').Binding, import('#compiler').Binding]> } */
92
85
const edges = [ ] ;
93
86
94
- for ( const tag of const_tags ) {
95
- for ( const id of tag . ids ) {
96
- for ( const dep of tag . deps ) {
97
- if ( tags . has ( dep ) ) {
98
- edges . push ( [ id , dep ] ) ;
99
- }
87
+ for ( const [ id , tag ] of tags ) {
88
+ for ( const dep of tag . deps ) {
89
+ if ( tags . has ( dep ) ) {
90
+ edges . push ( [ id , dep ] ) ;
100
91
}
101
92
}
102
93
}
@@ -124,7 +115,7 @@ function sort_const_tags(nodes, state) {
124
115
sorted . push ( tag . node ) ;
125
116
}
126
117
127
- for ( const tag of const_tags ) {
118
+ for ( const tag of tags . values ( ) ) {
128
119
add ( tag ) ;
129
120
}
130
121
0 commit comments