Skip to content

Commit 4676b96

Browse files
committed
fix(no-navigation-without-base): fixed namespace import detections
1 parent 36869be commit 4676b96

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

packages/eslint-plugin-svelte/src/rules/no-navigation-without-base.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,20 @@ function extractBasePathReferences(
127127
}
128128
}
129129
})) {
130-
const variable = findVariable(context, (node as TSESTree.ImportSpecifier).local);
131-
if (!variable) continue;
132-
for (const reference of variable.references) {
133-
if (reference.identifier.type === 'Identifier') set.add(reference.identifier);
130+
if (node.type === 'ImportSpecifier') {
131+
const variable = findVariable(context, node.local);
132+
if (variable === null) {
133+
continue;
134+
}
135+
for (const reference of variable.references) {
136+
if (reference.identifier.type === 'Identifier') set.add(reference.identifier);
137+
}
138+
} else if (
139+
node.type === 'MemberExpression' &&
140+
node.property.type === 'Identifier' &&
141+
node.property.name === 'base'
142+
) {
143+
set.add(node.property);
134144
}
135145
}
136146
return set;
@@ -218,6 +228,8 @@ function expressionStartsWithBase(
218228
return binaryExpressionStartsWithBase(context, url, basePathNames);
219229
case 'Identifier':
220230
return variableStartsWithBase(context, url, basePathNames);
231+
case 'MemberExpression':
232+
return memberExpressionStartsWithBase(url, basePathNames);
221233
case 'TemplateLiteral':
222234
return templateLiteralStartsWithBase(context, url, basePathNames);
223235
default:
@@ -236,6 +248,13 @@ function binaryExpressionStartsWithBase(
236248
);
237249
}
238250

251+
function memberExpressionStartsWithBase(
252+
url: TSESTree.MemberExpression,
253+
basePathNames: Set<TSESTree.Identifier>
254+
): boolean {
255+
return url.property.type === 'Identifier' && basePathNames.has(url.property);
256+
}
257+
239258
function variableStartsWithBase(
240259
context: RuleContext,
241260
url: TSESTree.Identifier,

0 commit comments

Comments
 (0)