mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
75663c077d
## Summary Part of https://github.com/oxc-project/oxc/issues/6073 and #11844 - Add `ConstantValue` type in `oxc_syntax` for representing enum member values (number/string) - Implement enum member value evaluation in `oxc_semantic` supporting numeric auto-increment, string values, binary/unary expressions, cross-member and cross-enum references, template literals, and merged enum declarations - Store evaluated enum member values in `Scoping` via `EnumData` struct with getter/setter APIs and enum body scope tracking - All enum evaluation code is gated behind the `enum_eval` Cargo feature (enabled by `oxc_transformer`) ### Feature gate The `enum_eval` feature controls: - `ts_enum` module (evaluator + data types) - `EnumData` field and enum-related methods on `Scoping` - `oxc_syntax/to_js_string` dependency Consumers that don't need enum values (linter, language server) pay zero cost. ### Babel alignment Unary operators on strings follow Babel's JS-coercion semantics (`+"s"` → `"s"`, `-"s"` → `NaN`, `~"s"` → `-1`), which differs from TypeScript (unevaluated). This is documented in the source. ## Test plan - [x] Integration tests in `crates/oxc_semantic/tests/integration/enum_values.rs` - [x] Semantic TypeScript conformance snapshot updated - [x] `cargo check -p oxc_semantic` passes (without feature) - [x] `cargo check -p oxc_semantic --features enum_eval` passes (with feature) - [x] `cargo check -p oxc_transformer` passes (enables feature transitively)
10 lines
155 B
Rust
10 lines
155 B
Rust
#![expect(clippy::missing_panics_doc)]
|
|
|
|
pub mod cfg;
|
|
pub mod classes;
|
|
pub mod enum_values;
|
|
pub mod modules;
|
|
pub mod scopes;
|
|
pub mod symbols;
|
|
pub mod util;
|