fix(eslint/no-obj-calls): should resolve non-global binding correctly (#745)

Fixes #744
This commit is contained in:
Yunfei He 2023-08-15 18:37:40 +08:00 committed by GitHub
parent 5dc69ea4ec
commit ec85fd8b7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -88,11 +88,13 @@ fn resolve_global_binding<'a, 'b: 'a>(
let scope = ctx.scopes();
let nodes = ctx.nodes();
let symbols = ctx.symbols();
scope.get_binding(scope_id, &ident.name).map_or_else(
scope.ancestors(scope_id).find_map(|id| scope.get_binding(id, &ident.name)).map_or_else(
|| {
// panic!("No binding id found for {}, but this IdentifierReference
// is not a global", &ident.name);
None
panic!(
"No binding id found for {}, but this IdentifierReference
is not a global",
&ident.name
);
},
|binding_id| {
let decl = nodes.get_node(symbols.get_declaration(binding_id));
@ -174,6 +176,8 @@ fn test() {
}",
None,
),
// https://github.com/web-infra-dev/oxc/pull/508#issuecomment-1618850742
("{const Math = () => {}; {let obj = new Math();}}", None),
];
let fail = vec![