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

refactor(js_semantic): ambient computed name can ref a variable imported as a type #3002

Merged
merged 4 commits into from
May 27, 2024

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented May 27, 2024

Summary

Fix #2975

A constant can be imported as a type and used in a computed member name of a member signature.
Here is an example:

import type { NAME } from "./constants.js";
type X = { [NAME]: number };

Previously, Biome was unable to bind the value imported as a type to the computed member name.
We now correctly handle this case.
To do that, I used the same strategy as typeof x:

  • The import NAME is still identified as a type.
  • The reference NAME is emitted as a Reference::AmbientRead (this ref kind was previously named Reference::Typeof).
  • We try to bind the Typeof reference to a value and fallback to an imported type otherwise.

There may be a way to better handle typeof x and more generally values that are imported as types and used in a type context.

Also, I took the opportunity of removing Reference::ExportType. This reference kind was added with the wrong assumption that export type can only reference a type. Actually a such declaration can also reference a value.
I unified Reference::Typeof and Reference::Qualified into a single variant named Reference::AmbientRead.

Test Plan

I added non-regression tests.

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Changelog Area: changelog labels May 27, 2024
Copy link
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 49701 49701 0
Passed 48721 48721 0
Failed 980 980 0
Panics 0 0 0
Coverage 98.03% 98.03% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6322 6322 0
Passed 2036 2036 0
Failed 4286 4286 0
Panics 0 0 0
Coverage 32.20% 32.20% 0.00%

ts/babel

Test result main count This PR count Difference
Total 662 662 0
Passed 593 593 0
Failed 69 69 0
Panics 0 0 0
Coverage 89.58% 89.58% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 17646 17646 0
Passed 13441 13441 0
Failed 4205 4205 0
Panics 0 0 0
Coverage 76.17% 76.17% 0.00%

@Conaclos Conaclos changed the title refcator(js_semantic): ambient computed name can ref a vriable imported as a type refactor(js_semantic): ambient computed name can ref a vriable imported as a type May 27, 2024
@Conaclos Conaclos changed the title refactor(js_semantic): ambient computed name can ref a vriable imported as a type refactor(js_semantic): ambient computed name can ref a variable imported as a type May 27, 2024
@Conaclos Conaclos force-pushed the conaclos/noUndeclaredVariables-2975 branch 2 times, most recently from eb96ab9 to 85ed6c0 Compare May 27, 2024 13:20
@Conaclos Conaclos merged commit 48f36ac into main May 27, 2024
14 checks passed
@Conaclos Conaclos deleted the conaclos/noUndeclaredVariables-2975 branch May 27, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Linter Area: linter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

noUndeclaredVariables not properly handling type import
1 participant