From b77c89022b5eaa8204e7957ea49290cd0ed6aac2 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Mon, 27 Feb 2017 17:57:44 -0800 Subject: [PATCH] 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 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Prince John Wesley --- lib/repl.js | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 60b68dc05b4c6a..3db04b7718ab20 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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