Skip to content

Commit 41b31c7

Browse files
BridgeARGeoffreyBooth
authored andcommitted
Fix repl.rli deprecation (#5178)
The `rli` property is just a reference to itself. It still exists for legacy reasons but it will likely be removed in a future major version. This makes sure everything works as expected.
1 parent ec034e2 commit 41b31c7

File tree

4 files changed

+78
-78
lines changed

4 files changed

+78
-78
lines changed

docs/v2/annotated-source/repl.html

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ <h1>repl.coffee</h1>
376376
vm.runInContext js, context, filename
377377
<span class="hljs-function">
378378
<span class="hljs-title">addMultilineHandler</span> = <span class="hljs-params">(repl)</span> -&gt;</span>
379-
{rli, inputStream, outputStream} = repl</pre></div></div>
379+
{inputStream, outputStream} = repl</pre></div></div>
380380

381381
</li>
382382

@@ -412,15 +412,15 @@ <h1>repl.coffee</h1>
412412

413413
</div>
414414

415-
<div class="content"><div class='highlight'><pre> nodeLineListener = rli.listeners(<span class="hljs-string">'line'</span>)[<span class="hljs-number">0</span>]
416-
rli.removeListener <span class="hljs-string">'line'</span>, nodeLineListener
417-
rli.<span class="hljs-literal">on</span> <span class="hljs-string">'line'</span>, <span class="hljs-function"><span class="hljs-params">(cmd)</span> -&gt;</span>
415+
<div class="content"><div class='highlight'><pre> nodeLineListener = repl.listeners(<span class="hljs-string">'line'</span>)[<span class="hljs-number">0</span>]
416+
repl.removeListener <span class="hljs-string">'line'</span>, nodeLineListener
417+
repl.<span class="hljs-literal">on</span> <span class="hljs-string">'line'</span>, <span class="hljs-function"><span class="hljs-params">(cmd)</span> -&gt;</span>
418418
<span class="hljs-keyword">if</span> multiline.enabled
419419
multiline.buffer += <span class="hljs-string">"<span class="hljs-subst">#{cmd}</span>\n"</span>
420-
rli.setPrompt multiline.prompt
421-
rli.prompt <span class="hljs-literal">true</span>
420+
repl.setPrompt multiline.prompt
421+
repl.prompt <span class="hljs-literal">true</span>
422422
<span class="hljs-keyword">else</span>
423-
rli.setPrompt origPrompt
423+
repl.setPrompt origPrompt
424424
nodeLineListener cmd
425425
<span class="hljs-keyword">return</span></pre></div></div>
426426

@@ -456,8 +456,8 @@ <h1>repl.coffee</h1>
456456

457457
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">unless</span> multiline.buffer.match <span class="hljs-regexp">/\n/</span>
458458
multiline.enabled = <span class="hljs-keyword">not</span> multiline.enabled
459-
rli.setPrompt origPrompt
460-
rli.prompt <span class="hljs-literal">true</span>
459+
repl.setPrompt origPrompt
460+
repl.prompt <span class="hljs-literal">true</span>
461461
<span class="hljs-keyword">return</span></pre></div></div>
462462

463463
</li>
@@ -473,7 +473,7 @@ <h1>repl.coffee</h1>
473473

474474
</div>
475475

476-
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> rli.line? <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> rli.line.match <span class="hljs-regexp">/^\s*$/</span></pre></div></div>
476+
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> <span class="hljs-keyword">if</span> repl.line? <span class="hljs-keyword">and</span> <span class="hljs-keyword">not</span> repl.line.match <span class="hljs-regexp">/^\s*$/</span></pre></div></div>
477477

478478
</li>
479479

@@ -489,10 +489,10 @@ <h1>repl.coffee</h1>
489489
</div>
490490

491491
<div class="content"><div class='highlight'><pre> multiline.enabled = <span class="hljs-keyword">not</span> multiline.enabled
492-
rli.line = <span class="hljs-string">''</span>
493-
rli.cursor = <span class="hljs-number">0</span>
494-
rli.output.cursorTo <span class="hljs-number">0</span>
495-
rli.output.clearLine <span class="hljs-number">1</span></pre></div></div>
492+
repl.line = <span class="hljs-string">''</span>
493+
repl.cursor = <span class="hljs-number">0</span>
494+
repl.output.cursorTo <span class="hljs-number">0</span>
495+
repl.output.clearLine <span class="hljs-number">1</span></pre></div></div>
496496

497497
</li>
498498

@@ -508,12 +508,12 @@ <h1>repl.coffee</h1>
508508
</div>
509509

510510
<div class="content"><div class='highlight'><pre> multiline.buffer = multiline.buffer.replace <span class="hljs-regexp">/\n/g</span>, <span class="hljs-string">'\uFF00'</span>
511-
rli.emit <span class="hljs-string">'line'</span>, multiline.buffer
511+
repl.emit <span class="hljs-string">'line'</span>, multiline.buffer
512512
multiline.buffer = <span class="hljs-string">''</span>
513513
<span class="hljs-keyword">else</span>
514514
multiline.enabled = <span class="hljs-keyword">not</span> multiline.enabled
515-
rli.setPrompt multiline.initialPrompt
516-
rli.prompt <span class="hljs-literal">true</span>
515+
repl.setPrompt multiline.initialPrompt
516+
repl.prompt <span class="hljs-literal">true</span>
517517
<span class="hljs-keyword">return</span></pre></div></div>
518518

519519
</li>
@@ -580,7 +580,7 @@ <h1>repl.coffee</h1>
580580

581581
</div>
582582

583-
<div class="content"><div class='highlight'><pre> repl.rli.history = buffer.toString().split(<span class="hljs-string">'\n'</span>).reverse()</pre></div></div>
583+
<div class="content"><div class='highlight'><pre> repl.history = buffer.toString().split(<span class="hljs-string">'\n'</span>).reverse()</pre></div></div>
584584

585585
</li>
586586

@@ -595,7 +595,7 @@ <h1>repl.coffee</h1>
595595

596596
</div>
597597

598-
<div class="content"><div class='highlight'><pre> repl.rli.history.pop() <span class="hljs-keyword">if</span> stat.size &gt; maxSize</pre></div></div>
598+
<div class="content"><div class='highlight'><pre> repl.history.pop() <span class="hljs-keyword">if</span> stat.size &gt; maxSize</pre></div></div>
599599

600600
</li>
601601

@@ -610,13 +610,13 @@ <h1>repl.coffee</h1>
610610

611611
</div>
612612

613-
<div class="content"><div class='highlight'><pre> repl.rli.history.shift() <span class="hljs-keyword">if</span> repl.rli.history[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">''</span>
614-
repl.rli.historyIndex = <span class="hljs-number">-1</span>
615-
lastLine = repl.rli.history[<span class="hljs-number">0</span>]
613+
<div class="content"><div class='highlight'><pre> repl.history.shift() <span class="hljs-keyword">if</span> repl.history[<span class="hljs-number">0</span>] <span class="hljs-keyword">is</span> <span class="hljs-string">''</span>
614+
repl.historyIndex = <span class="hljs-number">-1</span>
615+
lastLine = repl.history[<span class="hljs-number">0</span>]
616616

617617
fd = fs.openSync filename, <span class="hljs-string">'a'</span>
618618

619-
repl.rli.addListener <span class="hljs-string">'line'</span>, <span class="hljs-function"><span class="hljs-params">(code)</span> -&gt;</span>
619+
repl.addListener <span class="hljs-string">'line'</span>, <span class="hljs-function"><span class="hljs-params">(code)</span> -&gt;</span>
620620
<span class="hljs-keyword">if</span> code <span class="hljs-keyword">and</span> code.length <span class="hljs-keyword">and</span> code <span class="hljs-keyword">isnt</span> <span class="hljs-string">'.history'</span> <span class="hljs-keyword">and</span> code <span class="hljs-keyword">isnt</span> <span class="hljs-string">'.exit'</span> <span class="hljs-keyword">and</span> lastLine <span class="hljs-keyword">isnt</span> code</pre></div></div>
621621

622622
</li>
@@ -667,7 +667,7 @@ <h1>repl.coffee</h1>
667667
<div class="content"><div class='highlight'><pre> repl.commands[getCommandId(repl, <span class="hljs-string">'history'</span>)] =
668668
help: <span class="hljs-string">'Show command history'</span>
669669
action: <span class="hljs-function">-&gt;</span>
670-
repl.outputStream.write <span class="hljs-string">"<span class="hljs-subst">#{repl.rli.history[..].reverse().join <span class="hljs-string">'\n'</span>}</span>\n"</span>
670+
repl.outputStream.write <span class="hljs-string">"<span class="hljs-subst">#{repl.history[..].reverse().join <span class="hljs-string">'\n'</span>}</span>\n"</span>
671671
repl.displayPrompt()
672672
<span class="hljs-function">
673673
<span class="hljs-title">getCommandId</span> = <span class="hljs-params">(repl, commandName)</span> -&gt;</span></pre></div></div>
@@ -742,7 +742,7 @@ <h1>repl.coffee</h1>
742742
opts = merge replDefaults, opts
743743
repl = nodeREPL.start opts
744744
runInContext opts.prelude, repl.context, <span class="hljs-string">'prelude'</span> <span class="hljs-keyword">if</span> opts.prelude
745-
repl.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>, <span class="hljs-function">-&gt;</span> repl.outputStream.write <span class="hljs-string">'\n'</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> repl.rli.closed
745+
repl.<span class="hljs-literal">on</span> <span class="hljs-string">'exit'</span>, <span class="hljs-function">-&gt;</span> repl.outputStream.write <span class="hljs-string">'\n'</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> repl.closed
746746
addMultilineHandler repl
747747
addHistory repl, opts.historyFile, opts.historyMaxInputSize <span class="hljs-keyword">if</span> opts.historyFile</pre></div></div>
748748

lib/coffeescript/repl.js

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/repl.coffee

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ runInContext = (js, context, filename) ->
7575
vm.runInContext js, context, filename
7676

7777
addMultilineHandler = (repl) ->
78-
{rli, inputStream, outputStream} = repl
78+
{inputStream, outputStream} = repl
7979
# Node 0.11.12 changed API, prompt is now _prompt.
8080
origPrompt = repl._prompt ? repl.prompt
8181

@@ -86,15 +86,15 @@ addMultilineHandler = (repl) ->
8686
buffer: ''
8787

8888
# Proxy node's line listener
89-
nodeLineListener = rli.listeners('line')[0]
90-
rli.removeListener 'line', nodeLineListener
91-
rli.on 'line', (cmd) ->
89+
nodeLineListener = repl.listeners('line')[0]
90+
repl.removeListener 'line', nodeLineListener
91+
repl.on 'line', (cmd) ->
9292
if multiline.enabled
9393
multiline.buffer += "#{cmd}\n"
94-
rli.setPrompt multiline.prompt
95-
rli.prompt true
94+
repl.setPrompt multiline.prompt
95+
repl.prompt true
9696
else
97-
rli.setPrompt origPrompt
97+
repl.setPrompt origPrompt
9898
nodeLineListener cmd
9999
return
100100

@@ -105,25 +105,25 @@ addMultilineHandler = (repl) ->
105105
# allow arbitrarily switching between modes any time before multiple lines are entered
106106
unless multiline.buffer.match /\n/
107107
multiline.enabled = not multiline.enabled
108-
rli.setPrompt origPrompt
109-
rli.prompt true
108+
repl.setPrompt origPrompt
109+
repl.prompt true
110110
return
111111
# no-op unless the current line is empty
112-
return if rli.line? and not rli.line.match /^\s*$/
112+
return if repl.line? and not repl.line.match /^\s*$/
113113
# eval, print, loop
114114
multiline.enabled = not multiline.enabled
115-
rli.line = ''
116-
rli.cursor = 0
117-
rli.output.cursorTo 0
118-
rli.output.clearLine 1
115+
repl.line = ''
116+
repl.cursor = 0
117+
repl.output.cursorTo 0
118+
repl.output.clearLine 1
119119
# XXX: multiline hack
120120
multiline.buffer = multiline.buffer.replace /\n/g, '\uFF00'
121-
rli.emit 'line', multiline.buffer
121+
repl.emit 'line', multiline.buffer
122122
multiline.buffer = ''
123123
else
124124
multiline.enabled = not multiline.enabled
125-
rli.setPrompt multiline.initialPrompt
126-
rli.prompt true
125+
repl.setPrompt multiline.initialPrompt
126+
repl.prompt true
127127
return
128128

129129
# Store and load command history from a file
@@ -139,17 +139,17 @@ addHistory = (repl, filename, maxSize) ->
139139
fs.readSync readFd, buffer, 0, size, stat.size - size
140140
fs.closeSync readFd
141141
# Set the history on the interpreter
142-
repl.rli.history = buffer.toString().split('\n').reverse()
142+
repl.history = buffer.toString().split('\n').reverse()
143143
# If the history file was truncated we should pop off a potential partial line
144-
repl.rli.history.pop() if stat.size > maxSize
144+
repl.history.pop() if stat.size > maxSize
145145
# Shift off the final blank newline
146-
repl.rli.history.shift() if repl.rli.history[0] is ''
147-
repl.rli.historyIndex = -1
148-
lastLine = repl.rli.history[0]
146+
repl.history.shift() if repl.history[0] is ''
147+
repl.historyIndex = -1
148+
lastLine = repl.history[0]
149149

150150
fd = fs.openSync filename, 'a'
151151

152-
repl.rli.addListener 'line', (code) ->
152+
repl.addListener 'line', (code) ->
153153
if code and code.length and code isnt '.history' and code isnt '.exit' and lastLine isnt code
154154
# Save the latest command in the file
155155
fs.writeSync fd, "#{code}\n"
@@ -163,7 +163,7 @@ addHistory = (repl, filename, maxSize) ->
163163
repl.commands[getCommandId(repl, 'history')] =
164164
help: 'Show command history'
165165
action: ->
166-
repl.outputStream.write "#{repl.rli.history[..].reverse().join '\n'}\n"
166+
repl.outputStream.write "#{repl.history[..].reverse().join '\n'}\n"
167167
repl.displayPrompt()
168168

169169
getCommandId = (repl, commandName) ->
@@ -212,7 +212,7 @@ module.exports =
212212
opts = merge replDefaults, opts
213213
repl = nodeREPL.start opts
214214
runInContext opts.prelude, repl.context, 'prelude' if opts.prelude
215-
repl.on 'exit', -> repl.outputStream.write '\n' if not repl.rli.closed
215+
repl.on 'exit', -> repl.outputStream.write '\n' if not repl.closed
216216
addMultilineHandler repl
217217
addHistory repl, opts.historyFile, opts.historyMaxInputSize if opts.historyFile
218218
# Adapt help inherited from the node REPL

test/repl.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ctrlV = { ctrl: true, name: 'v'}
4545

4646

4747
testRepl 'reads history file', (input, output, repl) ->
48-
input.emitLine repl.rli.history[0]
48+
input.emitLine repl.history[0]
4949
eq '3', output.lastWrite()
5050

5151
testRepl "starts with coffee prompt", (input, output) ->

0 commit comments

Comments
 (0)