forked from babel/babel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sourcemap plainobject for use w / valueToNode
When the sourcemaps were switched to use "@ampproject/remapping", the type of the inputSourceMap that gets passed around changed from being a plain js object to a `class SourceMap` fromthe remapping package. This causes issues with the @babel/types valueToNode function because that function is defined to throw for objects that aren't plain-objects. In practice I was seeing this error after upgrading babel when running code- coverage, and I saw a similar error reported here: vuejs/vue-jest#450 before deciding to try to track the error down myself.
- Loading branch information
Adam J. Hines
committed
Feb 17, 2022
1 parent
5c2fcad
commit 6dbb4ff
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import _mergeSourceMap from "../lib/transformation/file/merge-map.js"; | ||
const mergeSourceMap = _mergeSourceMap.default; | ||
|
||
const inputMap = { | ||
file: "file.js", | ||
mappings: [], | ||
names: [], | ||
sources: ["file.ts"], | ||
version: 3, | ||
}; | ||
|
||
const outputMap = { | ||
file: "file.transpiled.js", | ||
mappings: [], | ||
names: [], | ||
sources: ["file.js"], | ||
version: 3, | ||
}; | ||
|
||
describe("merge-map", () => { | ||
it("returns a plain js object", () => { | ||
const map = mergeSourceMap(inputMap, outputMap, "file.transpiled.js"); | ||
const proto = Object.getPrototypeOf(map) ?? Object.getPrototypeOf({}); | ||
expect(typeof map).toBe("object"); | ||
expect(Object.prototype.toString.call(map)).toBe("object [object]"); | ||
expect(Object.getPrototypeOf(proto)).toBeNull(); | ||
}); | ||
}); |