Skip to content

Commit 6eaca17

Browse files
committed
fix(is-native-element): walk full scope chain for shadow detection
`scope.references` only catches references visible at the immediate scope level. A module-level `const div = MyComponent` binding needs `scope.upper` traversal to shadow the native `<div>` tag correctly.
1 parent 5792e1d commit 6eaca17

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

lib/utils/is-native-element.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,25 @@ function isNativeElement(node, sourceCode) {
6060
}
6161
const scope = sourceCode.getScope(node.parent);
6262
const firstPart = node.parts && node.parts[0];
63-
if (firstPart && scope.references.some((ref) => ref.identifier === firstPart)) {
63+
// Walk the full scope chain so a module-level `const div = MyComponent`
64+
// also shadows the native `<div>` tag, not just block-level bindings.
65+
if (firstPart && hasBindingInScopeChain(scope, firstPart.name)) {
6466
return false;
6567
}
6668
return true;
6769
}
6870

71+
function hasBindingInScopeChain(scope, name) {
72+
let current = scope;
73+
while (current) {
74+
if (current.variables && current.variables.some((v) => v.name === name)) {
75+
return true;
76+
}
77+
current = current.upper;
78+
}
79+
return false;
80+
}
81+
6982
/**
7083
* Inverse of {@link isNativeElement}. Returns true when the node should NOT
7184
* be treated as a native HTML element — either because it's a component

0 commit comments

Comments
 (0)