Repository navigation
Commit d2ae12b
fix(parse): keep getFeatureData's global regex a literal (#65)
* fix(parse): keep getFeatureData's global regex a literal
0.15.0 built getFeatureData's regex with new RegExp(featuresRe, "gs").
A transpiler that polyfills named capture groups only wraps regex
literals. CRA's production Babel does this, so in flowchart.fun's
production bundle the copy came back as a plain native RegExp, and
match.groups was undefined. The loop then hit
`if (!match.groups) continue;` on an empty match at lastIndex 0 and
never ended, which froze the page on its first parse.
The global regex is now its own literal, featuresReGlobal, next to
featuresRe. A test keeps the two sources identical. A match without
groups now breaks out of the loop instead of continuing, because an
empty match never advances lastIndex.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* chore(lint): ban building a RegExp from a non-literal
Consumers that transpile named capture groups, like CRA's production
Babel, only wrap regex literals. A RegExp built from another regex
loses match.groups, which is how 0.15.0 froze flowchart.fun's
production build. The lookbehind rule guards against the same kind of
consumer break. Run against 0.15.0's getFeatureData.ts, this rule
flags line 5. It flags nothing in the current tree.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 3e520aa commit d2ae12b
4 files changed
Lines changed: 26 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
6 | 12 | | |
7 | 13 | | |
8 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | 4 | | |
8 | 5 | | |
9 | 6 | | |
| |||
17 | 14 | | |
18 | 15 | | |
19 | 16 | | |
20 | | - | |
| 17 | + | |
| 18 | + | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
0 commit comments