Skip to content

Commit 8628db3

Browse files
committed
TS imports, special handling for @angular-like refs
1 parent dc13756 commit 8628db3

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

stackmuncher_lib/src/kwc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ impl KeywordCounter {
9494

9595
// loop through the characters to find the first boundary
9696
for (i, c) in kwc.k.as_bytes().iter().enumerate() {
97-
// keep iterating until the first separator (not -._"')
98-
if c.is_ascii_alphanumeric() || *c == 45u8 || *c == 46u8 || *c == 95u8 {
97+
// keep iterating until the first separator (not -._"'@)
98+
if c.is_ascii_alphanumeric() || *c == 45u8 || *c == 46u8 || *c == 95u8 || *c == 64u8 {
9999
continue;
100100
}
101101

stackmuncher_lib/src/tech.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,23 @@ impl Tech {
291291
tech.refs.remove(&local_import);
292292
}
293293

294+
// some TypeScript refs start with @, e.g. @angular/core
295+
// it's a valid name, but @ will get in the way of users searching for "angular"
296+
tech.refs = tech
297+
.refs
298+
.into_iter()
299+
.map(|kwc| {
300+
if kwc.k.starts_with("@") {
301+
KeywordCounter {
302+
k: kwc.k.trim_start_matches("@").to_string(),
303+
..kwc
304+
}
305+
} else {
306+
kwc
307+
}
308+
})
309+
.collect::<HashSet<KeywordCounter>>();
310+
294311
tech
295312
}
296313
}

stackmuncher_lib/stm_rules/munchers/ts.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
],
1717
"block_comments_end": [
1818
"(?i)\\*/\\s*$"
19+
],
20+
"refs": [
21+
"^[[:blank:]]*import[[:blank:]]+.*[[:blank:]]*['\"]([@A-Za-z0-9_][@A-Za-z0-9_\\-\\.]+).*['\"][[:blank:]]*;"
1922
]
2023
}

0 commit comments

Comments
 (0)