repl: remove magic mode semantics

The workaround used in repl to support `let` and `const` in non-strict
mode (known as "magic" mode) has been unnecessary since V8 v4.9 /
Node.js v6.0.0. This commit functionally removes this workaround.

PR-URL: https://github.com/nodejs/node/pull/11599
Refs: https://v8project.blogspot.com/2016/01/v8-release-49.html
Refs: https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V6.md#6.0.0
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
This commit is contained in:
Timothy Gu 2017-02-27 17:57:44 -08:00
Родитель 60c8115f63
Коммит b77c89022b
1 изменённых файлов: 8 добавлений и 19 удалений

Просмотреть файл

@ -78,10 +78,6 @@ exports.writer = util.inspect;
exports._builtinLibs = internalModule.builtinLibs;
const BLOCK_SCOPED_ERROR = 'Block-scoped declarations (let, const, function, ' +
'class) not yet supported outside strict mode';
class LineParser {
constructor() {
@ -266,7 +262,6 @@ function REPLServer(prompt,
code = code.replace(/\n$/, '');
code = preprocess(code);
var retry = false;
var input = code;
var err, result, wrappedErr;
// first, create the Script object to check the syntax
@ -277,9 +272,9 @@ function REPLServer(prompt,
while (true) {
try {
if (!/^\s*$/.test(code) &&
(self.replMode === exports.REPL_MODE_STRICT || retry)) {
// "void 0" keeps the repl from returning "use strict" as the
// result value for let/const statements.
self.replMode === exports.REPL_MODE_STRICT) {
// "void 0" keeps the repl from returning "use strict" as the result
// value for statements and declarations that don't return a value.
code = `'use strict'; void 0;\n${code}`;
}
var script = vm.createScript(code, {
@ -288,17 +283,11 @@ function REPLServer(prompt,
});
} catch (e) {
debug('parse error %j', code, e);
if (self.replMode === exports.REPL_MODE_MAGIC &&
e.message === BLOCK_SCOPED_ERROR &&
!retry || self.wrappedCmd) {
if (self.wrappedCmd) {
self.wrappedCmd = false;
// unwrap and try again
code = `${input.substring(1, input.length - 2)}\n`;
wrappedErr = e;
} else {
retry = true;
}
if (self.wrappedCmd) {
self.wrappedCmd = false;
// unwrap and try again
code = `${input.substring(1, input.length - 2)}\n`;
wrappedErr = e;
continue;
}
// preserve original error for wrapped command