Bundler / minifier not handling end of file comments correctly


I have noticed that the bundler doesn't handle single line comments at the end of a javascript file correctly (or as would be expected), when the script is bundled and minified.

A single line comment at the end of one of the script files, without a line break at the end, affects the content/interpretation of the script of the next file.

Suppose script 1 has:
var hello = "Hello";

function SayHelloWorld() {
    alert(hello + "World");

//=======test comment==========(no line break here)
and script two has:
function Test()
    this.a = 1;

//===== another comment with no line break at the end=======
The resulting script after bundling is:
function SayHelloWorld(){alert(hello+"World")}var hello="Hello";this.a=1
Notice that constructor function Test() has disappeared and only the contents of that function are placed on the resulting script;

Removing the comment at the end of the file, or adding a line break after it outputs the correct and expected script
function SayHelloWorld(){alert(hello+"World")}function Test(){this.a=1}var hello="Hello"
about the attatchment: I includes a Bundle.cs (with the bundle definition), the javascript files in the script/testscripts directory, and a modified _layout to include the bundle. This can be copied onto a simple MVC4 internet Application project.

file attachments

Closed Jun 11, 2013 at 7:55 PM by eilonlipton
Hello, and thank you for the bug report. I talked to the developer of that project and he says this bug is fixed in v1.1 Beta 1, which is available on NuGet: http://nuget.org/packages/Microsoft.AspNet.Web.Optimization/1.1.0-Beta1


Rafaelsc wrote May 22, 2013 at 7:01 PM

Same problem here. (With Microsoft ASP.NET Web Optimization Framework 1.0.0)

I'm using jquery-migrate package.
The jquery-migrate-1.1.1.min.js file have a End-line comment, and this comment broke the minification process.