CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-swc--core-darwin-arm64

Platform-specific native binary for SWC TypeScript/JavaScript compiler on macOS ARM64 architecture

89

1.15x
Overview
Eval results
Files

task.mdevals/scenario-2/

JavaScript Code Minifier

Build a JavaScript minifier that reduces variable names and compresses code while preserving functionality.

Requirements

Your tool should accept JavaScript source code as input and produce minified output with the following characteristics:

  1. 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.

  2. 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.

  3. Whitespace and Formatting: Remove unnecessary whitespace, newlines, and formatting while maintaining code correctness.

  4. Comment Removal: Strip all comments from the source code unless they are marked as important (e.g., license comments starting with /*!).

Implementation

@generates

API

/**
 * 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 };

Test Cases

  • 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

Dependencies { .dependencies }

@swc/core { .dependency }

Provides high-performance JavaScript parsing, transformation, and minification capabilities.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-swc--core-darwin-arm64

tile.json