inputSourceMap should work when it is in an external file (#10623)

* fix: construct comment block for fromMapFileComment

* add test

* small tweak: redundant capturing group
This commit is contained in:
Huáng Jùnliàng 2019-10-31 16:12:44 -04:00 committed by GitHub
parent a2b5437b01
commit d08702c9d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 2 deletions

View File

@ -65,7 +65,8 @@ export default function normalizeFile(
if (typeof options.filename === "string" && lastComment) {
try {
inputMap = convertSourceMap.fromMapFileComment(
lastComment,
// fromMapFileComment requires the whole comment block
`//${lastComment}`,
path.dirname(options.filename),
);
} catch (err) {
@ -156,7 +157,7 @@ function parser(
// eslint-disable-next-line max-len
const INLINE_SOURCEMAP_REGEX = /^[@#]\s+sourceMappingURL=data:(?:application|text)\/json;(?:charset[:=]\S+?;)?base64,(?:.*)$/;
const EXTERNAL_SOURCEMAP_REGEX = /^[@#][ \t]+sourceMappingURL=([^\s'"`]+?)[ \t]*$/;
const EXTERNAL_SOURCEMAP_REGEX = /^[@#][ \t]+sourceMappingURL=(?:[^\s'"`]+?)[ \t]*$/;
function extractCommentsFromList(regex, comments, lastComment) {
if (comments) {

View File

@ -0,0 +1,5 @@
var foo = function () {
return 4;
};
//# sourceMappingURL=input.js.map

View File

@ -0,0 +1 @@
{"version":3,"sources":["original.js"],"names":[],"mappings":"AAAA,UAAU,Y;SAAM,C;CAAC","sourcesContent":["var foo = () => 4;"]}

View File

@ -0,0 +1,3 @@
{
"inputSourceMap": true
}

View File

@ -0,0 +1,3 @@
var foo = function () {
return 4;
};

View File

@ -0,0 +1,7 @@
{
"mappings": "AAAA,IAAA,GAAA,GAAU,Y;SAAM,C;AAAC,CAAjB",
"names": [],
"sources": ["original.js"],
"sourcesContent": ["var foo = () => 4;"],
"version": 3
}