1
+ /** @import { Expression, Node, Pattern, Statement } from 'estree' */
2
+ /** @import { Visitors } from '../types' */
1
3
import is_reference from 'is-reference' ;
2
4
import { serialize_get_binding , serialize_set_binding } from '../utils.js' ;
3
5
import * as b from '../../../../utils/builders.js' ;
4
6
5
- /** @type {import('../types'). Visitors } */
7
+ /** @type {Visitors } */
6
8
export const global_visitors = {
7
9
Identifier ( node , { path, state } ) {
8
- if ( is_reference ( node , /** @type {import('estree'). Node } */ ( path . at ( - 1 ) ) ) ) {
10
+ if ( is_reference ( node , /** @type {Node } */ ( path . at ( - 1 ) ) ) ) {
9
11
if ( node . name === '$$props' ) {
10
12
return b . id ( '$$sanitized_props' ) ;
11
13
}
@@ -74,7 +76,7 @@ export const global_visitors = {
74
76
binding ?. kind === 'bindable_prop' ||
75
77
is_store
76
78
) {
77
- /** @type {import('estree'). Expression[] } */
79
+ /** @type {Expression[] } */
78
80
const args = [ ] ;
79
81
80
82
let fn = '$.update' ;
@@ -105,7 +107,7 @@ export const global_visitors = {
105
107
let fn = '$.update' ;
106
108
if ( node . prefix ) fn += '_pre' ;
107
109
108
- /** @type {import('estree'). Expression[] } */
110
+ /** @type {Expression[] } */
109
111
const args = [ argument ] ;
110
112
if ( node . operator === '--' ) {
111
113
args . push ( b . literal ( - 1 ) ) ;
@@ -116,7 +118,7 @@ export const global_visitors = {
116
118
// turn it into an IIFEE assignment expression: i++ -> (() => { const $$value = i; i+=1; return $$value; })
117
119
const assignment = b . assignment (
118
120
node . operator === '++' ? '+=' : '-=' ,
119
- /** @type {import('estree'). Pattern } */ ( argument ) ,
121
+ /** @type {Pattern } */ ( argument ) ,
120
122
b . literal ( 1 )
121
123
) ;
122
124
const serialized_assignment = serialize_set_binding (
@@ -125,14 +127,14 @@ export const global_visitors = {
125
127
( ) => assignment ,
126
128
node . prefix
127
129
) ;
128
- const value = /** @type {import('estree'). Expression } */ ( visit ( argument ) ) ;
130
+ const value = /** @type {Expression } */ ( visit ( argument ) ) ;
129
131
if ( serialized_assignment === assignment ) {
130
132
// No change to output -> nothing to transform -> we can keep the original update expression
131
133
return next ( ) ;
132
134
} else if ( context . state . analysis . runes ) {
133
135
return serialized_assignment ;
134
136
} else {
135
- /** @type {import('estree'). Statement[] } */
137
+ /** @type {Statement[] } */
136
138
let statements ;
137
139
if ( node . prefix ) {
138
140
statements = [ b . stmt ( serialized_assignment ) , b . return ( value ) ] ;
0 commit comments