mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
38e4b535f7
## Summary
Invalid RegExp patterns like `RegExp("[")` or invalid flags like `RegExp("a", "xyz")` throw `SyntaxError` at runtime, but the minifier was incorrectly removing them.
This change uses `oxc_regular_expression` to validate patterns at compile time:
- Valid patterns are marked as pure and can be removed when unused
- Invalid patterns or non-literal arguments are kept (preserving runtime errors)
### Behavior
| Input | Valid? | Removed? |
|-------|--------|----------|
| `RegExp()` | ✅ | ✅ |
| `RegExp('a', 'g')` | ✅ | ✅ |
| `RegExp(/foo/)` | ✅ | ✅ |
| `RegExp('[')` | ❌ | ❌ (throws SyntaxError) |
| `RegExp('a', 'xyz')` | ❌ | ❌ (throws SyntaxError) |
| `RegExp(variable)` | ? | ❌ (can't determine) |
Fixes #18050
## Test plan
- [x] Updated existing tests to reflect correct behavior
- [x] Added tests for invalid patterns and flags
- [x] `cargo test -p oxc_minifier` passes
- [x] `cargo test -p oxc_ecmascript` passes
🤖 Generated with [Claude Code](https://claude.com/claude-code)
18 lines
723 B
Plaintext
18 lines
723 B
Plaintext
commit: 499beb6f
|
||
|
||
minifier_node_compat Summary:
|
||
AST Parsed : 938/938 (100.00%)
|
||
Positive Passed: 932/938 (99.36%)
|
||
execution_result: tasks/coverage/ES2015/built-ins›Proxy›"getOwnPropertyDescriptor" handler invariants
|
||
|
||
execution_result: tasks/coverage/ES2015/misc›Proxy, internal 'get' calls›HasBinding
|
||
|
||
execution_result: tasks/coverage/ES2015/misc›Proxy, internal 'get' calls›String.raw
|
||
|
||
execution_result: tasks/coverage/ES2015/misc›Proxy, internal 'ownKeys' calls›TestIntegrityLevel
|
||
|
||
execution_result: tasks/coverage/ES2018/misc›Proxy "ownKeys" handler, duplicate keys for non-extensible targets
|
||
|
||
execution_result: tasks/coverage/ES2022/features›Object.hasOwn›ToObject called before ToPropertyKey
|
||
|