Commit 35ed36c
fix(traverse): fix panic when truncating non-ASCII variable names (#16265)
## Summary
Fix panic when `get_var_name_from_node` processes non-ASCII variable
names (Korean, CJK, Greek, etc.).
## Problem
When transpiling code with non-ASCII variable names like Korean:
```typescript
const [서비스이용약관_query, 개인정보수집동의_query] = useQueries({...});
```
The following panic occurs:
`thread 'tokio-runtime-worker' panicked at
oxc_traverse/src/ast_operations/gather_node_parts.rs:26:14:
assertion failed: self.is_char_boundary(new_len)`
## Cause
get_var_name_from_node was using byte-based truncate(20):
name.truncate(20); // Cuts at byte 20, not character 20
Korean characters are 3 bytes in UTF-8, so "서비스이용약관" (7 chars = 21
bytes) gets cut in the middle of '관', causing the panic.
## Solution
Changed to character-based truncation to match
https://github.com/babel/babel/blob/419644f27c5c59deb19e71aaabd417a3bc5483ca/packages/babel-traverse/src/scope/index.ts#L210:
```typescript
if name.len() > 20 {
name = name.chars().take(20).collect();
}
```
The len() > 20 check avoids unnecessary allocation when string is
already short enough (20 bytes guarantees ≤20 chars).
## Test Plan
Added tests for:
- 2-byte UTF-8 (Greek letters)
- 3-byte UTF-8 (Korean characters)
- 4-byte UTF-8
- Mixed ASCII + multi-byte
Co-authored-by: peter <[email protected]>1 parent 02bdf90 commit 35ed36c
1 file changed
+80
-2
lines changedLines changed: 80 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
27 | 42 | | |
28 | 43 | | |
29 | 44 | | |
| |||
563 | 578 | | |
564 | 579 | | |
565 | 580 | | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
0 commit comments