terinjokes/gulp-uglify

Gulp-uglify removes back-slash at the end of a line within a multi line string, causing a corrupted source-maps

Closed this issue · 2 comments

When the source code contains a "traditional" multiline string, as oppose to using string interpolation using back-ticks, and one of the lines within the string ends with a back-slash, the uglification process removes that back-slash, but the source-map generated by "gulp-sourcemaps" package doesn't take this into account, causing all following source-map segments to be out of sync with the source code.

An excerpt from the build script used:

sourcemaps = require("gulp-sourcemaps"),
uglify = require("gulp-uglify")

var thePipe = gulp
      .src(sourceFiles)
      .pipe(sourcemaps.init({ loadMaps: true }))
      ...
      .pipe(uglify({ compress: false, mangle: true }))
      .pipe(sourcemaps.write(".", createSourceMapOptions(moduleInfo)))
      ...

An excerpt from the source code:

console.error("Error found in module: \r\n\
abc");

I'm sorry you're running into this problem; working with sourcemaps is pretty painful. Unfortunately, the sourcemaps created by UglifyJS are often incomplete or subtlety incorrect. There's not much I can do here: I pass the sourcemaps created by UglifyJS to vinyl.

Pull requests welcome, but the fix is likely required in another package.

Thanks @terinjokes for addressing the issue.

I've opened an issue mishoo/UglifyJS#3748 in UglifyJS repository https://github.com/mishoo/UglifyJS2.