Obelisk::Lexers::JavaScript
Inherits Obelisk::RegexLexer < Obelisk::Lexer < Reference < Object
JavaScript/TypeScript language lexer Optimized for performance using Chroma-like simple patterns
Constants
Builtin objects (simplified to ~24 names like Chroma, vs Obelisk's 40+) Note: Chroma includes: Array, Boolean, Date, Error, Function, Math, Number, Object, RegExp, String, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, eval, isFinite, isNaN, parseFloat, parseInt, document, this, window
Constants (simplified from Obelisk's pattern)
String delimiters
Escape sequences (shared across string states)
Generic identifier (Chroma approach - most identifiers are just "names")
Template literal interpolation
Keywords (simplified - one pattern vs Chroma's multiple patterns)
Reserved/declaration keywords
Numbers (simplified from 7 to 3 patterns, matching Chroma)
Operators - must include compound operators before single chars Note: ? is NOT in single-char class as it's only used in ??, ??= operators Order matters: longer patterns first to avoid splitting
Punctuation (dot is handled separately to support optional chaining ?. operator)
Regular expression literal (simplified - not context-aware like a real parser) This may have false positives but is much faster than full context tracking
String content patterns (excluding escape sequences and quotes)
TypeScript keywords
Whitespace and comments
Instance methods
Analyze text to determine if this lexer can handle it Returns a score from 0.0 to 1.0