Skip to content

Commit

Permalink
Use cwd-relative path for sourceFileName.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Apr 27, 2018
1 parent 74c1239 commit cba1ec1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions packages/babel-core/src/transformation/normalize-opts.js
Expand Up @@ -6,15 +6,18 @@ import type { ResolvedConfig } from "../config";
export default function normalizeOptions(config: ResolvedConfig): {} {
const {
filename,
filenameRelative = filename || "unknown",
cwd,
filenameRelative = typeof filename === "string"
? path.relative(cwd, filename)
: "unknown",
sourceType = "module",
inputSourceMap,
sourceMaps = !!inputSourceMap,

moduleRoot,
sourceRoot = moduleRoot,

sourceFileName = path.basename(filenameRelative),
sourceFileName = filenameRelative,

comments = true,
compact = "auto",
Expand All @@ -35,7 +38,7 @@ export default function normalizeOptions(config: ResolvedConfig): {} {
generatorOpts: Object.assign(
{
// General generator flags.
filename,
filename: filenameRelative,
auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
retainLines: opts.retainLines,
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-core/test/api.js
Expand Up @@ -395,10 +395,12 @@ describe("api", function() {

it("default source map filename", function() {
return transformAsync("var a = 10;", {
cwd: "/some/absolute",
filename: "/some/absolute/file/path.js",
sourceMaps: true,
}).then(function(result) {
expect(result.map.sources).toEqual(["path.js"]);
expect(result.map.sources).toEqual(["file/path.js"]);
expect(result.map.file).toEqual("file/path.js");
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/babel-generator/src/source-map.js
Expand Up @@ -19,6 +19,7 @@ export default class SourceMap {
get() {
if (!this._cachedMap) {
const map = (this._cachedMap = new sourceMap.SourceMapGenerator({
file: this._opts.filename,
sourceRoot: this._opts.sourceRoot,
}));

Expand Down

0 comments on commit cba1ec1

Please sign in to comment.