Skip to content

Commit 24749d4

Browse files
author
Guillaume Chau
committed
Merge branch 'symbols-and-functions'
2 parents 34acfbd + f8ff617 commit 24749d4

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
@@ -93,7 +93,11 @@ export default {
9393
html: '<b>Bold</b> <i>Italic</i>',
9494
htmlReg: /<b>hey<\/b>/i,
9595
'html <b>key</b>': (h, t, m, l) => {},
96-
proxy1
96+
proxy1,
97+
sym: Symbol('test'),
98+
multiLineParameterFunction: function(a,
99+
b,
100+
c) {}
97101
}
98102
},
99103
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))
@@ -251,8 +253,9 @@ export function getCustomFunctionDetails (func) {
251253
} catch (e) {
252254
// Func is probably a Proxy, which can break Function.prototype.toString()
253255
}
254-
const matches = string.match(/\(.*\)/)
255-
const args = matches ? matches[0] : '(?)'
256+
const matches = string.match(/\([\s\S]*?\)/)
257+
// Trim any excess whitespace from the argument string
258+
const args = matches ? `(${matches[0].substr(1, matches[0].length - 2).split(',').map(a => a.trim()).join(', ')})` : '(?)'
256259
return {
257260
_custom: {
258261
type: 'function',
@@ -268,6 +271,7 @@ export function parse (data, revive) {
268271
}
269272

270273
const specialTypeRE = /^\[native (\w+) (.*)\]$/
274+
const symbolRE = /^\[native Symbol Symbol\((.*)\)\]$/
271275

272276
function reviver (key, val) {
273277
if (val === UNDEFINED) {
@@ -286,6 +290,9 @@ function reviver (key, val) {
286290
} else if (val._custom.type === 'set') {
287291
return reviveSet(val)
288292
}
293+
} else if (symbolRE.test(val)) {
294+
const [, string] = symbolRE.exec(val)
295+
return Symbol.for(string)
289296
} else if (specialTypeRE.test(val)) {
290297
const [, type, string] = specialTypeRE.exec(val)
291298
return new window[type](string)

0 commit comments

Comments
 (0)