mirror of
https://github.com/hanzoai/swc.git
synced 2026-10-30 19:42:53 +00:00
**Description:** Refactor module transforms around a shared, target-neutral `SourceModule` collection stage. `SourceModule` only collects source-level module facts. CommonJS, AMD, and UMD share syntax stripping and CommonJS-like module-entry reduction, while SystemJS intentionally bypasses those stages and lowers the collected source model into its own IR for dependency setters, live bindings, and execution timing. Key decisions: - Import attributes are retained for SystemJS. CommonJS, AMD, and UMD intentionally do not process them because those formats cannot express import attributes; these lowering paths assume attributed module requests are not provided. - Module transforms now own TypeScript `import = require(...)` and `export =` lowering. - A non-exported `import x = require(...)` is modeled as the CTS form of ES `import.sync`, outside the ES module linking stage. It therefore does not mark the file as ESM, emit an `__esModule` marker, or introduce an `exports` wrapper dependency. The exported form additionally registers `x` as a local export in the linking model. - AMD and UMD emit `import = require(...)` as wrapper dependencies. UMD routes `export =` through the factory result, and SystemJS now supports `export =`. - Anonymous SystemJS default functions are initialized in the `System.register` declaration callback to preserve their hoisting semantics.