Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default sourceFileName. #7764

Merged
merged 6 commits into from Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 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 = filenameRelative,
sourceFileName = path.basename(filenameRelative),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking the basename here is not right. The sourceFileName should include at least part of the file path.

Perhaps what we should do is change

filenameRelative = filename || "unknown",

to

filenameRelative = typeof filename === "string" ? path.relative(config.options.cwd, filename) || "unknown",

I'd also probably be in favor of removing unknown in favor of null but that could probably wait.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok that sounds right, taking the actual relative path?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think that'd be ideal. We didn't have cwd in 6.x so it wasn't as nice of an option. Once we land the config PR it might even make sense to use the root value, but cwd works for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, that makes sense. will check if browserify+babelify deals well with that too and update tonight.


comments = true,
compact = "auto",
Expand Down
10 changes: 10 additions & 0 deletions packages/babel-core/test/api.js
Expand Up @@ -394,6 +394,16 @@ 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"]);
});
});

it("code option false", function() {
return transformAsync("foo('bar');", { code: false }).then(function(
result,
Expand Down