diff options
| author | David Sherret <dsherret@users.noreply.github.com> | 2023-10-24 09:37:02 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-24 09:37:02 -0400 |
| commit | 8f065a60e79e221a6ce7f6ce06c3022a85edb56a (patch) | |
| tree | e1be8f4d384b5dd4f73940b86fd60cc58f43aef1 /cli/tools/repl/editor.rs | |
| parent | 9df36b33c6aa250daa200167eb0e1b9d6d738da1 (diff) | |
fix: improved using declaration support (#20959)
Upgrades to deno_ast 0.30.
Diffstat (limited to 'cli/tools/repl/editor.rs')
| -rw-r--r-- | cli/tools/repl/editor.rs | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/cli/tools/repl/editor.rs b/cli/tools/repl/editor.rs index 5c2832aab..52fad4759 100644 --- a/cli/tools/repl/editor.rs +++ b/cli/tools/repl/editor.rs @@ -374,32 +374,35 @@ impl Highlighter for EditorHelper { } Word::Keyword(_) => colors::cyan(&line[range]).to_string(), Word::Ident(ident) => { - if ident == *"undefined" { - colors::gray(&line[range]).to_string() - } else if ident == *"Infinity" || ident == *"NaN" { - colors::yellow(&line[range]).to_string() - } else if ident == *"async" || ident == *"of" { - colors::cyan(&line[range]).to_string() - } else { - let next = lexed_items.peek().map(|item| &item.inner); - if matches!( - next, - Some(deno_ast::TokenOrComment::Token(Token::LParen)) - ) { - // We're looking for something that looks like a function - // We use a simple heuristic: 'ident' followed by 'LParen' - colors::intense_blue(&line[range]).to_string() - } else if ident == *"from" - && matches!( + match ident.as_ref() { + "undefined" => colors::gray(&line[range]).to_string(), + "Infinity" | "NaN" => { + colors::yellow(&line[range]).to_string() + } + "async" | "of" => colors::cyan(&line[range]).to_string(), + _ => { + let next = lexed_items.peek().map(|item| &item.inner); + if matches!( next, - Some(deno_ast::TokenOrComment::Token(Token::Str { .. })) - ) - { - // When ident 'from' is followed by a string literal, highlight it - // E.g. "export * from 'something'" or "import a from 'something'" - colors::cyan(&line[range]).to_string() - } else { - line[range].to_string() + Some(deno_ast::TokenOrComment::Token(Token::LParen)) + ) { + // We're looking for something that looks like a function + // We use a simple heuristic: 'ident' followed by 'LParen' + colors::intense_blue(&line[range]).to_string() + } else if ident.as_ref() == "from" + && matches!( + next, + Some(deno_ast::TokenOrComment::Token( + Token::Str { .. } + )) + ) + { + // When ident 'from' is followed by a string literal, highlight it + // E.g. "export * from 'something'" or "import a from 'something'" + colors::cyan(&line[range]).to_string() + } else { + line[range].to_string() + } } } } |
