mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
* Warn when pg.Pool() isn’t called as a constructor in preparation for #1541. `eval` is a bit awkward, but it’s more accurate than an `instanceof` check and will work on platforms new enough to support pg 8 (i.e. only not Node 4). * Warn when Query() isn’t called as a constructor
23 lines
537 B
JavaScript
23 lines
537 B
JavaScript
'use strict'
|
||
|
||
const warnDeprecation = require('./warn-deprecation')
|
||
|
||
// Node 4 doesn’t support new.target.
|
||
let hasNewTarget
|
||
|
||
try {
|
||
// eslint-disable-next-line no-eval
|
||
eval('(function () { new.target })')
|
||
hasNewTarget = true
|
||
} catch (error) {
|
||
hasNewTarget = false
|
||
}
|
||
|
||
const checkConstructor = (name, code, getNewTarget) => {
|
||
if (hasNewTarget && getNewTarget() === undefined) {
|
||
warnDeprecation(`Constructing a ${name} without new is deprecated and will stop working in pg 8.`, code)
|
||
}
|
||
}
|
||
|
||
module.exports = checkConstructor
|