diff --git a/packages/vue-cli-plugin-uni/lib/format-log.js b/packages/vue-cli-plugin-uni/lib/format-log.js index 0f57cb04e46c4f142df04ee0ce066dbbd975268b..711c0af385a889ad430b66a14cc6e0d5c7a01e0b 100644 --- a/packages/vue-cli-plugin-uni/lib/format-log.js +++ b/packages/vue-cli-plugin-uni/lib/format-log.js @@ -1,11 +1,16 @@ function typof (v) { - const s = Object.prototype.toString.call(v) + var s = Object.prototype.toString.call(v) return s.substring(8, s.length - 1) } -export default function formatLog (...args) { - const msgs = args.map((v) => { - const type = Object.prototype.toString.call(v) +export default function formatLog () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key] + } + + var msgs = args.map(function (v) { + var type = Object.prototype.toString.call(v) + if (type.toLowerCase() === '[object object]') { try { v = '---BEGIN:JSON---' + JSON.stringify(v) + '---END:JSON---' @@ -18,7 +23,8 @@ export default function formatLog (...args) { } else if (v === undefined) { v = '---UNDEFINED---' } else { - const vType = typof(v).toUpperCase() + var vType = typof(v).toUpperCase() + if (vType === 'NUMBER' || vType === 'BOOLEAN') { v = '---BEGIN:' + vType + '---' + v + '---END:' + vType + '---' } else { @@ -26,12 +32,15 @@ export default function formatLog (...args) { } } } + return v }) - let msg = '' + var msg = '' + if (msgs.length > 1) { - const lastMsg = msgs.pop() + var lastMsg = msgs.pop() msg = msgs.join('---COMMA---') + if (lastMsg.indexOf(' at ') === 0) { msg += lastMsg } else { @@ -40,5 +49,6 @@ export default function formatLog (...args) { } else { msg = msgs[0] } + return msg }