+
Skip to content

Conversation

sterliakov
Copy link
Contributor

Summary

Fixed #6939. This bug was introduced in #6901 hastily merged without review.

In the implementation proposed below, biome uses a simple inference algorithm. We iterate over all ancestors of this expr and apply the following checks:

  1. If a node is a function (only sync/async function declaration/expression, not methods) and is not used as a class/object member, we assign unknown.
  2. If a node is a class decl/expr, we bind this to it.
  3. If a node is an object and we have already encountered a function or an object method/getter/setter, we bind this to object.

If no node matched any of those steps, we also assign unknown.

Test Plan

Added several snapshot tests relying on basic inference to prove that type of this is deduced correctly.

Docs

Bugfix, N/A

Copy link

changeset-bot bot commented Jul 19, 2025

🦋 Changeset detected

Latest commit: ba548cc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sterliakov sterliakov changed the title Bugfix/st this binding fix(core): fix type onference of this Jul 19, 2025
@sterliakov sterliakov changed the title fix(core): fix type onference of this fix(core): fix type inference of this Jul 19, 2025
@github-actions github-actions bot added A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Type-Inference Area: type inference labels Jul 19, 2025
Copy link
Contributor

@arendjr arendjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thank you!

@arendjr arendjr merged commit cfda528 into biomejs:main Jul 20, 2025
12 checks passed
@github-actions github-actions bot mentioned this pull request Jul 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter A-Project Area: project A-Type-Inference Area: type inference L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 useExhaustiveSwitchCases does not work on arrow functions that are members of a class

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载