Skip to content

Commit f8ff617

Browse files
author
Connor Pearson
committed
improve the display of symbols and functions
1 parent e7b80e1 commit f8ff617

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

shells/dev/target/NativeTypes.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ export default {
7979
j: new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])], [8, new Set([1, 2, 3, 4, new Set([5, 6, 7, 8]), new Map([[1, 2], [3, 4], [5, new Map([[6, 7]])]])])]]),
8080
html: '<b>Bold</b> <i>Italic</i>',
8181
htmlReg: /<b>hey<\/b>/i,
82-
'html <b>key</b>': (h, t, m, l) => {}
82+
'html <b>key</b>': (h, t, m, l) => {},
83+
sym: Symbol('test'),
84+
multiLineParameterFunction: function(a,
85+
b,
86+
c) {}
8387
}
8488
},
8589
computed: {

shells/dev/target/store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export default new Vuex.Store({
88
count: 0,
99
date: new Date(),
1010
set: new Set(),
11-
map: new Map()
11+
map: new Map(),
12+
sym: Symbol('test')
1213
},
1314
mutations: {
1415
INCREMENT: state => state.count++,

src/util.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ function replacer (key) {
125125
return NEGATIVE_INFINITY
126126
} else if (type === 'function') {
127127
return getCustomFunctionDetails(val)
128+
} else if (type === 'symbol') {
129+
return `[native Symbol ${Symbol.prototype.toString.call(val)}]`
128130
} else if (val !== null && type === 'object') {
129131
if (val instanceof Map) {
130132
return encodeCache.cache(val, () => getCustomMapDetails(val))
@@ -246,8 +248,9 @@ export function getCustomComponentDefinitionDetails (def) {
246248

247249
export function getCustomFunctionDetails (func) {
248250
const string = Function.prototype.toString.call(func) || ''
249-
const matches = string.match(/\(.*\)/)
250-
const args = matches ? matches[0] : '(?)'
251+
const matches = string.match(/\([\s\S]*?\)/)
252+
// Trim any excess whitespace from the argument string
253+
const args = matches ? `(${matches[0].substr(1, matches[0].length - 2).split(',').map(a => a.trim()).join(', ')})` : '(?)'
251254
return {
252255
_custom: {
253256
type: 'function',
@@ -263,6 +266,7 @@ export function parse (data, revive) {
263266
}
264267

265268
const specialTypeRE = /^\[native (\w+) (.*)\]$/
269+
const symbolRE = /^\[native Symbol Symbol\((.*)\)\]$/
266270

267271
function reviver (key, val) {
268272
if (val === UNDEFINED) {
@@ -281,6 +285,9 @@ function reviver (key, val) {
281285
} else if (val._custom.type === 'set') {
282286
return reviveSet(val)
283287
}
288+
} else if (symbolRE.test(val)) {
289+
const [, string] = symbolRE.exec(val)
290+
return Symbol.for(string)
284291
} else if (specialTypeRE.test(val)) {
285292
const [, type, string] = specialTypeRE.exec(val)
286293
return new window[type](string)

0 commit comments

Comments
 (0)