CodeVetter · Repo Unpack · Data flow
swc-project/swc
JavaScript requests cross the native boundary as source strings, serialized Programs, and JSON option buffers. Compiler instances own source maps, while AST envelopes preserve enough original source information to restore positions across calls. Configuration builds the transformation pass and output metadata before code generation. Persistent state mainly appears in native image and plugin caches; CLI handlers separately own generated-file writes.
- toBuffer serializes options with JSON.stringify; transform classifies non-string input as a Program and uses stringifyProgram before calling the native binding.
- Native transform chooses Input::Program with the shared compiler or Input::Source with a fresh compiler; TransformTask::compute deserializes options, adjusts filename-dependent config, and reads files or creates SourceFiles before compilation.
- parse serializes ProgramEnvelope with source text, real filename, and byte bounds; JavaScript stores sourceContext on a non-enumerable Symbol and includes it again only when serializing the Program for native consumption.
- Context-bearing ASTs restore a SourceFile, require its byte length to match the original range, and rebase positions; out-of-range spans become DUMMY_SP, while dummy and reserved positions are preserved.
- parse_js_as_input first applies filename matching, then read_config, then Options::build_as_input; explicit config paths bypass discovery, and RootMode::Upward errors when no .swcrc is found.
- apply_transforms captures auxiliary output while applying the configured pass under HELPERS and HANDLER, optionally downgrades a Flow type-only module, filters comments, and forwards source-map settings to print.
- WASM plugins receive a versioned serialized Program; outputs feed the next plugin as serialized bytes, and the host deserializes once after the configured sequence finishes.
- Native images persist in a user/version namespace under a digest filename, using locks and staging replacement; compiler printing itself does not write its target path, whereas CLI emit_directory_output writes code, maps, and optional declarations.