mishoo / UglifyJS

JavaScript parser / mangler / compressor / beautifier toolkit
http://lisperator.net/uglifyjs/
Other
13.17k stars 1.25k forks source link

Fancybox2 cannot be parsed properly #1013

Closed miraclebg closed 8 years ago

miraclebg commented 8 years ago

For some reason fancybox2 is being messed up after uglification by r.js.

After quite some debugging this is what causes it (probably the html template) - after this is removed all is ok:


defaults: {
            skipSingle: false, // disables if gallery contains single image
            pos
[jquery.fancybox_custom.js.zip](https://github.com/mishoo/UglifyJS2/files/182768/jquery.fancybox_custom.js.zip)
ition: 'top', // 'top' or 'bottom'
            tpl: '<div id="fancybox-buttons"><ul><li><a class="btnPrev" title="Previous" href="javascript:;"></a></li><li><a class="btnPlay" title="Start slideshow" href="javascript:;"></a></li><li><a class="btnNext" title="Next" href="javascript:;"></a></li><li><a class="btnToggle" title="Toggle size" href="javascript:;"></a></li><li><a class="btnClose" title="Close" href="javascript:;"></a></li></ul></div>'
        },

I've attached the fancybox file.

screen shot 2016-03-21 at 19 06 30

rvanvelzen commented 8 years ago

I only see some incomplete JS and an image. Please provide a source file, and the calls to bin/uglifyjs with which your issue can be reproduced.

miraclebg commented 8 years ago

Please ignore the attached javascript file. I am attaching the one that you should be looking at now (the previous one was an experiment). jquery.fancybox.js.zip

Once you remove from the file the HTML templates (line 138) - it can compile properly:

// HTML templates
            tpl: {
                wrap     : '<div class="fancybox-wrap" tabIndex="-1"><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>',
                image    : '<img class="fancybox-image" src="{href}" alt="" />',
                iframe   : '<iframe id="fancybox-frame{rnd}" name="fancybox-frame{rnd}" class="fancybox-iframe" frameborder="0" vspace="0" hspace="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen' + (IE ? ' allowtransparency="true"' : '') + '></iframe>',
                error    : '<p class="fancybox-error">The requested content cannot be loaded.<br/>Please try again later.</p>',
                closeBtn : '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"></a>',
                next     : '<a title="Next" class="fancybox-nav fancybox-next" href="javascript:;"><span></span></a>',
                prev     : '<a title="Previous" class="fancybox-nav fancybox-prev" href="javascript:;"><span></span></a>'
            },
miraclebg commented 8 years ago

@rvanvelzen I am not using uglifyjs directly - i am packing up a requirejs project with r.js - which is in turn probably calling your bin?

miraclebg commented 8 years ago

@rvanvelzen Also attached now the final compiled file (which is broken):

payin7.js.zip

miraclebg commented 8 years ago

@rvanvelzen And i've just found out what's the cause (in the correct file now):

Line 144-146:

Was:

closeBtn : '<a title="Close" class="fancybox-item fancybox-close" href="javascript:;"></a>',
                next     : '<a title="Next" class="fancybox-nav fancybox-next" href="javascript:;"><span></span></a>',
                prev     : '<a title="Previous" class="fancybox-nav fancybox-prev" href="javascript:;"><span></span></a>'

Changed it to:

closeBtn : '<a title="Close" class="fancybox-item fancybox-close"></a>',
                next     : '<a title="Next" class="fancybox-nav fancybox-next"><span></span></a>',
                prev     : '<a title="Previous" class="fancybox-nav fancybox-prev"><span></span></a>'

Just removed href="javascript:;" and it compiles properly.

rvanvelzen commented 8 years ago

I'm sorry, I do not believe UglifyJS to be doing anything wrong here - payin7.js is valid JS.

href="javascript:;" is not something we alter, or even read. If it only happens after minification, I suggest that you look into other parts of your build pipeline.

miraclebg commented 8 years ago

@rvanvelzen Hm, well something is definitely messing this up - i'll have to get to the r.js people.

Thanks anyway!