License detector for UglifyJS that identifies and preserves license comments during minification
Overall
score
98%
Build a comment filtering function that determines which comments should be preserved during code minification. The function should apply multiple criteria to intelligently decide whether each comment is important enough to keep.
Your function should accept a comment object and return a boolean indicating whether the comment should be preserved.
The comment object has the following structure:
file: The file path being processedtype: The comment type ('comment1' for line comments, 'comment2' for block comments)value: The text content of the commentline: The line number where the comment appearsA comment should be preserved if it meets ANY of the following conditions:
@preserve, @cc_on, MIT, MPL, GPL, BSD, ISCL, (c), License, or Copyright! (bang notation)Your function must maintain state across multiple invocations to handle consecutive comments correctly:
MIT License in the content, the function returns true @test!, the function returns true @test@generates
/**
* Determines whether a comment should be preserved during minification.
*
* @param {Object} node - AST node from the parser (unused but part of standard signature)
* @param {Object} comment - Comment information object
* @param {string} comment.file - Current file path being processed
* @param {string} comment.type - Comment type ('comment1' for line, 'comment2' for block)
* @param {string} comment.value - Comment text content
* @param {number} comment.line - Line number of the comment
* @returns {boolean} True if the comment should be preserved, false otherwise
*/
function shouldPreserveComment(node, comment) {
// IMPLEMENTATION HERE
}
module.exports = shouldPreserveComment;Provides comment preservation logic for minification tools.
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