| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ff9ef89 commit 97d0817
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,8 @@ const Console = require('console').Console; | |||
| 32 | 32 | const domain = require('domain'); | |
| 33 | 33 | const debug = util.debuglog('repl'); | |
| 34 | 34 | ||
| 35 | + const replMap = new WeakMap(); | ||
| 36 | + | ||
| 35 | 37 | try { | |
| 36 | 38 | // hack for require.resolve("./relative") to work properly. | |
| 37 | 39 | module.filename = path.resolve('repl'); | |
@@ -189,11 +191,12 @@ function REPLServer(prompt, | |||
| 189 | 191 | ||
| 190 | 192 | self._domain.on('error', function(e) { | |
| 191 | 193 | debug('domain error'); | |
| 192 | - self.outputStream.write((e.stack || e) + '\n'); | ||
| 193 | - self._currentStringLiteral = null; | ||
| 194 | - self.bufferedCommand = ''; | ||
| 195 | - self.lines.level = []; | ||
| 196 | - self.displayPrompt(); | ||
| 194 | + const top = replMap.get(self); | ||
| 195 | + top.outputStream.write((e.stack || e) + '\n'); | ||
| 196 | + top._currentStringLiteral = null; | ||
| 197 | + top.bufferedCommand = ''; | ||
| 198 | + top.lines.level = []; | ||
| 199 | + top.displayPrompt(); | ||
| 197 | 200 | }); | |
| 198 | 201 | ||
| 199 | 202 | if (!input && !output) { | |
@@ -472,6 +475,7 @@ exports.start = function(prompt, | |||
| 472 | 475 | ignoreUndefined, | |
| 473 | 476 | replMode); | |
| 474 | 477 | if (!exports.repl) exports.repl = repl; | |
| 478 | + replMap.set(repl, repl); | ||
| 475 | 479 | return repl; | |
| 476 | 480 | }; | |
| 477 | 481 | ||
@@ -601,6 +605,7 @@ REPLServer.prototype.complete = function(line, callback) { | |||
| 601 | 605 | // all this is only profitable if the nested REPL | |
| 602 | 606 | // does not have a bufferedCommand | |
| 603 | 607 | if (!magic.bufferedCommand) { | |
| 608 | + replMap.set(magic, replMap.get(this)); | ||
| 604 | 609 | return magic.complete(line, callback); | |
| 605 | 610 | } | |
| 606 | 611 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,41 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const util = require('util'); | ||
| 6 | + const repl = require('repl'); | ||
| 7 | + | ||
| 8 | + var referenceErrorCount = 0; | ||
| 9 | + | ||
| 10 | + // A stream to push an array into a REPL | ||
| 11 | + function ArrayStream() { | ||
| 12 | + this.run = function(data) { | ||
| 13 | + const self = this; | ||
| 14 | + data.forEach(function(line) { | ||
| 15 | + self.emit('data', line + '\n'); | ||
| 16 | + }); | ||
| 17 | + }; | ||
| 18 | + } | ||
| 19 | + util.inherits(ArrayStream, require('stream').Stream); | ||
| 20 | + ArrayStream.prototype.readable = true; | ||
| 21 | + ArrayStream.prototype.writable = true; | ||
| 22 | + ArrayStream.prototype.resume = function() {}; | ||
| 23 | + ArrayStream.prototype.write = function(msg) { | ||
| 24 | + if (msg.startsWith('ReferenceError: ')) { | ||
| 25 | + referenceErrorCount++; | ||
| 26 | + } | ||
| 27 | + }; | ||
| 28 | + | ||
| 29 | + const putIn = new ArrayStream(); | ||
| 30 | + const testMe = repl.start('', putIn); | ||
| 31 | + | ||
| 32 | + // https://github.com/nodejs/node/issues/3346 | ||
| 33 | + // Tab-completion for an undefined variable inside a function should report a | ||
| 34 | + // ReferenceError. | ||
| 35 | + putIn.run(['.clear']); | ||
| 36 | + putIn.run(['function () {']); | ||
| 37 | + testMe.complete('arguments.'); | ||
| 38 | + | ||
| 39 | + process.on('exit', function() { | ||
| 40 | + assert.strictEqual(referenceErrorCount, 1); | ||
| 41 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments