@@ -5,6 +5,7 @@ import { FindVariableContext } from '../utils/ast-utils.js';
5
5
import { findVariable } from '../utils/ast-utils.js' ;
6
6
import type { RuleContext } from '../types.js' ;
7
7
import type { AST } from 'svelte-eslint-parser' ;
8
+ import { type TSTools , getTypeScriptTools } from 'src/utils/ts-utils/index.js' ;
8
9
9
10
export default createRule ( 'no-navigation-without-resolve' , {
10
11
meta : {
@@ -48,6 +49,8 @@ export default createRule('no-navigation-without-resolve', {
48
49
]
49
50
} ,
50
51
create ( context ) {
52
+ const tsTools = getTypeScriptTools ( context ) ;
53
+
51
54
let resolveReferences : Set < TSESTree . Identifier > = new Set < TSESTree . Identifier > ( ) ;
52
55
return {
53
56
Program ( ) {
@@ -60,7 +63,7 @@ export default createRule('no-navigation-without-resolve', {
60
63
} = extractFunctionCallReferences ( referenceTracker ) ;
61
64
if ( context . options [ 0 ] ?. ignoreGoto !== true ) {
62
65
for ( const gotoCall of gotoCalls ) {
63
- checkGotoCall ( context , gotoCall , resolveReferences ) ;
66
+ checkGotoCall ( context , gotoCall , resolveReferences , tsTools ) ;
64
67
}
65
68
}
66
69
if ( context . options [ 0 ] ?. ignorePushState !== true ) {
@@ -69,6 +72,7 @@ export default createRule('no-navigation-without-resolve', {
69
72
context ,
70
73
pushStateCall ,
71
74
resolveReferences ,
75
+ tsTools ,
72
76
'pushStateWithoutResolve'
73
77
) ;
74
78
}
@@ -79,6 +83,7 @@ export default createRule('no-navigation-without-resolve', {
79
83
context ,
80
84
replaceStateCall ,
81
85
resolveReferences ,
86
+ tsTools ,
82
87
'replaceStateWithoutResolve'
83
88
) ;
84
89
}
@@ -105,7 +110,8 @@ export default createRule('no-navigation-without-resolve', {
105
110
! isResolveCall (
106
111
new FindVariableContext ( context ) ,
107
112
node . value [ 0 ] . expression ,
108
- resolveReferences
113
+ resolveReferences ,
114
+ tsTools
109
115
) )
110
116
) {
111
117
context . report ( { loc : node . value [ 0 ] . loc , messageId : 'linkWithoutResolve' } ) ;
@@ -193,13 +199,14 @@ function extractFunctionCallReferences(referenceTracker: ReferenceTracker): {
193
199
function checkGotoCall (
194
200
context : RuleContext ,
195
201
call : TSESTree . CallExpression ,
196
- resolveReferences : Set < TSESTree . Identifier >
202
+ resolveReferences : Set < TSESTree . Identifier > ,
203
+ tsTools : TSTools | null
197
204
) : void {
198
205
if ( call . arguments . length < 1 ) {
199
206
return ;
200
207
}
201
208
const url = call . arguments [ 0 ] ;
202
- if ( ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences ) ) {
209
+ if ( ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences , tsTools ) ) {
203
210
context . report ( { loc : url . loc , messageId : 'gotoWithoutResolve' } ) ;
204
211
}
205
212
}
@@ -208,6 +215,7 @@ function checkShallowNavigationCall(
208
215
context : RuleContext ,
209
216
call : TSESTree . CallExpression ,
210
217
resolveReferences : Set < TSESTree . Identifier > ,
218
+ tsTools : TSTools | null ,
211
219
messageId : string
212
220
) : void {
213
221
if ( call . arguments . length < 1 ) {
@@ -216,7 +224,7 @@ function checkShallowNavigationCall(
216
224
const url = call . arguments [ 0 ] ;
217
225
if (
218
226
! expressionIsEmpty ( url ) &&
219
- ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences )
227
+ ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences , tsTools )
220
228
) {
221
229
context . report ( { loc : url . loc , messageId } ) ;
222
230
}
@@ -227,7 +235,8 @@ function checkShallowNavigationCall(
227
235
function isResolveCall (
228
236
ctx : FindVariableContext ,
229
237
node : TSESTree . CallExpressionArgument ,
230
- resolveReferences : Set < TSESTree . Identifier >
238
+ resolveReferences : Set < TSESTree . Identifier > ,
239
+ tsTools : TSTools | null
231
240
) : boolean {
232
241
if (
233
242
node . type === 'CallExpression' &&
@@ -238,9 +247,13 @@ function isResolveCall(
238
247
) {
239
248
return true ;
240
249
}
241
- if ( node . type !== 'Identifier' ) {
250
+ if ( node . type !== 'Identifier' || tsTools === null ) {
242
251
return false ;
243
252
}
253
+ const tsNode = tsTools . service . esTreeNodeToTSNodeMap . get ( node ) ;
254
+ console . log ( tsNode ) ;
255
+ console . log ( tsTools . service . program . getTypeChecker ( ) . getTypeAtLocation ( tsNode ) ) ;
256
+ /*
244
257
const variable = ctx.findVariable(node);
245
258
if (
246
259
variable === null ||
@@ -251,6 +264,7 @@ function isResolveCall(
251
264
return false;
252
265
}
253
266
return isResolveCall(ctx, variable.identifiers[0].parent.init, resolveReferences);
267
+ */
254
268
}
255
269
256
270
function expressionIsEmpty ( url : TSESTree . CallExpressionArgument ) : boolean {
0 commit comments