-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sources: ["0"], output the correct source
Case 1, sourcemap missing In [terser-js](https://github.com/terser-js/terser#source-map-options), sources are always 0 if old sourcemaps are not provided. The value passed for sourceMap.url is only used to set //# sourceMappingURL=out.js.map in result.code. The value of filename is only used to set file attribute in source map file. In broccoli-uglify-sourcemap we know in this case we are generating sourcemap for the file we are processing, changing 0 to the actual file gives us the correct source. Case2, multiple sourceMap comments source-map-url only matches the very first magic comment so we mistakenly thinks the js file doesn't have a valid sourcemap.
- Loading branch information
Showing
5 changed files
with
121 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const srcURL = require('source-map-url'); | ||
const srcRegExpg = new RegExp(srcURL.regex, 'g'); | ||
|
||
module.exports = function getSourceMapContent(src, inFile, relativePath, silent) { | ||
let urls = []; | ||
let match; | ||
// eslint-disable-next-line no-cond-assign | ||
while (match = srcRegExpg.exec(src)) { | ||
urls.push(match[1] || match[2] || ''); | ||
} | ||
if (urls.length) { | ||
for (let i = urls.length - 1; i >= 0; --i) { | ||
let sourceMapPath = path.join(path.dirname(inFile), urls[i]); | ||
if (fs.existsSync(sourceMapPath)) { | ||
return JSON.parse(fs.readFileSync(sourceMapPath)); | ||
} | ||
} | ||
if (!silent) { | ||
console.warn(`[WARN] (broccoli-uglify-sourcemap) ${urls.map(u => `"${u}"`).join(', ')} referenced in "${relativePath}" could not be found`); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.