Skip to content

Commit ac9d017

Browse files
committed
Auto-generated commit
1 parent eaa6027 commit ac9d017

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-07-05)
7+
## Unreleased (2024-07-09)
88

99
<section class="packages">
1010

@@ -40,6 +40,7 @@
4040

4141
##### Bug Fixes
4242

43+
- [`3efb708`](https://github.com/stdlib-js/stdlib/commit/3efb708f62e31603de837db5621522471046b27d) - address duplicate token bug when syntax-highlighting [(#2542)](https://github.com/stdlib-js/stdlib/pull/2542)
4344
- [`d2cd4c3`](https://github.com/stdlib-js/stdlib/commit/d2cd4c355302240f3cc5ea050d349715925be744) - pass options when parsing to suppress warnings in the REPL [(#2430)](https://github.com/stdlib-js/stdlib/pull/2430)
4445
- [`1036087`](https://github.com/stdlib-js/stdlib/commit/1036087c00b59cc981530e66b3aaa1966c6e74e0) - prevent access if properties couldn't be resolved when syntax highlighting in the REPL [(##2412)](#2412)
4546
- [`9f3dcaf`](https://github.com/stdlib-js/stdlib/commit/9f3dcaf4d19fde9e7066f7dc12a49cf87e6fd0f7) - update error message
@@ -271,6 +272,7 @@ A total of 9 people contributed to this release. Thank you to the following cont
271272

272273
<details>
273274

275+
- [`3efb708`](https://github.com/stdlib-js/stdlib/commit/3efb708f62e31603de837db5621522471046b27d) - **fix:** address duplicate token bug when syntax-highlighting [(#2542)](https://github.com/stdlib-js/stdlib/pull/2542) _(by Snehil Shah)_
274276
- [`243ab4d`](https://github.com/stdlib-js/stdlib/commit/243ab4d0fbd85acb68e4d394fac8d84011621a44) - **test:** fix failing tests in the REPL [(#2516)](https://github.com/stdlib-js/stdlib/pull/2516) _(by Snehil Shah)_
275277
- [`350aa53`](https://github.com/stdlib-js/stdlib/commit/350aa5304430dc8b29acbfcecd9e23f9780bd5a1) - **docs:** update REPL namespace documentation [(#2515)](https://github.com/stdlib-js/stdlib/pull/2515) _(by stdlib-bot, Athan Reines)_
276278
- [`7ba179c`](https://github.com/stdlib-js/stdlib/commit/7ba179c7f5084a9b39e22282b02e756c9671d6d8) - **feat:** add bracketed-paste mode in the REPL [(#2502)](https://github.com/stdlib-js/stdlib/pull/2502) _(by Snehil Shah, Athan Reines)_

lib/syntax_highlighter.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var readline = require( 'readline' );
2626
var logger = require( 'debug' );
2727
var format = require( '@stdlib/string/format' );
2828
var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
29+
var isEmptyArray = require( '@stdlib/assert/is-empty-array' );
2930
var objectKeys = require( '@stdlib/utils/keys' );
3031
var omit = require( '@stdlib/utils/omit' );
3132
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
@@ -54,6 +55,26 @@ function tokenComparator( a, b ) {
5455
return a.start - b.start;
5556
}
5657

58+
/**
59+
* Removes duplicate tokens from a sorted tokens array.
60+
*
61+
* @private
62+
* @param {Array<Object>} tokens - sorted tokens array
63+
* @returns {Array<Object>} array with unique tokens
64+
*/
65+
function removeDuplicateTokens( tokens ) {
66+
var out = [];
67+
var i;
68+
69+
out.push( tokens[ 0 ] );
70+
for ( i = 1; i < tokens.length; i++ ) {
71+
if ( tokens[ i - 1 ].start !== tokens[ i ].start ) {
72+
out.push( tokens[ i ] );
73+
}
74+
}
75+
return out;
76+
}
77+
5778

5879
// MAIN //
5980

@@ -125,8 +146,7 @@ setNonEnumerableReadOnly( SyntaxHighlighter.prototype, '_highlightLine', functio
125146
var i;
126147
var j;
127148

128-
// Sort and traverse the tokens...
129-
tokens.sort( tokenComparator );
149+
// Traverse the tokens...
130150
for ( i = 0; i < tokens.length; i++ ) {
131151
token = tokens[ i ];
132152
color = theme[ token.type ];
@@ -309,11 +329,15 @@ setNonEnumerableReadOnly( SyntaxHighlighter.prototype, 'onKeypress', function on
309329
// Tokenize:
310330
debug( 'Line change detected. Tokenizing line: %s', this._rli.line );
311331
tokens = tokenizer( this._rli.line, this._repl._context );
312-
if ( !tokens ) {
332+
if ( isEmptyArray( tokens ) ) {
313333
debug( 'No tokens found. Skipping highlighting...' );
314334
this._multilineHandler.updateLine( this._rli.line ); // save displayed line
315335
return;
316336
}
337+
// Process tokens:
338+
tokens.sort( tokenComparator );
339+
tokens = removeDuplicateTokens( tokens );
340+
317341
// Highlight:
318342
debug( '%d tokens found. Highlighting...', tokens.length );
319343
this._line = this._rli.line; // updated line buffer

test/integration/fixtures/syntax-highlighting/member_expressions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"expression": "var a = { 'b': 'bar' }; var foo = { 'bar': { 'func': function() { return true; } } };\nfoo[a.b].func()",
3-
"expected": "\u001b[31mfoo\u001b[0m[\u001b[31ma\u001b[0m.\u001b[32mb\u001b[0m].\u001b[33mfunc\u001b[0m()",
2+
"expression": "var a = { 'b': { 'c': 'bar' } }; var foo = { 'bar': { 'func': function() { return true; } } };\nfoo[a.b.c].func()",
3+
"expected": "\u001b[31mfoo\u001b[0m[\u001b[31ma\u001b[0m.\u001b[31mb\u001b[0m.\u001b[32mc\u001b[0m].\u001b[33mfunc\u001b[0m()",
44
"theme": {
55
"object": "red",
66
"function": "yellow",

0 commit comments

Comments
 (0)