Skip to content

Commit

Permalink
fix: remove syntax highlighting upon encountering invalid JS
Browse files Browse the repository at this point in the history
Previously, if you entered `varlkdf`, the `var` would remain highlighted. This commit addresses this syntax highlighting bug.

PR-URL: #2758
Reviewed-by: Athan Reines <kgryte@gmail.com>
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
  • Loading branch information
Snehil-Shah authored Aug 8, 2024
1 parent 90133e3 commit e9c6d40
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/node_modules/@stdlib/repl/lib/syntax_highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,20 @@ setNonEnumerableReadOnly( SyntaxHighlighter.prototype, 'onKeypress', function on
if ( this._line !== this._rli.line ) {
// Tokenize:
debug( 'Line change detected. Tokenizing line: %s', this._rli.line );
tokens = tokenizer( this._rli.line, this._repl._context );
this._line = this._rli.line; // update line buffer
tokens = tokenizer( this._line, this._repl._context );
if ( isEmptyArray( tokens ) ) {
debug( 'No tokens found. Skipping highlighting...' );
this._multilineHandler.updateLine( this._rli.line ); // save displayed line
return;
this._highlightedLine = this._line;
} else {
// Process tokens:
tokens.sort( tokenComparator );
tokens = removeDuplicateTokens( tokens );

// Highlight:
debug( '%d tokens found. Highlighting...', tokens.length );
this._highlightedLine = this._highlightLine( this._line, tokens );
}
// Process tokens:
tokens.sort( tokenComparator );
tokens = removeDuplicateTokens( tokens );

// Highlight:
debug( '%d tokens found. Highlighting...', tokens.length );
this._line = this._rli.line; // updated line buffer
this._highlightedLine = this._highlightLine( this._line, tokens );
}
// Replace:
debug( 'Replacing current line with the highlighted line...' );
Expand Down

1 comment on commit e9c6d40

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
repl $\color{red}10404/12996$
$\color{green}+80.06\%$
$\color{red}631/862$
$\color{green}+73.20\%$
$\color{red}146/232$
$\color{green}+62.93\%$
$\color{red}10404/12996$
$\color{green}+80.06\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.