Skip to content

Commit 570f24e

Browse files
committed
refactor: clean code logic
Signed-off-by: Snehil Shah <[email protected]>
1 parent 3e7d7ba commit 570f24e

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lib/node_modules/@stdlib/repl/lib/syntax_highlighter.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ setNonEnumerableReadOnly( SyntaxHighlighter.prototype, 'enable', function enable
295295
* @returns {void}
296296
*/
297297
setNonEnumerableReadOnly( SyntaxHighlighter.prototype, 'onKeypress', function onKeypress() {
298-
var highlightedLine;
299298
var tokens;
300299

301300
if ( !this._enabled ) {
@@ -305,11 +304,8 @@ setNonEnumerableReadOnly( SyntaxHighlighter.prototype, 'onKeypress', function on
305304
debug( 'Empty line detected. Skipping highlighting...' );
306305
return;
307306
}
308-
// If no line change is detected, use the highlighted line from cache...
309-
if ( this._line === this._rli.line ) {
310-
debug( 'No line change detected. Using cache...' );
311-
highlightedLine = this._highlightedLine;
312-
} else {
307+
// If line change is detected, tokenize & highlight the line. Use cache if no line change is detected...
308+
if ( this._line !== this._rli.line ) {
313309
// Update line buffer:
314310
this._line = this._rli.line;
315311

@@ -322,16 +318,13 @@ setNonEnumerableReadOnly( SyntaxHighlighter.prototype, 'onKeypress', function on
322318
}
323319
// Highlight:
324320
debug( '%d tokens found. Highlighting...', tokens.length );
325-
highlightedLine = this._highlightLine( this._line, tokens );
326-
327-
// Cache the newly highlighted line:
328-
this._highlightedLine = highlightedLine;
321+
this._highlightedLine = this._highlightLine( this._line, tokens );
329322
}
330323
// Replace:
331324
debug( 'Replacing current line with the highlighted line...' );
332325
readline.moveCursor( this._ostream, -1 * this._rli.cursor, 0 );
333326
readline.clearLine( this._ostream, 1 );
334-
this._ostream.write( highlightedLine );
327+
this._ostream.write( this._highlightedLine );
335328
readline.moveCursor( this._ostream, this._rli.cursor - this._line.length, 0 ); // eslint-disable-line max-len
336329
});
337330

0 commit comments

Comments
 (0)