Skip to content

Commit 6757dd2

Browse files
spzmAkryum
authored andcommitted
fix: custom function details parsing when argument is specific Proxy function (#709)
1 parent 43210a2 commit 6757dd2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/util.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,22 @@ export function getCustomComponentDefinitionDetails (def) {
249249

250250
export function getCustomFunctionDetails (func) {
251251
let string = ''
252+
let matches = null
252253
try {
253254
string = Function.prototype.toString.call(func)
255+
matches = String.prototype.match.call(string, /\([\s\S]*?\)/)
254256
} catch (e) {
255257
// Func is probably a Proxy, which can break Function.prototype.toString()
256258
}
257-
const matches = string.match(/\([\s\S]*?\)/)
258259
// Trim any excess whitespace from the argument string
259-
const args = matches ? `(${matches[0].substr(1, matches[0].length - 2).split(',').map(a => a.trim()).join(', ')})` : '(?)'
260+
const match = matches && matches[0]
261+
const args = typeof match === 'string'
262+
? `(${match.substr(1, match.length - 2).split(',').map(a => a.trim()).join(', ')})` : '(?)'
263+
const name = typeof func.name === 'string' ? func.name : ''
260264
return {
261265
_custom: {
262266
type: 'function',
263-
display: `<span>ƒ</span> ${escape(func.name)}${args}`
267+
display: `<span>ƒ</span> ${escape(name)}${args}`
264268
}
265269
}
266270
}

0 commit comments

Comments
 (0)