Files
oxc-project__oxc/tasks/coverage/snapshots/minifier_node_compat.snap
Boshen 38e4b535f7 fix(minifier): validate RegExp patterns before marking as pure (#18125)
## 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)
2026-01-18 12:24:39 +08:00

18 lines
723 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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