CodeVetter · Repo Unpack · Behavior traces
swc-project/swc
The inspected flows trace concrete calls across JavaScript, native bindings, compiler configuration, and output boundaries. Startup includes platform selection and, for carrier packages, verified materialization before dynamic loading. Transformation and AST round-tripping take different compiler ownership branches. Minification and CLI output provide additional complete paths with explicit failure conditions.
- Startup: the core module reads SWC_BINARY_PATH, requires that path or binding.js, checks getTargetTriple, and attempts @swc/wasm on an exception; the generated loader detects Linux libc through filesystem, process-report, then child-process probes.
- Carrier startup: napi_register_module_v1 calls initialize → Payload::parse/with_integrity → CacheMode::from_env → optional try_replace or cache::materialize → OS library load → resolve raw napi_register_module_v1 → materialized.loaded; the raw registration function then receives the original Node pointers.
- Persistent materialization: cached_at creates the secure namespace, obtains namespace/per-image locks, opens and verifies an existing image, or decodes and verifies a staging file before atomic replace_file; special-file errors return without repair.
- Text transformation: Compiler.transform → bindings.transform → AsyncTask<TransformTask> → compute → new_source_file → Compiler::process_js_file; a legacy JS plugin instead parses first, invokes plugin(m), copies source context, and recursively transforms without the plugin option.
- Compiler pipeline: process_js_file → process_js_with_custom_pass → parse_js_as_input → read_config/build_as_input → apply_transforms → print; a configuration-excluded input produces 'cannot process file because it’s ignored by .swcrc'.
- AST round-trip: ParseTask::compute creates source/comments → parse_js → resolver → serialize_program; parseProgramJson attaches context, then print calls stringifyProgram → PrintTask::compute → deserialize_program_input → fresh compiler for context-bearing input → prepare_program_with_context → Compiler::print.
- Minification: Compiler.minify → native minify → MinifyTask::compute → MinifyTarget::to_file → Compiler::minify → parse_js → paren_remover/resolver → optimize → hygiene when mangling is disabled → fixer → comment handling → print.
- CLI compilation: main → run → CompileOptions::execute → validate → execute_once or a watch handler; stdout mode collects inputs, calls execute_transform/process_js_file, then emit_stdout_output, while directory mode processes output entries in parallel.