Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): overflow in no-obj-calls #4397

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_obj_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ fn resolve_global_binding<'a, 'b: 'a>(
let nodes = ctx.nodes();
let symbols = ctx.symbols();
scope.ancestors(scope_id).find_map(|id| scope.get_binding(id, &ident.name)).map_or_else(
// panic in debug builds, but fail gracefully in release builds
|| {
panic!(
debug_assert!(
false,
"No binding id found for {}, but this IdentifierReference
is not a global",
&ident.name
);
None
},
|binding_id| {
let decl = nodes.get_node(symbols.get_declaration(binding_id));
Expand All @@ -104,7 +107,9 @@ fn resolve_global_binding<'a, 'b: 'a>(
}
match &parent_decl.init {
// handles "let a = JSON; let b = a; a();"
Some(Expression::Identifier(parent_ident)) => {
Some(Expression::Identifier(parent_ident))
if parent_ident.name != ident.name =>
{
resolve_global_binding(parent_ident, decl_scope, ctx)
}
// handles "let a = globalThis.JSON; let b = a; a();"
Expand Down Expand Up @@ -180,6 +185,13 @@ fn test() {
// https://github.com/oxc-project/oxc/pull/508#issuecomment-1618850742
("{const Math = () => {}; {let obj = new Math();}}", None),
("{const {parse} = JSON;parse('{}')}", None),
// https://github.com/oxc-project/oxc/issues/4389
(
r"
export const getConfig = getConfig;
getConfig();",
None,
),
];

let fail = vec![
Expand Down