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

chore(sourcemap): convert inputSourceMap to plain js object #272

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions src/index.js
Expand Up @@ -15,6 +15,20 @@ function getRealpath (n) {
}
}

function isPlainObject(value) {
if (
typeof value !== "object" ||
Object.prototype.toString.call(value) !== "[object Object]"
) {
return false
}
const proto = Object.getPrototypeOf(value)
// Object.prototype's __proto__ is null. Every other class's __proto__.__proto__ is
// not null by default. We cannot check if proto === Object.prototype because it
// could come from another realm.
return proto === null || Object.getPrototypeOf(proto) === null
}

const memoize = new Map()
/* istanbul ignore next */
const memosep = path.sep === '/' ? ':' : ';'
Expand Down Expand Up @@ -113,6 +127,9 @@ export default declare(api => {
if (this.opts.useInlineSourceMaps !== false) {
if (!inputSourceMap && this.file.inputMap) {
inputSourceMap = this.file.inputMap.sourcemap
if (!isPlainObject(sourceMapFromFile)) {
inputSourceMap = {...inputSourceMap};
}
}
}
const visitorOptions = {}
Expand Down