Skip to content

Commit f7f97f2

Browse files
committed
chore: optimize warning message
1 parent a10c88e commit f7f97f2

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/console.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
const warn = console.warn
2-
console.warn = function(...data) {
3-
const msg = data[0] || ""
4-
if (msg.startsWith("[Vue warn]: Extraneous non-props attributes (data-v-inspector-file, data-v-inspector-line, data-v-inspector-column, data-v-inspector-title)")) return
2+
console.warn = function (...data) {
3+
const skipMsgPrefix = "[Vue warn]: Extraneous non-props attributes ";
4+
let msg = data[0] || ""
5+
if (msg.startsWith(skipMsgPrefix)) {
6+
msg = msg.replace(/\([^)]+\)/, function (match) {
7+
const attributes = match
8+
.slice(1, -1)
9+
.split(', ')
10+
.filter(function (item) {
11+
return !/^data-v-inspector-(file|line|column|title)$/.test(item)
12+
})
13+
.join(', ')
14+
return '(' + attributes + ')'
15+
})
16+
if (msg.slice(skipMsgPrefix.length).startsWith('()')) return
17+
if (msg) data[0] = msg
18+
}
519
warn(...data)
620
}

0 commit comments

Comments
 (0)