Skip to content

Commit

Permalink
repl: add trailing commas in source files
Browse files Browse the repository at this point in the history
PR-URL: #46757
Reviewed-By: Deokjin Kim <deokjin81.kim@gmail.com>
Reviewed-By: Qingyu Deng <i@ayase-lab.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
aduh95 authored and targos committed Mar 13, 2023
1 parent 58b1f33 commit 4f2bf8c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 41 deletions.
4 changes: 3 additions & 1 deletion lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ overrides:
- ./internal/process/*.js
- ./internal/readline/*.js
- ./internal/readme.md
- ./internal/repl/history.js
- ./internal/repl.js
- ./internal/repl/*.js
- ./internal/source_map/prepare_stack_trace.js
- ./internal/streams/*.js
- ./internal/structured_clone.js
Expand All @@ -310,6 +311,7 @@ overrides:
- ./path/*.js
- ./process.js
- ./punycode.js
- ./repl.js
- ./stream/*.js
- ./sys.js
- ./test.js
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function createRepl(env, opts, cb) {
ignoreUndefined: false,
useGlobal: true,
breakEvalOnSigint: true,
...opts
...opts,
};

if (NumberParseInt(env.NODE_NO_READLINE)) {
Expand All @@ -32,7 +32,7 @@ function createRepl(env, opts, cb) {
if (env.NODE_REPL_MODE) {
opts.replMode = {
'strict': REPL.REPL_MODE_STRICT,
'sloppy': REPL.REPL_MODE_SLOPPY
'sloppy': REPL.REPL_MODE_SLOPPY,
}[env.NODE_REPL_MODE.toLowerCase().trim()];
}

Expand Down
6 changes: 3 additions & 3 deletions lib/internal/repl/await.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const visitorsWithoutAncestors = {
}

walk.base.VariableDeclaration(node, state, c);
}
},
};

const visitors = {};
Expand Down Expand Up @@ -209,7 +209,7 @@ function processTopLevelAwait(src) {
wrappedArray[node.end - 1] += str;
},
containsAwait: false,
containsReturn: false
containsReturn: false,
};

walk.recursive(body, state, visitors);
Expand Down Expand Up @@ -258,5 +258,5 @@ function processTopLevelAwait(src) {
}

module.exports = {
processTopLevelAwait
processTopLevelAwait,
};
12 changes: 6 additions & 6 deletions lib/internal/repl/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const { tokTypes: tt, Parser: AcornParser } =
const { sendInspectorCommand } = require('internal/util/inspector');

const {
ERR_INSPECTOR_NOT_AVAILABLE
ERR_INSPECTOR_NOT_AVAILABLE,
} = require('internal/errors').codes;

const {
Expand All @@ -54,7 +54,7 @@ let debug = require('internal/util/debuglog').debuglog('repl', (fn) => {
const previewOptions = {
colors: false,
depth: 1,
showHidden: false
showHidden: false,
};

const REPL_MODE_STRICT = Symbol('repl-strict');
Expand Down Expand Up @@ -340,7 +340,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
colors: false,
depth: 1,
compact: true,
breakLength: Infinity
breakLength: Infinity,
}, previewOptions);
session.post('Runtime.callFunctionOn', {
functionDeclaration:
Expand All @@ -349,7 +349,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
.getOwnPropertyDescriptor(globalThis, 'util')
.get().inspect(v, ${inspectOptions})`,
objectId: result.objectId,
arguments: [result]
arguments: [result],
}, (error, preview) => {
if (error) {
callback(error);
Expand Down Expand Up @@ -520,7 +520,7 @@ function setupReverseSearch(repl) {
const alreadyMatched = new SafeSet();
const labels = {
r: 'bck-i-search: ',
s: 'fwd-i-search: '
s: 'fwd-i-search: ',
};
let isInReverseSearch = false;
let historyIndex = -1;
Expand Down Expand Up @@ -749,5 +749,5 @@ module.exports = {
isRecoverableError,
kStandaloneREPL: Symbol('kStandaloneREPL'),
setupPreview,
setupReverseSearch
setupReverseSearch,
};
58 changes: 29 additions & 29 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ const {
const { BuiltinModule } = require('internal/bootstrap/loaders');
const {
makeRequireFunction,
addBuiltinLibsToObject
addBuiltinLibsToObject,
} = require('internal/modules/helpers');
const {
isIdentifierStart,
isIdentifierChar
isIdentifierChar,
} = require('internal/deps/acorn/acorn/dist/acorn');
const {
decorateErrorStack,
Expand All @@ -118,7 +118,7 @@ const path = require('path');
const fs = require('fs');
const { Interface } = require('readline');
const {
commonPrefix
commonPrefix,
} = require('internal/readline/utils');
const { Console } = require('console');
const CJSModule = require('internal/modules/cjs/loader').Module;
Expand Down Expand Up @@ -173,7 +173,7 @@ const {
} = internalBinding('util');
const {
startSigintWatchdog,
stopSigintWatchdog
stopSigintWatchdog,
} = internalBinding('contextify');

const history = require('internal/repl/history');
Expand Down Expand Up @@ -296,7 +296,7 @@ function REPLServer(prompt,
'DEP0141') :
(val) => this.input = val,
enumerable: false,
configurable: true
configurable: true,
});
ObjectDefineProperty(this, 'outputStream', {
__proto__: null,
Expand All @@ -313,7 +313,7 @@ function REPLServer(prompt,
'DEP0141') :
(val) => this.output = val,
enumerable: false,
configurable: true
configurable: true,
});

this.allowBlockingCompletions = !!options.allowBlockingCompletions;
Expand Down Expand Up @@ -462,7 +462,7 @@ function REPLServer(prompt,
importModuleDynamically: (specifier, _, importAssertions) => {
return asyncESM.esmLoader.import(specifier, parentURL,
importAssertions);
}
},
});
} catch (fallbackError) {
if (isRecoverableError(fallbackError, fallbackCode)) {
Expand Down Expand Up @@ -506,7 +506,7 @@ function REPLServer(prompt,
importModuleDynamically: (specifier, _, importAssertions) => {
return asyncESM.esmLoader.import(specifier, parentURL,
importAssertions);
}
},
});
} catch (e) {
debug('parse error %j', code, e);
Expand Down Expand Up @@ -563,7 +563,7 @@ function REPLServer(prompt,
try {
const scriptOptions = {
displayErrors: false,
breakOnSigint: self.breakEvalOnSigint
breakOnSigint: self.breakEvalOnSigint,
};

if (self.useGlobal) {
Expand Down Expand Up @@ -767,7 +767,7 @@ function REPLServer(prompt,
completer: options.completer || completer,
terminal: options.terminal,
historySize: options.historySize,
prompt
prompt,
}]);

self.resetContext();
Expand All @@ -793,7 +793,7 @@ function REPLServer(prompt,
return ObjectAssign(writer.options, options);
},
enumerable: true,
configurable: true
configurable: true,
});
}
}
Expand Down Expand Up @@ -967,7 +967,7 @@ function REPLServer(prompt,

const {
clearPreview,
showPreview
showPreview,
} = setupPreview(
this,
kContextId,
Expand Down Expand Up @@ -1097,7 +1097,7 @@ REPLServer.prototype.createContext = function() {
__proto__: null,
configurable: true,
writable: true,
value: _console
value: _console,
});
}

Expand All @@ -1108,13 +1108,13 @@ REPLServer.prototype.createContext = function() {
__proto__: null,
configurable: true,
writable: true,
value: replModule
value: replModule,
});
ObjectDefineProperty(context, 'require', {
__proto__: null,
configurable: true,
writable: true,
value: makeRequireFunction(replModule)
value: makeRequireFunction(replModule),
});

addBuiltinLibsToObject(context, '<REPL>');
Expand All @@ -1140,7 +1140,7 @@ REPLServer.prototype.resetContext = function() {
this.underscoreAssigned = true;
this.output.write('Expression assignment to _ now disabled.\n');
}
}
},
});

ObjectDefineProperty(this.context, '_error', {
Expand All @@ -1154,7 +1154,7 @@ REPLServer.prototype.resetContext = function() {
this.output.write(
'Expression assignment to _error now disabled.\n');
}
}
},
});

// Allow REPL extensions to extend the new context
Expand Down Expand Up @@ -1240,7 +1240,7 @@ function getGlobalLexicalScopeNames(contextId) {
return sendInspectorCommand((session) => {
let names = [];
session.post('Runtime.globalLexicalScopeNames', {
executionContextId: contextId
executionContextId: contextId,
}, (error, result) => {
if (!error) names = result.names;
});
Expand Down Expand Up @@ -1661,7 +1661,7 @@ function _memory(cmd) {
// scope will not work for this function.
ArrayPrototypePush(self.lines.level, {
line: self.lines.length - 1,
depth: depth
depth: depth,
});
} else if (depth < 0) {
// Going... up.
Expand Down Expand Up @@ -1711,7 +1711,7 @@ function defineDefaultCommands(repl) {
action: function() {
this.clearBufferedCommand();
this.displayPrompt();
}
},
});

let clearMessage;
Expand All @@ -1729,14 +1729,14 @@ function defineDefaultCommands(repl) {
this.resetContext();
}
this.displayPrompt();
}
},
});

repl.defineCommand('exit', {
help: 'Exit the REPL',
action: function() {
this.close();
}
},
});

repl.defineCommand('help', {
Expand All @@ -1756,7 +1756,7 @@ function defineDefaultCommands(repl) {
this.output.write('\nPress Ctrl+C to abort current expression, ' +
'Ctrl+D to exit the REPL\n');
this.displayPrompt();
}
},
});

repl.defineCommand('save', {
Expand All @@ -1769,7 +1769,7 @@ function defineDefaultCommands(repl) {
this.output.write(`Failed to save: ${file}\n`);
}
this.displayPrompt();
}
},
});

repl.defineCommand('load', {
Expand All @@ -1792,7 +1792,7 @@ function defineDefaultCommands(repl) {
this.output.write(`Failed to load: ${file}\n`);
}
this.displayPrompt();
}
},
});
if (repl.terminal) {
repl.defineCommand('editor', {
Expand All @@ -1801,7 +1801,7 @@ function defineDefaultCommands(repl) {
_turnOnEditorMode(this);
this.output.write(
'// Entering editor mode (Ctrl+D to finish, Ctrl+C to cancel)\n');
}
},
});
}
}
Expand All @@ -1818,15 +1818,15 @@ module.exports = {
REPLServer,
REPL_MODE_SLOPPY,
REPL_MODE_STRICT,
Recoverable
Recoverable,
};

ObjectDefineProperty(module.exports, 'builtinModules', {
__proto__: null,
get: () => _builtinLibs,
set: (val) => _builtinLibs = val,
enumerable: true,
configurable: true
configurable: true,
});

ObjectDefineProperty(module.exports, '_builtinLibs', {
Expand All @@ -1842,5 +1842,5 @@ ObjectDefineProperty(module.exports, '_builtinLibs', {
'DEP0142',
) : (val) => _builtinLibs = val,
enumerable: false,
configurable: true
configurable: true,
});

0 comments on commit 4f2bf8c

Please sign in to comment.