Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a minimal function declaration as the token string to replace preserved comment block #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions lib/jsminify.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@ exports.jsminify = function (code, config, callback) {
}
config = config || exports.config;
var comments = [],
token = '"yUglify: preserved comment block"',
token = 'function fn(){"yUglify: preserved comment block";}',
reMultiComments = /\/\*![\s\S]*?\*\//g,
/*
In some cases Uglify adds a comma, in others it doesn't
So we have to process the tokens twice, first with the comma
then without it to catch both cases and to be clear about it.
*/
reTokens1 = new RegExp(token + ',', 'g'),
reTokens = new RegExp(token, 'g'),
reTokens = new RegExp('function \\w+\\(\\)\\{\\"yUglify: preserved comment block\\";\\}', 'g'),
ast;

try {
Expand All @@ -63,12 +57,6 @@ exports.jsminify = function (code, config, callback) {
code = uglify.split_lines(code, config.max_line_length);
}

//First pass with comma (comment inside code somewhere)
code = code.replace(reTokens1, function () {
return '\n' + comments.shift() + '\n';
});

//Second pass without the comma to catch normal comments
code = code.replace(reTokens, function () {
return '\n' + comments.shift() + '\n';
});
Expand Down