diff --git a/packages/babel-cli/src/babel/dir.js b/packages/babel-cli/src/babel/dir.js index 28b2f5bd3c..e03daf9cf4 100644 --- a/packages/babel-cli/src/babel/dir.js +++ b/packages/babel-cli/src/babel/dir.js @@ -28,7 +28,6 @@ export default function(commander, filenames, opts) { defaults( { sourceFileName: slash(path.relative(dest + "/..", src)), - sourceMapTarget: path.basename(relative), }, opts, ), @@ -44,6 +43,7 @@ export default function(commander, filenames, opts) { ) { const mapLoc = dest + ".map"; res.code = util.addSourceMappingUrl(res.code, mapLoc); + res.map.file = path.basename(relative); outputFileSync(mapLoc, JSON.stringify(res.map)); } diff --git a/packages/babel-cli/src/babel/file.js b/packages/babel-cli/src/babel/file.js index 9a08545b76..def6aa3eb7 100644 --- a/packages/babel-cli/src/babel/file.js +++ b/packages/babel-cli/src/babel/file.js @@ -16,7 +16,10 @@ export default function(commander, filenames, opts) { const buildResult = function() { const map = new sourceMap.SourceMapGenerator({ - file: path.basename(commander.outFile || "") || "stdout", + file: + commander.sourceMapTarget || + path.basename(commander.outFile || "") || + "stdout", sourceRoot: opts.sourceRoot, }); diff --git a/packages/babel-cli/src/babel/index.js b/packages/babel-cli/src/babel/index.js index 6d80942134..68a4c9b80e 100755 --- a/packages/babel-cli/src/babel/index.js +++ b/packages/babel-cli/src/babel/index.js @@ -259,6 +259,7 @@ delete opts.configFile; delete opts.deleteDirOnStart; delete opts.keepFileExtension; delete opts.relative; +delete opts.sourceMapTarget; // Commander will default the "--no-" arguments to true, but we want to leave them undefined so that // @babel/core can handle the default-assignment logic on its own. diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/bar/bar.js b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/bar/bar.js index 8216b06eeb..7bc139ae8a 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/bar/bar.js +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/bar/bar.js @@ -7,4 +7,4 @@ function _classCallCheck(instance, Constructor) { if (!_instanceof(instance, Con var Test = function Test() { _classCallCheck(this, Test); }; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbIlRlc3QiXSwibWFwcGluZ3MiOiI7Ozs7OztJQUFNQSxJIiwiZmlsZSI6ImJhci5qcyIsInNvdXJjZXNDb250ZW50IjpbImNsYXNzIFRlc3Qge1xuXG59Il19 +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9iYXIvYmFyLmpzIl0sIm5hbWVzIjpbIlRlc3QiXSwibWFwcGluZ3MiOiI7Ozs7OztJQUFNQSxJIiwic291cmNlc0NvbnRlbnQiOlsiY2xhc3MgVGVzdCB7XG5cbn0iXX0= diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js index 6439e69a2f..a7df874e43 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps inline/out-files/lib/foo.js @@ -3,4 +3,4 @@ arr.map(function (x) { return x * MULTIPLIER; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCIsIk1VTFRJUExJRVIiXSwibWFwcGluZ3MiOiI7O0FBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlDLFVBQVQ7QUFBQSxDQUFSIiwiZmlsZSI6ImZvby5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogTVVMVElQTElFUik7Il19 +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9mb28uanMiXSwibmFtZXMiOlsiYXJyIiwibWFwIiwieCIsIk1VTFRJUExJRVIiXSwibWFwcGluZ3MiOiI7O0FBQUFBLElBQUlDLEdBQUosQ0FBUTtBQUFBLFNBQUtDLElBQUlDLFVBQVQ7QUFBQSxDQUFSIiwic291cmNlc0NvbnRlbnQiOlsiYXJyLm1hcCh4ID0+IHggKiBNVUxUSVBMSUVSKTsiXX0= diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map index a970cba944..99078be50b 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/bar/bar.js.map @@ -1 +1 @@ -{"version":3,"sources":["../../src/bar/bar.js"],"names":["Test"],"mappings":";;;;;;IAAMA,I","file":"bar.js","sourcesContent":["class Test {\n\n}"]} +{"version":3,"sources":["../../src/bar/bar.js"],"names":["Test"],"mappings":";;;;;;IAAMA,I","sourcesContent":["class Test {\n\n}"],"file":"bar.js"} diff --git a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map index a97ad9e88f..595013088c 100644 --- a/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map +++ b/packages/babel-cli/test/fixtures/babel/dir --out-dir --source-maps/out-files/lib/foo.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/foo.js"],"names":["arr","map","x","MULTIPLIER"],"mappings":";;AAAAA,IAAIC,GAAJ,CAAQ;AAAA,SAAKC,IAAIC,UAAT;AAAA,CAAR","file":"foo.js","sourcesContent":["arr.map(x => x * MULTIPLIER);"]} +{"version":3,"sources":["../src/foo.js"],"names":["arr","map","x","MULTIPLIER"],"mappings":";;AAAAA,IAAIC,GAAJ,CAAQ;AAAA,SAAKC,IAAIC,UAAT;AAAA,CAAR","sourcesContent":["arr.map(x => x * MULTIPLIER);"],"file":"foo.js"} diff --git a/packages/babel-core/README.md b/packages/babel-core/README.md index c2e3fd3436..8814930519 100644 --- a/packages/babel-core/README.md +++ b/packages/babel-core/README.md @@ -242,7 +242,6 @@ Following is a table of the options you can use: | `shouldPrintComment` | `null` | An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE:** This overrides the `comment` option when used | | `sourceFileName` | `(filenameRelative)` | Set `sources[0]` on returned source map | | `sourceMaps` | `false` | If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"` then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!** To have sourcemaps emitted using the CLI, you must pass it the `--source-maps` option | -| `sourceMapTarget` | `(filenameRelative)` | Set `file` on returned source map | | `sourceRoot` | `(moduleRoot)` | The root from which all sources are relative | | `sourceType` | `"module"` | Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". `"unambiguous"` will make Babel attempt to _guess_, based on the presence of ES6 `import` or `export` statements. Files with ES6 `import`s and `export`s are considered `"module"` and are otherwise `"script"`. | | `wrapPluginVisitorMethod`| `null` | An optional callback that can be used to wrap visitor methods. **NOTE:** This is useful for things like introspection, and not really needed for implementing anything. Called as `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`. diff --git a/packages/babel-core/src/config/validation/options.js b/packages/babel-core/src/config/validation/options.js index bd7a4ffe66..e0e855d720 100644 --- a/packages/babel-core/src/config/validation/options.js +++ b/packages/babel-core/src/config/validation/options.js @@ -119,9 +119,6 @@ const COMMON_VALIDATORS: ValidatorSet = { sourceMap: (assertSourceMaps: Validator< $PropertyType, >), - sourceMapTarget: (assertString: Validator< - $PropertyType, - >), sourceFileName: (assertString: Validator< $PropertyType, >), @@ -192,7 +189,6 @@ export type ValidatedOptions = { // Sourcemap generation options. sourceMaps?: SourceMapsOption, sourceMap?: SourceMapsOption, - sourceMapTarget?: string, sourceFileName?: string, sourceRoot?: string, diff --git a/packages/babel-core/src/config/validation/removed.js b/packages/babel-core/src/config/validation/removed.js index 09885afec3..165bc4049f 100644 --- a/packages/babel-core/src/config/validation/removed.js +++ b/packages/babel-core/src/config/validation/removed.js @@ -44,7 +44,8 @@ export default { message: "Put the specific transforms you want in the `plugins` option", }, sourceMapName: { - message: "Use the `sourceMapTarget` option", + message: + "The `sourceMapName` option has been removed because it makes more sense for the tooling that calls Babel to assign `map.file` themselves.", }, stage: { message: @@ -64,4 +65,10 @@ export default { message: "Generated plugin metadata is always included in the output result", }, + + sourceMapTarget: { + version: 6, + message: + "The `sourceMapTarget` option has been removed because it makes more sense for the tooling that calls Babel to assign `map.file` themselves.", + }, }; diff --git a/packages/babel-core/src/transformation/normalize-opts.js b/packages/babel-core/src/transformation/normalize-opts.js index f224ff01ee..6cd0f32447 100644 --- a/packages/babel-core/src/transformation/normalize-opts.js +++ b/packages/babel-core/src/transformation/normalize-opts.js @@ -15,7 +15,6 @@ export default function normalizeOptions(config: ResolvedConfig): {} { sourceRoot = moduleRoot, sourceFileName = filenameRelative, - sourceMapTarget = filenameRelative, comments = true, compact = "auto", @@ -47,7 +46,6 @@ export default function normalizeOptions(config: ResolvedConfig): {} { // Source-map generation flags. sourceMaps, - sourceMapTarget, sourceRoot, sourceFileName, }, diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json b/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json index 93aa0c2509..77952227ea 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json +++ b/packages/babel-core/test/fixtures/transformation/source-maps/full/source-map.json @@ -1,6 +1,5 @@ { "version": 3, - "file": "source-maps/full/output.js", "sources": ["source-maps/full/input.js"], "names": [ "arr", diff --git a/packages/babel-core/test/fixtures/transformation/source-maps/inline/output.js b/packages/babel-core/test/fixtures/transformation/source-maps/inline/output.js index d297120507..4d7c7ba70f 100644 --- a/packages/babel-core/test/fixtures/transformation/source-maps/inline/output.js +++ b/packages/babel-core/test/fixtures/transformation/source-maps/inline/output.js @@ -1,4 +1,4 @@ arr.map(function (x) { return x * x; }); -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9pbnB1dC5qcyJdLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4Il0sIm1hcHBpbmdzIjoiQUFBQUEsSUFBSUMsR0FBSixDQUFRO0FBQUEsU0FBS0MsSUFBSUEsQ0FBVDtBQUFBLENBQVIiLCJmaWxlIjoic291cmNlLW1hcHMvaW5saW5lL291dHB1dC5qcyIsInNvdXJjZXNDb250ZW50IjpbImFyci5tYXAoeCA9PiB4ICogeCk7Il19 +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS1tYXBzL2lubGluZS9pbnB1dC5qcyJdLCJuYW1lcyI6WyJhcnIiLCJtYXAiLCJ4Il0sIm1hcHBpbmdzIjoiQUFBQUEsSUFBSUMsR0FBSixDQUFRO0FBQUEsU0FBS0MsSUFBSUEsQ0FBVDtBQUFBLENBQVIiLCJzb3VyY2VzQ29udGVudCI6WyJhcnIubWFwKHggPT4geCAqIHgpOyJdfQ== diff --git a/packages/babel-generator/README.md b/packages/babel-generator/README.md index bc847715d0..44725b6047 100644 --- a/packages/babel-generator/README.md +++ b/packages/babel-generator/README.md @@ -43,7 +43,6 @@ Options for source maps: name | type | default | description -----------------------|----------|-----------------|-------------------------------------------------------------------------- sourceMaps | boolean | `false` | Enable generating source maps -sourceMapTarget | string | | The filename of the generated code that the source map will be associated with sourceRoot | string | | A root for all relative URLs in the source map sourceFileName | string | | The filename for the source code (i.e. the code in the `code` argument). This will only be used if `code` is a string. diff --git a/packages/babel-generator/src/source-map.js b/packages/babel-generator/src/source-map.js index c2a4164282..cbdbe8af89 100644 --- a/packages/babel-generator/src/source-map.js +++ b/packages/babel-generator/src/source-map.js @@ -19,7 +19,6 @@ export default class SourceMap { get() { if (!this._cachedMap) { const map = (this._cachedMap = new sourceMap.SourceMapGenerator({ - file: this._opts.sourceMapTarget, sourceRoot: this._opts.sourceRoot, })); diff --git a/packages/babel-helper-transform-fixture-test-runner/src/index.js b/packages/babel-helper-transform-fixture-test-runner/src/index.js index 03dda4511e..76eaacc36e 100644 --- a/packages/babel-helper-transform-fixture-test-runner/src/index.js +++ b/packages/babel-helper-transform-fixture-test-runner/src/index.js @@ -382,15 +382,7 @@ function run(task) { let actualCode = actual.code; const expectCode = expected.code; if (!execCode || actualCode) { - result = babel.transform( - actualCode, - Object.assign( - { - sourceMapTarget: task.expect.filename, - }, - getOpts(actual), - ), - ); + result = babel.transform(actualCode, getOpts(actual)); checkDuplicatedNodes(result.ast); if ( !expected.code &&