Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion shells/dev/target/NativeTypes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ export default {
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]])]])])]]),
html: '<b>Bold</b> <i>Italic</i>',
htmlReg: /<b>hey<\/b>/i,
'html <b>key</b>': (h, t, m, l) => {}
'html <b>key</b>': (h, t, m, l) => {},
sym: Symbol('test'),
multiLineParameterFunction: function(a,
b,
c) {}
}
},
computed: {
Expand Down
3 changes: 2 additions & 1 deletion shells/dev/target/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default new Vuex.Store({
count: 0,
date: new Date(),
set: new Set(),
map: new Map()
map: new Map(),
sym: Symbol('test')
},
mutations: {
INCREMENT: state => state.count++,
Expand Down
11 changes: 9 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ function replacer (key) {
return NEGATIVE_INFINITY
} else if (type === 'function') {
return getCustomFunctionDetails(val)
} else if (type === 'symbol') {
return `[native Symbol ${Symbol.prototype.toString.call(val)}]`
} else if (val !== null && type === 'object') {
if (val instanceof Map) {
return encodeCache.cache(val, () => getCustomMapDetails(val))
Expand Down Expand Up @@ -246,8 +248,9 @@ export function getCustomComponentDefinitionDetails (def) {

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

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

function reviver (key, val) {
if (val === UNDEFINED) {
Expand All @@ -281,6 +285,9 @@ function reviver (key, val) {
} else if (val._custom.type === 'set') {
return reviveSet(val)
}
} else if (symbolRE.test(val)) {
const [, string] = symbolRE.exec(val)
return Symbol.for(string)
} else if (specialTypeRE.test(val)) {
const [, type, string] = specialTypeRE.exec(val)
return new window[type](string)
Expand Down