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

can not preserve comments rightly #82

Closed
gideonstele opened this issue Feb 5, 2015 · 9 comments
Closed

can not preserve comments rightly #82

gideonstele opened this issue Feb 5, 2015 · 9 comments

Comments

@gideonstele
Copy link

such as:

gulp.task('script',function(){
   gulp.src('js/**/*.js')
     .pipe(uglify({
       preserveComments:'some'
     }))
     .pipe(gulp.dest(PATH.js));
})
/* origin:*/
/*!
  do not delete
*/
var a = String(function(){
    /*!
    <div class="foo">{{bar}}</div>
    */
    }).replace(/^[^\{]*\{\s*\/\*!?|\*\/[;|\s]*\}$/g, '');

output:

var a = String(function(){}).replace(/^[^\{]*\{\s*\/\*!?|\*\/[;|\s]*\}$/g, '');

Comments with a bang(!) or @preserve, @license, @cc_on,should not be deleted,as README said.

@terinjokes
Copy link
Owner

@ShiJinYu If you swap the order of the "origin" and "do not delete" comments, does it work?

@gideonstele
Copy link
Author

No, it doesn't work.
I just want to put the HTML template code in a javascript file,in the form of js comment.But Uglify looks does not correctly identify it.
In addition,if I set the value of preserveComments as 'all',all comments would be preserved but the comment as this form:

String(function(){
    /*! I will be deleted in any case
    <div class="foo">{{bar}}</div>
    */
    })

@taylortom
Copy link

I'm also experiencing the same issue. I can't get any values of preserveComments to work besides none.

@gideonstele
Copy link
Author

What a pity! It is really a very strange requirement what I had encountered.

@terinjokes
Copy link
Owner

This might be a regression in how uglifyjs handles preserving comments.
None of the code in this project has changed, and our tests still pass.

I'll look when I return from vacation next week. ✨
On Feb 27, 2015 2:34 AM, "Shijinyu" notifications@github.com wrote:

What a pity! It does be a very strange requirement what I had encountered.


Reply to this email directly or view it on GitHub
#82 (comment)
.

@gideonstele
Copy link
Author

I'm very much obliged to you,enjoying your time.

@colinskow
Copy link

I have been having the same issue. I made it work by specifying the comments options manually

.pipe(uglify({output: {comments: /^!|@preserve|@license|@cc_on/i}}))

@terinjokes
Copy link
Owner

I've just confirmed the proper option is being generated and passed to UglifyJS correctly. Can you reproduce the behavior calling their binary directly?

Also, I note the following from the --help screen:

Note that currently not *all* comments can be kept when
compression is on, because of dead code removal or
cascading statements into sequences. 

@gideonstele
Copy link
Author

UglifyJS code is too complicated for me, I will try later but I'm not sure if I can reproduce. Thank you so much for making nothing of hardships to find out way and discuss this issue with me.

Go to bed early please. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants