Platform-specific native binary for SWC TypeScript/JavaScript compiler on macOS ARM64 architecture
89
Build a JavaScript minifier that reduces variable names and compresses code while preserving functionality.
Your tool should accept JavaScript source code as input and produce minified output with the following characteristics:
Variable Name Reduction: All variable, function, and parameter names should be shortened to minimal identifiers (e.g., a, b, c, etc.) while preserving program semantics.
Property Name Handling: The minifier should optionally mangle property names when configured to do so, but must preserve property names that are accessed using bracket notation or are part of the public API.
Whitespace and Formatting: Remove unnecessary whitespace, newlines, and formatting while maintaining code correctness.
Comment Removal: Strip all comments from the source code unless they are marked as important (e.g., license comments starting with /*!).
@generates
/**
* Minifies JavaScript source code with variable name mangling.
*
* @param {string} sourceCode - The JavaScript code to minify
* @param {Object} options - Minification options
* @param {boolean} options.mangleProperties - Whether to mangle property names (default: false)
* @param {string[]} options.reservedNames - Array of variable/property names to preserve
* @param {boolean} options.keepComments - Preserve license comments (default: true)
* @returns {Promise<{code: string, map?: string}>} The minified code and optional source map
*/
async function minify(sourceCode, options = {}) {
// IMPLEMENTATION HERE
}
module.exports = { minify };Given a simple function function calculateTotal(price, tax) { return price + tax; }, the minified output should have shortened parameter names while maintaining functionality. @test
Given code with multiple variable declarations let userName = "Alice"; let userAge = 30; let userEmail = "alice@example.com";, all variable names should be mangled to single-letter identifiers. @test
Given code with property access like obj.myProperty = 5; console.log(obj.myProperty);, property names should NOT be mangled by default, preserving the code's functionality. @test
Given code with a license comment /*! MIT License */ function add(a, b) { return a + b; }, the license comment should be preserved in the output when keepComments is true. @test
Provides high-performance JavaScript parsing, transformation, and minification capabilities.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-swc--core-darwin-arm64docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10