Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn when Query() isn’t called as a constructor
- Loading branch information
1 parent
deebe7d
commit dbe46c7
Showing
4 changed files
with
47 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict' | ||
|
||
const { deprecate } = require('util') | ||
|
||
const dummyFunctions = new Map() | ||
|
||
// Node 4 doesn’t support process.emitWarning(message, 'DeprecationWarning', code). | ||
const emitDeprecationWarning = (message, code) => { | ||
let dummy = dummyFunctions.get(code) | ||
|
||
if (dummy === undefined) { | ||
dummy = deprecate(() => {}, message) | ||
dummyFunctions.set(code, dummy) | ||
} | ||
|
||
dummy() | ||
} | ||
|
||
module.exports = emitDeprecationWarning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters