Skip to content

Commit ae2c733

Browse files
kdy1claudegithub-actions[bot]
authored
feat: Add SWC feature flags library with build-time and runtime transforms (#578)
Implements a two-phase feature flag system: Phase 1 (Build-time): - SWC Wasm plugin that marks feature flag usage - Replaces flag identifiers with __SWC_FLAGS__ markers - Removes imports and hook calls from configured libraries - Supports destructuring patterns and multiple libraries - Handles variable shadowing correctly using SWC's Id system Phase 2 (Runtime): - Standalone Rust crate for dead code elimination - Substitutes flag values with boolean literals - Eliminates dead branches (if, ternary, logical operators) - Tracks statistics (bytes removed, branches eliminated) - Unwraps block statements for cleaner output Features: - Customizable function names (not hardcoded) - Selective flag exclusion - Scope-safe transformations - Minifier-safe markers - Comprehensive fixture tests - TypeScript definitions Packages: - crates/swc_feature_flags: Standalone Rust crate - packages/feature-flags: SWC Wasm plugin wrapper --------- Co-authored-by: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
1 parent 15f32da commit ae2c733

25 files changed

Lines changed: 1877 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
description = "Feature flag transformation for SWC - build-time marking and runtime dead code elimination"
3+
name = "swc_feature_flags"
4+
version = "0.1.0"
5+
6+
authors = { workspace = true }
7+
edition = { workspace = true }
8+
homepage = { workspace = true }
9+
license = { workspace = true }
10+
repository = { workspace = true }
11+
rust-version = { workspace = true }
12+
13+
[dependencies]
14+
serde = { workspace = true, features = ["derive"] }
15+
swc_atoms = { workspace = true }
16+
swc_common = { workspace = true }
17+
swc_ecma_ast = { workspace = true }
18+
swc_ecma_codegen = { workspace = true }
19+
swc_ecma_visit = { workspace = true }
20+
21+
[dev-dependencies]
22+
swc_ecma_codegen = { workspace = true }
23+
swc_ecma_parser = { workspace = true }
24+
swc_ecma_transforms_base = { workspace = true }
25+
swc_ecma_transforms_testing = { workspace = true }
26+
testing = { workspace = true }

0 commit comments

Comments
 (0)