Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
repl: remove usage of require('util') in repl.js
Use `require('internal/util/inspect').inspect` and 
`require('internal/util/debuglog').debuglog` instead of
`require('util').inspect` and `require('util').debuglog`.

Refs: #26546
  • Loading branch information
dnlup committed Mar 26, 2019
commit ed2495647ce6326f70ca2c44da99a436eb3ae135
44 changes: 25 additions & 19 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ const {
isIdentifierStart,
isIdentifierChar
} = require('internal/deps/acorn/acorn/dist/acorn');
const internalUtil = require('internal/util');
const util = require('util');
const {
decorateErrorStack,
isError,
deprecate
} = require('internal/util');
const { inspect } = require('internal/util/inspect');
const Stream = require('stream');
const vm = require('vm');
const path = require('path');
Expand All @@ -61,7 +65,7 @@ const { Interface } = require('readline');
const { Console } = require('console');
const CJSModule = require('internal/modules/cjs/loader');
const domain = require('domain');
const debug = util.debuglog('repl');
const debug = require('internal/util/debuglog').debuglog('repl');
const {
ERR_CANNOT_WATCH_SIGINT,
ERR_INVALID_ARG_TYPE,
Expand Down Expand Up @@ -120,8 +124,8 @@ function hasOwnProperty(obj, prop) {
// This is the default "writer" value, if none is passed in the REPL options,
// and it can be overridden by custom print functions, such as `probe` or
// `eyes.js`.
const writer = exports.writer = (obj) => util.inspect(obj, writer.options);
writer.options = { ...util.inspect.defaultOptions, showProxy: true };
const writer = exports.writer = (obj) => inspect(obj, writer.options);
writer.options = { ...inspect.defaultOptions, showProxy: true };

exports._builtinLibs = builtinLibs;

Expand Down Expand Up @@ -204,10 +208,10 @@ function REPLServer(prompt,

let rli = this;
Object.defineProperty(this, 'rli', {
get: util.deprecate(() => rli,
'REPLServer.rli is deprecated', 'DEP0124'),
set: util.deprecate((val) => rli = val,
'REPLServer.rli is deprecated', 'DEP0124'),
get: deprecate(() => rli,
'REPLServer.rli is deprecated', 'DEP0124'),
set: deprecate((val) => rli = val,
'REPLServer.rli is deprecated', 'DEP0124'),
enumerable: true,
configurable: true
});
Expand Down Expand Up @@ -430,15 +434,15 @@ function REPLServer(prompt,
if (typeof e === 'object' && e !== null) {
const pstrace = Error.prepareStackTrace;
Error.prepareStackTrace = prepareStackTrace(pstrace);
internalUtil.decorateErrorStack(e);
decorateErrorStack(e);
Error.prepareStackTrace = pstrace;

if (e.domainThrown) {
delete e.domain;
delete e.domainThrown;
}

if (internalUtil.isError(e)) {
if (isError(e)) {
if (e.stack) {
if (e.name === 'SyntaxError') {
// Remove stack trace.
Expand Down Expand Up @@ -482,10 +486,12 @@ function REPLServer(prompt,

self.clearBufferedCommand();
Object.defineProperty(this, 'bufferedCommand', {
get: util.deprecate(() => self[kBufferedCommandSymbol],
'REPLServer.bufferedCommand is deprecated', 'DEP0074'),
set: util.deprecate((val) => self[kBufferedCommandSymbol] = val,
'REPLServer.bufferedCommand is deprecated', 'DEP0074'),
get: deprecate(() => self[kBufferedCommandSymbol],
'REPLServer.bufferedCommand is deprecated',
'DEP0074'),
set: deprecate((val) => self[kBufferedCommandSymbol] = val,
'REPLServer.bufferedCommand is deprecated',
'DEP0074'),
enumerable: true
});

Expand Down Expand Up @@ -518,7 +524,7 @@ function REPLServer(prompt,
writer.options.colors = self.useColors;

if (options[kStandaloneREPL]) {
Object.defineProperty(util.inspect, 'replDefaults', {
Object.defineProperty(inspect, 'replDefaults', {
get() {
return writer.options;
},
Expand Down Expand Up @@ -567,7 +573,7 @@ function REPLServer(prompt,
return false;
}

self.parseREPLKeyword = util.deprecate(
self.parseREPLKeyword = deprecate(
_parseREPLKeyword,
'REPLServer.parseREPLKeyword() is deprecated',
'DEP0075');
Expand Down Expand Up @@ -924,7 +930,7 @@ REPLServer.prototype.setPrompt = function setPrompt(prompt) {
Interface.prototype.setPrompt.call(this, prompt);
};

REPLServer.prototype.turnOffEditorMode = util.deprecate(
REPLServer.prototype.turnOffEditorMode = deprecate(
function() { _turnOffEditorMode(this); },
'REPLServer.turnOffEditorMode() is deprecated',
'DEP0078');
Expand Down Expand Up @@ -1315,7 +1321,7 @@ REPLServer.prototype.defineCommand = function(keyword, cmd) {
this.commands[keyword] = cmd;
};

REPLServer.prototype.memory = util.deprecate(
REPLServer.prototype.memory = deprecate(
_memory,
'REPLServer.memory() is deprecated',
'DEP0082');
Expand Down