fix: avoid false positives on import/export aliases#3
Merged
albertodeago merged 1 commit intoMay 12, 2026
Merged
Conversation
…iases
The previous pattern `$expr as $type` over-matches because the `as`
token appears in many AST constructs, not just `TsAsExpression`:
- `import { foo as bar } from ...` (JsNamedImportSpecifier)
- `import * as ns from ...` (JsNamespaceImportSpecifier)
- `export { foo as bar }` (JsExportNamedFromSpecifier)
The exclusion `! $expr <: within \`import $_ from $_\`` only
covered single-specifier default imports, leaving multi-specifier named
imports and namespace imports as false positives.
biome 2.4.9 fixed a metavariable matching bug
(biomejs/biome#9586) that previously masked the issue, so the false
positives now surface for any user of biome >= 2.4.9.
Constrain the matched node to `TsAsExpression()` so only genuine TS
type assertions are flagged.
Closes albertodeago#2
Contributor
Author
|
Hi @albertodeago — gentle ping on this one when you get a chance 🙏 This fixes a real regression that surfaces for any user on biome >= 2.4.9 (since biomejs/biome#9586 fixed the metavariable matching that was previously masking the issue). Happy to address any feedback if there's anything you'd like changed. Thanks for maintaining this plugin! |
Owner
|
hey @maroKanatani |
albertodeago
approved these changes
May 12, 2026
albertodeago
left a comment
Owner
There was a problem hiding this comment.
Amazing work, thanks for the fix!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2.
$expr as $typematches any use of theastoken, including importaliases (
import { foo as bar }), namespace imports (import * as ns),and export aliases (
export { foo as bar }). The existing guard! $expr <: within \import $_ from $_`` only handled single-specifierimports and left the rest as false positives.
This was harmless until biome 2.4.9, which fixed metavariable matching
inside
import { ... }/export { ... }clauses(biomejs/biome#9586). After that fix the broken guard started firing.
The fix is to constrain on
TsAsExpression()instead: