Skip to content

Commit

Permalink
inputSourceMap should work when it is in an external file (#10623)
Browse files Browse the repository at this point in the history
* fix: construct comment block for fromMapFileComment

* add test

* small tweak: redundant capturing group
  • Loading branch information
JLHwung committed Oct 31, 2019
1 parent a2b5437 commit d08702c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/babel-core/src/transformation/normalize-file.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

0 comments on commit d08702c

Please sign in to comment.