Skip to content

Commit

Permalink
Replace the is-plain-obj dependency
Browse files Browse the repository at this point in the history
It does some checks that we don’t need. Just checking the prototype is
sufficient.
  • Loading branch information
remcohaszing committed May 7, 2024
1 parent 63f5936 commit c01d1fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"test": "c8 node --enable-source-maps dist/test.js"
},
"dependencies": {
"@types/estree": "^1.0.0",
"is-plain-obj": "^4.0.0"
"@types/estree": "^1.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
Expand Down
10 changes: 6 additions & 4 deletions src/estree-util-value-to-estree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
type SimpleLiteral,
type VariableDeclarator
} from 'estree'
import isPlainObject from 'is-plain-obj'

/**
* Create an ESTree identifier node for a given name.
Expand Down Expand Up @@ -364,12 +363,15 @@ export function valueToEstree(value: unknown, options: Options = {}): Expression
for (const entry of val) {
analyze(entry)
}
} else if (options.instanceAsObject || isPlainObject(val)) {
} else {
const proto = Object.getPrototypeOf(val)
if (proto != null && proto !== Object.prototype && !options.instanceAsObject) {
throw new TypeError(`Unsupported value: ${val}`, { cause: val })
}

for (const key of Reflect.ownKeys(val)) {
analyze((val as Record<string | symbol, unknown>)[key])
}
} else {
throw new TypeError(`Unsupported value: ${val}`, { cause: val })
}
stack.pop()
}
Expand Down

0 comments on commit c01d1fb

Please sign in to comment.