fix(js,ts): find a store exported by an export { } list when its name starts or ends with $ (#2384)

TreeSitterExtractor.isExportedLater and its kernel mirror is_exported_later
bounded the name in the `export { ... }` branch with `\b`, which takes a `$`
for a separator. It never fires beside a leading or trailing `$`, so
`const items$ = create(...)` + `export { items$ };` (or `export { $items as
default };` for a `$items` store) never matched, and the store's actions
were not extracted on either engine. It also matched inside a longer name:
`export { useStore$ }` or `export { $useStore }` counted as exporting a
store named `useStore`.

The clause branch now bounds the name with a character that can't continue
an identifier. The regex crate has no look-around, so the bounds consume,
and both sides spell the class in ASCII, since the crate's `\w` is Unicode
while JS's is ASCII. Plain names decide as before apart from the two false
positives. A non-ASCII letter written against the name (`export {
éuseStore }`) used to split the engines (the kernel's Unicode `\b` said not
exported, the wasm path exported); both now give the wasm answer.

Adds kernel/wasm parity cases (ts/tsx/js/jsx) inside 'a store exported by a
later statement', and the same cases in store-exported-later.test.ts, for
`items$`, `$items as default` and both false-positive shapes. They fail with
the unfixed kernel and with the unfixed TS on the wasm path, and pass with
both fixes.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-10-06 15:31:37 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent d500e58a52
commit 5f5b8db620
5 changed files with 45 additions and 2 deletions
+5 -1
View File
@@ -2818,8 +2818,12 @@ export class TreeSitterExtractor {
// not the character. Escaped as the kernel's `regex::escape` does, so
// both paths decide the same.
const n = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
// Inside `{ … }` the name is bounded by a character that can't continue
// an identifier, not by `\b`, which takes a `$` for a separator: it can't
// bound `items$` and finds `items` inside it. Spelled in ASCII, as the
// kernel spells it, since the kernel's `\w` is Unicode.
const re = new RegExp(
`^[ \\t]*export\\s+(?:default\\s+${n}\\s*;?[ \\t]*$|\\{[^}]*\\b${n}\\b[^}]*\\})`,
`^[ \\t]*export\\s+(?:default\\s+${n}\\s*;?[ \\t]*$|\\{(?:[^}]*[^0-9A-Za-z_$}])?${n}(?:[^0-9A-Za-z_$}][^}]*)?\\})`,
'm'
);
return re.test(this.source);