Permalink
Browse files

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: #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>
  • Loading branch information...
TimothyGu committed Feb 28, 2017
1 parent 60c8115 commit b77c89022b5eaa8204e7957ea49290cd0ed6aac2
Showing with 8 additions and 19 deletions.
  1. +8 −19 lib/repl.js
View
@@ -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

0 comments on commit b77c890

Please sign in to comment.