Skip to content

Commit 4cafb71

Browse files
authored
fix(grit): fix queries for export { $foo } ... (#9586)
1 parent 27969fd commit 4cafb71

18 files changed

Lines changed: 262 additions & 46 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#8828](https://github.com/biomejs/biome/issues/8828): Grit patterns using `export { $foo } from $source` now match named re-exports in JavaScript and TypeScript files.

crates/biome_grit_patterns/src/grit_target_language.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ macro_rules! generate_target_language {
181181
fn is_metavariable(&self, node: &GritTargetNode) -> bool {
182182
node.kind() == self.metavariable_kind()
183183
|| (self.is_alternative_metavariable_kind(node.kind())
184-
&& self.exact_replaced_variable_regex().is_match(node.text()))
184+
&& self
185+
.exact_replaced_variable_regex()
186+
.is_match(node.text().trim()))
185187
}
186188

187189
fn align_padding<'a>(

crates/biome_grit_patterns/src/pattern_compiler/snippet_compiler.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,4 +972,39 @@ mod tests {
972972
)
973973
"#);
974974
}
975+
976+
#[test]
977+
fn test_export_named_from_snippet_node() {
978+
let snippet = GritJsParser.parse_snippet("", "export { µfoo } from \"source\"", "");
979+
let node = node_from_tree(&snippet).expect("no node found");
980+
let formatted = format!("{node:#?}");
981+
982+
insta::assert_snapshot!(formatted, @r###"
983+
GritTargetNode {
984+
node: JsLanguage(
985+
Node(
986+
0: JS_EXPORT@0..30
987+
0: JS_DECORATOR_LIST@0..0
988+
1: EXPORT_KW@0..7 "export" [] [Whitespace(" ")]
989+
2: JS_EXPORT_NAMED_FROM_CLAUSE@7..30
990+
0: (empty)
991+
1: L_CURLY@7..9 "{" [] [Whitespace(" ")]
992+
2: JS_EXPORT_NAMED_FROM_SPECIFIER_LIST@9..15
993+
0: JS_EXPORT_NAMED_FROM_SPECIFIER@9..15
994+
0: (empty)
995+
1: JS_METAVARIABLE@9..15
996+
0: GRIT_METAVARIABLE@9..15 "µfoo" [] [Whitespace(" ")]
997+
2: (empty)
998+
3: R_CURLY@15..17 "}" [] [Whitespace(" ")]
999+
4: FROM_KW@17..22 "from" [] [Whitespace(" ")]
1000+
5: JS_MODULE_SOURCE@22..30
1001+
0: JS_STRING_LITERAL@22..30 "\"source\"" [] []
1002+
6: (empty)
1003+
7: (empty)
1004+
,
1005+
),
1006+
),
1007+
}
1008+
"###);
1009+
}
9751010
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`export { $foo } from $source`
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/biome_grit_patterns/tests/spec_tests.rs
3+
expression: export_named_from_patterns
4+
---
5+
SnapshotResult {
6+
messages: [],
7+
matched_ranges: [
8+
"2:1-2:39",
9+
],
10+
rewritten_files: [],
11+
created_files: [],
12+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Named re-export
2+
export { foo } from "../../deep/path";

crates/biome_js_analyze/src/lint/nursery/no_redundant_default_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn get_binding_from_identifier(
105105
.name()
106106
.ok()
107107
.and_then(|ref_id| model.binding(&ref_id)),
108-
AnyIdentifier::JsLiteralExportName(_) => None,
108+
AnyIdentifier::AnyJsLiteralExportName(_) => None,
109109
}
110110
}
111111

crates/biome_js_factory/src/generated/node_factory.rs

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_js_factory/src/generated/syntax_factory.rs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_js_formatter/src/generated.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11979,6 +11979,31 @@ impl IntoFormat<JsFormatContext> for biome_js_syntax::AnyJsInProperty {
1197911979
)
1198011980
}
1198111981
}
11982+
impl AsFormat<JsFormatContext> for biome_js_syntax::AnyJsLiteralExportName {
11983+
type Format<'a> = FormatRefWithRule<
11984+
'a,
11985+
biome_js_syntax::AnyJsLiteralExportName,
11986+
crate::js::any::literal_export_name::FormatAnyJsLiteralExportName,
11987+
>;
11988+
fn format(&self) -> Self::Format<'_> {
11989+
FormatRefWithRule::new(
11990+
self,
11991+
crate::js::any::literal_export_name::FormatAnyJsLiteralExportName::default(),
11992+
)
11993+
}
11994+
}
11995+
impl IntoFormat<JsFormatContext> for biome_js_syntax::AnyJsLiteralExportName {
11996+
type Format = FormatOwnedWithRule<
11997+
biome_js_syntax::AnyJsLiteralExportName,
11998+
crate::js::any::literal_export_name::FormatAnyJsLiteralExportName,
11999+
>;
12000+
fn into_format(self) -> Self::Format {
12001+
FormatOwnedWithRule::new(
12002+
self,
12003+
crate::js::any::literal_export_name::FormatAnyJsLiteralExportName::default(),
12004+
)
12005+
}
12006+
}
1198212007
impl AsFormat<JsFormatContext> for biome_js_syntax::AnyJsLiteralExpression {
1198312008
type Format<'a> = FormatRefWithRule<
1198412009
'a,

0 commit comments

Comments
 (0)