Skip to content

Commit e9c6d40

Browse files
authored
fix: remove syntax highlighting upon encountering invalid JS
Previously, if you entered `varlkdf`, the `var` would remain highlighted. This commit addresses this syntax highlighting bug. PR-URL: #2758 Reviewed-by: Athan Reines <[email protected]> Signed-off-by: Snehil Shah <[email protected]>
1 parent 90133e3 commit e9c6d40

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -328,20 +328,20 @@ setNonEnumerableReadOnly( SyntaxHighlighter.prototype, 'onKeypress', function on
328328
if ( this._line !== this._rli.line ) {
329329
// Tokenize:
330330
debug( 'Line change detected. Tokenizing line: %s', this._rli.line );
331-
tokens = tokenizer( this._rli.line, this._repl._context );
331+
this._line = this._rli.line; // update line buffer
332+
tokens = tokenizer( this._line, this._repl._context );
332333
if ( isEmptyArray( tokens ) ) {
333334
debug( 'No tokens found. Skipping highlighting...' );
334-
this._multilineHandler.updateLine( this._rli.line ); // save displayed line
335-
return;
335+
this._highlightedLine = this._line;
336+
} else {
337+
// Process tokens:
338+
tokens.sort( tokenComparator );
339+
tokens = removeDuplicateTokens( tokens );
340+
341+
// Highlight:
342+
debug( '%d tokens found. Highlighting...', tokens.length );
343+
this._highlightedLine = this._highlightLine( this._line, tokens );
336344
}
337-
// Process tokens:
338-
tokens.sort( tokenComparator );
339-
tokens = removeDuplicateTokens( tokens );
340-
341-
// Highlight:
342-
debug( '%d tokens found. Highlighting...', tokens.length );
343-
this._line = this._rli.line; // updated line buffer
344-
this._highlightedLine = this._highlightLine( this._line, tokens );
345345
}
346346
// Replace:
347347
debug( 'Replacing current line with the highlighted line...' );

0 commit comments

Comments
 (0)