Skip to content

fix: variable reference in function passed as argument#20248

Open
Tanujkanti4441 wants to merge 6 commits intoeslint:mainfrom
Tanujkanti4441:fix-ref
Open

fix: variable reference in function passed as argument#20248
Tanujkanti4441 wants to merge 6 commits intoeslint:mainfrom
Tanujkanti4441:fix-ref

Conversation

@Tanujkanti4441
Copy link
Contributor

@Tanujkanti4441 Tanujkanti4441 commented Oct 25, 2025

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Added a new option called ignoreSelfReferentialInitializers (boolean) (false by default) to avoid reporting the variable references in its initializer that can cause a TDZ error while execution.

following code will be reported with option ignoreSelfReferentialInitializers: false

const a = TestFunction(
    arr,
    (T) => {
        console.log(`blah: ${a}`); // right now `a` is not reported
        return T;
    }
);

const b = (() => b)();

const c = await (async () => c)();

const d = array.map(x => d.length);

const E = class { foo() { return E; } }.prototype.foo();

it does not report these cases with ignoreSelfReferentialInitializers: false

const a = () => a;

const b = await (async () => "foo")();

const D = class { foo() { return D; } bar() {} }.prototype.bar();

Is there anything you'd like reviewers to focus on?

Fixes #20014

@Tanujkanti4441 Tanujkanti4441 requested a review from a team as a code owner October 25, 2025 17:46
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Oct 25, 2025
@netlify
Copy link

netlify bot commented Oct 25, 2025

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit 7c7661a
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/69b5065e33af070008ba7299
😎 Deploy Preview https://deploy-preview-20248--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@lumirlumir lumirlumir added the accepted There is consensus among the team that this change meets the criteria for inclusion label Oct 27, 2025
@nzakas nzakas moved this from Needs Triage to Evaluating in Triage Oct 31, 2025
@nzakas
Copy link
Member

nzakas commented Oct 31, 2025

Thanks for looking at this. Looking back at the issue, I'm not sure there was consensus how to move forward with this.

@mdjermanovic
Copy link
Member

Converting to draft, per the previous comment.

@Tanujkanti4441 Tanujkanti4441 marked this pull request as ready for review March 13, 2026 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Projects

Status: Evaluating

Development

Successfully merging this pull request may close these issues.

Bug: no-use-before-define - Can use undefined variables in a function that is passed as a parameter and then executed

4 participants