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

wrong minified JS #645

Closed
ajinkyapisal opened this issue Mar 2, 2015 · 5 comments
Closed

wrong minified JS #645

ajinkyapisal opened this issue Mar 2, 2015 · 5 comments

Comments

@ajinkyapisal
Copy link

Here is the piece of javascript code.

$(function(){
  var modalElement = '<div id="confirm-logout-modal" class="modal hide fade">' +
    '<div class="modal-header">' +
    '<h3 class="modal-title">Logout</h3>' +
    '</div>' +
    '<div class="modal-body">' +
    '<p>' +
    '<span class="modal-main-message">You have been logged</span>' +
    '</p>' +
    '</div>' +
    '<div class="modal-footer">' +
    '<button id="btn-confirm" class="btn btn-success">Okay</button>' +
    '</div>' +
    '</div>';
  $("body").append(modalElement);

  $('#btn-open').click(function(){
    $('#confirm-logout-modal').modal('show');
  });
  $('#btn-close').click(function(){
    $('#confirm-logout-modal').modal('hide');
  });
});

I minified it using https://github.com/lautis/uglifier

Uglifier.compile(File.read("source.js"))

Its output is

004 > Uglifier.compile(File.read("source.js"))
 => "$(function(){var o='<div id=\"confirm-logout-modal\" class=\"modal hide fade\"><div class=\"modal-header\"><h3 class=\"modal-title\">Logout</h3></div><div class=\"modal-body\"><p><span class=\"modal-main-message\">You have been logged</span></p></div><div class=\"modal-footer\"><button id=\"btn-confirm\" class=\"btn btn-success\">Okay</button></div></div>';$(\"body\").append(o),$(\"#btn-open\").click(function(){$(\"#confirm-logout-modal\").modal(\"show\")}),$(\"#btn-close\").click(function(){$(\"#confirm-logout-modal\").modal(\"hide\")})});"

Here is the output of the chrome console

> $(function(){var o='<div id=\"confirm-logout-modal\" class=\"modal hide fade\"><div class=\"modal-header\"><h3 class=\"modal-title\">Logout</h3></div><div class=\"modal-body\"><p><span class=\"modal-main-message\">You have been logged</span></p></div><div class=\"modal-footer\"><button id=\"btn-confirm\" class=\"btn btn-success\">Okay</button></div></div>';$(\"body\").append(o),$(\"#btn-open\").click(function(){$(\"#confirm-logout-modal\").modal(\"show\")}),$(\"#btn-close\").click(function(){$(\"#confirm-logout-modal\").modal(\"hide\")})});
VM247:2 Uncaught SyntaxError: Unexpected token ILLEGAL
@mishoo
Copy link
Owner

mishoo commented Mar 2, 2015

The commas are valid.

@mishoo mishoo closed this as completed Mar 2, 2015
@ajinkyapisal
Copy link
Author

I just tried using this code it is invalid code. Please look into it

@ajinkyapisal
Copy link
Author

Here is js fiddle without minifying
http://jsfiddle.net/2g9zcxhj/3/

Here is js fiddle with minifying
http://jsfiddle.net/2g9zcxhj/1/

Minified version is not working.

@mishoo
Copy link
Owner

mishoo commented Mar 2, 2015

That code compresses just fine here:

$(function(){var o='<div id="confirm-logout-modal" class="modal hide fade"><div class="modal-header"><h3 class="modal-title">Logout</h3></div><div class="modal-body"><p><span class="modal-main-message">You have been logged</span></p></div><div class="modal-footer"><button id="btn-confirm" class="btn btn-success">Okay</button></div></div>';$("body").append(o),$("#btn-open").click(function(){$("#confirm-logout-modal").modal("show")}),$("#btn-close").click(function(){$("#confirm-logout-modal").modal("hide")})});

Note that I'm using the UglifyJS's command line. In your case the minified code contains obvious syntax errors, but that's probably a bug of https://github.com/lautis/uglifier — please direct your questions there.

@ajinkyapisal
Copy link
Author

Okay.Thanks

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

2 participants