@@ -5,6 +5,7 @@ import { FindVariableContext } from '../utils/ast-utils.js';
55import { findVariable } from '../utils/ast-utils.js' ;
66import type { RuleContext } from '../types.js' ;
77import type { AST } from 'svelte-eslint-parser' ;
8+ import { type TSTools , getTypeScriptTools } from 'src/utils/ts-utils/index.js' ;
89
910export default createRule ( 'no-navigation-without-resolve' , {
1011 meta : {
@@ -48,6 +49,8 @@ export default createRule('no-navigation-without-resolve', {
4849 ]
4950 } ,
5051 create ( context ) {
52+ const tsTools = getTypeScriptTools ( context ) ;
53+
5154 let resolveReferences : Set < TSESTree . Identifier > = new Set < TSESTree . Identifier > ( ) ;
5255
5356 const ignoreGoto = context . options [ 0 ] ?. ignoreGoto ?? false ;
@@ -66,7 +69,7 @@ export default createRule('no-navigation-without-resolve', {
6669 } = extractFunctionCallReferences ( referenceTracker ) ;
6770 if ( ! ignoreGoto ) {
6871 for ( const gotoCall of gotoCalls ) {
69- checkGotoCall ( context , gotoCall , resolveReferences ) ;
72+ checkGotoCall ( context , gotoCall , resolveReferences , tsTools ) ;
7073 }
7174 }
7275 if ( ! ignorePushState ) {
@@ -75,6 +78,7 @@ export default createRule('no-navigation-without-resolve', {
7578 context ,
7679 pushStateCall ,
7780 resolveReferences ,
81+ tsTools ,
7882 'pushStateWithoutResolve'
7983 ) ;
8084 }
@@ -85,6 +89,7 @@ export default createRule('no-navigation-without-resolve', {
8589 context ,
8690 replaceStateCall ,
8791 resolveReferences ,
92+ tsTools ,
8893 'replaceStateWithoutResolve'
8994 ) ;
9095 }
@@ -131,7 +136,8 @@ export default createRule('no-navigation-without-resolve', {
131136 ! isResolveCall (
132137 new FindVariableContext ( context ) ,
133138 node . value [ 0 ] . expression ,
134- resolveReferences
139+ resolveReferences ,
140+ tsTools
135141 ) )
136142 ) {
137143 context . report ( { loc : node . value [ 0 ] . loc , messageId : 'linkWithoutResolve' } ) ;
@@ -219,13 +225,14 @@ function extractFunctionCallReferences(referenceTracker: ReferenceTracker): {
219225function checkGotoCall (
220226 context : RuleContext ,
221227 call : TSESTree . CallExpression ,
222- resolveReferences : Set < TSESTree . Identifier >
228+ resolveReferences : Set < TSESTree . Identifier > ,
229+ tsTools : TSTools | null
223230) : void {
224231 if ( call . arguments . length < 1 ) {
225232 return ;
226233 }
227234 const url = call . arguments [ 0 ] ;
228- if ( ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences ) ) {
235+ if ( ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences , tsTools ) ) {
229236 context . report ( { loc : url . loc , messageId : 'gotoWithoutResolve' } ) ;
230237 }
231238}
@@ -234,6 +241,7 @@ function checkShallowNavigationCall(
234241 context : RuleContext ,
235242 call : TSESTree . CallExpression ,
236243 resolveReferences : Set < TSESTree . Identifier > ,
244+ tsTools : TSTools | null ,
237245 messageId : string
238246) : void {
239247 if ( call . arguments . length < 1 ) {
@@ -242,7 +250,7 @@ function checkShallowNavigationCall(
242250 const url = call . arguments [ 0 ] ;
243251 if (
244252 ! expressionIsEmpty ( url ) &&
245- ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences )
253+ ! isResolveCall ( new FindVariableContext ( context ) , url , resolveReferences , tsTools )
246254 ) {
247255 context . report ( { loc : url . loc , messageId } ) ;
248256 }
@@ -253,7 +261,8 @@ function checkShallowNavigationCall(
253261function isResolveCall (
254262 ctx : FindVariableContext ,
255263 node : TSESTree . CallExpressionArgument ,
256- resolveReferences : Set < TSESTree . Identifier >
264+ resolveReferences : Set < TSESTree . Identifier > ,
265+ tsTools : TSTools | null
257266) : boolean {
258267 if (
259268 node . type === 'CallExpression' &&
@@ -264,9 +273,13 @@ function isResolveCall(
264273 ) {
265274 return true ;
266275 }
267- if ( node . type !== 'Identifier' ) {
276+ if ( node . type !== 'Identifier' || tsTools === null ) {
268277 return false ;
269278 }
279+ const tsNode = tsTools . service . esTreeNodeToTSNodeMap . get ( node ) ;
280+ console . log ( tsNode ) ;
281+ console . log ( tsTools . service . program . getTypeChecker ( ) . getTypeAtLocation ( tsNode ) ) ;
282+ /*
270283 const variable = ctx.findVariable(node);
271284 if (
272285 variable === null ||
@@ -277,6 +290,7 @@ function isResolveCall(
277290 return false;
278291 }
279292 return isResolveCall(ctx, variable.identifiers[0].parent.init, resolveReferences);
293+ */
280294}
281295
282296function expressionIsEmpty ( url : TSESTree . CallExpressionArgument ) : boolean {
0 commit comments