Skip to content

Commit 8716bc6

Browse files
authored
fix: resolve unrecognized keywords bug in the REPL's syntax-highlighter
PR-URL: #2284 Signed-off-by: Snehil Shah <snehilshah.989@gmail.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 24f4a8f commit 8716bc6

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function tokenizer( line, context ) {
122122
tokens.push( token );
123123
return;
124124
}
125-
if ( token.type.keyword ) {
125+
if ( token.type.keyword || ( token.type.label === 'name' && isUnrecognizedKeyword( token.value ) ) ) {
126126
// Keywords - `function`, `import`, `var`, `const`, `let` etc.:
127127
token.type = 'keyword';
128128
tokens.push( token );
@@ -197,6 +197,10 @@ function tokenizer( line, context ) {
197197
if ( node.start === node.end ) {
198198
return true;
199199
}
200+
// Ignore node if it is an unrecognized `keyword`:
201+
if ( isUnrecognizedKeyword( node.name ) ) {
202+
return true;
203+
}
200204
// If node is an unrecognized `literal`, push it as a token:
201205
if ( node.name === 'undefined' ) {
202206
tokens.push({
@@ -207,16 +211,6 @@ function tokenizer( line, context ) {
207211
});
208212
return true;
209213
}
210-
// If node is an unrecognized `keyword`, push it as a token:
211-
if ( isUnrecognizedKeyword( node.name ) ) {
212-
tokens.push({
213-
'value': node.name,
214-
'type': 'keyword',
215-
'start': node.start,
216-
'end': node.end
217-
});
218-
return true;
219-
}
220214
// If identifier is defined in the local scope, assume and treat it like a `variable` and push it as a token...
221215
if ( contains( resolveLocalScope( ast, node ), node.name ) ) {
222216
tokens.push({

0 commit comments

Comments
 (0)