License detector for UglifyJS that identifies and preserves license comments during minification
Overall
score
98%
Build a JavaScript minification utility that processes a source file and produces minified output while automatically preserving any comment that appears on the first line of the file. This is useful for maintaining license headers during code minification.
Provides license comment detection and preservation during minification.
JavaScript parser and minifier.
File Processing: Create a function that accepts input JavaScript source code as a string and returns minified JavaScript as a string.
First-Line Comment Preservation: Any comment appearing on line 1 of the source code must be preserved in the minified output, regardless of comment type (line comment // or block comment /* */) or content.
Standard Minification: Apply JavaScript minification including whitespace removal and code compression.
Comment Filtering: Comments not on the first line should be removed during minification (standard minification behavior).
// ...) and block comments (/* ... */) on line 1 must be handledInput:
// Copyright 2024 Example Corp. MIT License.
function add(x, y) {
return x + y;
}
console.log(add(5, 10));Expected output (example):
// Copyright 2024 Example Corp. MIT License.
function add(n,o){return n+o}console.log(add(5,10));The first-line comment is preserved while the code is minified.
Input:
function multiply(a, b) {
return a * b;
}Expected output (example):
function multiply(n,o){return n*o}No comments are preserved; standard minification is applied.
Input:
/* Copyright 2024. All rights reserved. */
const greet = (name) => {
return "Hello, " + name;
};Expected output (example):
/* Copyright 2024. All rights reserved. */
const greet=n=>"Hello, "+n;The first-line block comment is preserved while the code is minified.
minify.js { .implementation }Main module that exports a minification function:
minify(sourceCode) - Accepts JavaScript source code as a string and returns minified JavaScript as a string, preserving any first-line comments.minify.test.js { .test }Test suite validating the behavior described in the test cases above.
Install with Tessl CLI
npx tessl i tessl/npm-uglify-save-licensedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10