diff --git a/packages/babel-core/src/transformation/normalize-file.js b/packages/babel-core/src/transformation/normalize-file.js index fa4d03505d..22ea4ef470 100644 --- a/packages/babel-core/src/transformation/normalize-file.js +++ b/packages/babel-core/src/transformation/normalize-file.js @@ -27,15 +27,23 @@ export default function normalizeFile( let inputMap = null; if (options.inputSourceMap !== false) { - try { - inputMap = convertSourceMap.fromSource(code); + // If an explicit object is passed in, it overrides the processing of + // source maps that may be in the file itself. + if (typeof options.inputSourceMap === "object") { + inputMap = convertSourceMap.fromObject(options.inputSourceMap); + } - if (inputMap) { + if (!inputMap) { + try { + inputMap = convertSourceMap.fromSource(code); + + if (inputMap) { + code = convertSourceMap.removeComments(code); + } + } catch (err) { + debug("discarding unknown inline input sourcemap", err); code = convertSourceMap.removeComments(code); } - } catch (err) { - debug("discarding unknown inline input sourcemap", err); - code = convertSourceMap.removeComments(code); } if (!inputMap) { @@ -50,10 +58,6 @@ export default function normalizeFile( code = convertSourceMap.removeMapFileComments(code); } } - - if (!inputMap && typeof options.inputSourceMap === "object") { - inputMap = convertSourceMap.fromObject(options.inputSourceMap); - } } if (ast) {