Skip to content

Commit

Permalink
repl: remove magic mode semantics
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
TimothyGu committed Mar 7, 2017
1 parent 60c8115 commit b77c890
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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, {
Expand All @@ -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
Expand Down

0 comments on commit b77c890

Please sign in to comment.