Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl: docs-only deprecate magic mode #11599

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
repl: remove magic mode semantics
  • Loading branch information
TimothyGu committed Mar 1, 2017
commit 6b1d020670946259ab171a8b22d0df293dbc4f3e
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