Skip to content

Commit b77c890

Browse files
committed
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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Prince John Wesley <[email protected]>
1 parent 60c8115 commit b77c890

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

lib/repl.js

+8-19
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ exports.writer = util.inspect;
7878
exports._builtinLibs = internalModule.builtinLibs;
7979

8080

81-
const BLOCK_SCOPED_ERROR = 'Block-scoped declarations (let, const, function, ' +
82-
'class) not yet supported outside strict mode';
83-
84-
8581
class LineParser {
8682

8783
constructor() {
@@ -266,7 +262,6 @@ function REPLServer(prompt,
266262
code = code.replace(/\n$/, '');
267263
code = preprocess(code);
268264

269-
var retry = false;
270265
var input = code;
271266
var err, result, wrappedErr;
272267
// first, create the Script object to check the syntax
@@ -277,9 +272,9 @@ function REPLServer(prompt,
277272
while (true) {
278273
try {
279274
if (!/^\s*$/.test(code) &&
280-
(self.replMode === exports.REPL_MODE_STRICT || retry)) {
281-
// "void 0" keeps the repl from returning "use strict" as the
282-
// result value for let/const statements.
275+
self.replMode === exports.REPL_MODE_STRICT) {
276+
// "void 0" keeps the repl from returning "use strict" as the result
277+
// value for statements and declarations that don't return a value.
283278
code = `'use strict'; void 0;\n${code}`;
284279
}
285280
var script = vm.createScript(code, {
@@ -288,17 +283,11 @@ function REPLServer(prompt,
288283
});
289284
} catch (e) {
290285
debug('parse error %j', code, e);
291-
if (self.replMode === exports.REPL_MODE_MAGIC &&
292-
e.message === BLOCK_SCOPED_ERROR &&
293-
!retry || self.wrappedCmd) {
294-
if (self.wrappedCmd) {
295-
self.wrappedCmd = false;
296-
// unwrap and try again
297-
code = `${input.substring(1, input.length - 2)}\n`;
298-
wrappedErr = e;
299-
} else {
300-
retry = true;
301-
}
286+
if (self.wrappedCmd) {
287+
self.wrappedCmd = false;
288+
// unwrap and try again
289+
code = `${input.substring(1, input.length - 2)}\n`;
290+
wrappedErr = e;
302291
continue;
303292
}
304293
// preserve original error for wrapped command

0 commit comments

Comments
 (0)