feat: warn if deprecated property is already set
This commit is contained in:
parent
61fac1bbc1
commit
2275625e1a
2 changed files with 32 additions and 10 deletions
|
@ -90,21 +90,27 @@ deprecate.getHandler = () => deprecationHandler
|
|||
|
||||
// Deprecate the old name of a property
|
||||
deprecate.property = (object, deprecatedName, newName) => {
|
||||
let warned = false
|
||||
let warn = () => {
|
||||
if (!(warned || process.noDeprecation)) {
|
||||
warned = true
|
||||
deprecate.warn(deprecatedName, newName)
|
||||
}
|
||||
}
|
||||
|
||||
if ((typeof object[newName] === 'undefined') &&
|
||||
(typeof object[deprecatedName] !== 'undefined')) {
|
||||
warn()
|
||||
object[newName] = object[deprecatedName]
|
||||
}
|
||||
|
||||
return Object.defineProperty(object, deprecatedName, {
|
||||
get: function () {
|
||||
let warned = false
|
||||
if (!(warned || process.noDeprecation)) {
|
||||
warned = true
|
||||
deprecate.warn(deprecatedName, newName)
|
||||
}
|
||||
warn()
|
||||
return this[newName]
|
||||
},
|
||||
set: function (value) {
|
||||
let warned = false
|
||||
if (!(warned || process.noDeprecation)) {
|
||||
warned = true
|
||||
deprecate.warn(deprecatedName, newName)
|
||||
}
|
||||
warn()
|
||||
this[newName] = value
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue