module
Noir::JSLiteralScanner
Overview
JSLiteralScanner provides utilities for scanning JavaScript source code while properly skipping string literals, comments, template literals, and regex. This ensures parenthesis/brace matching doesn't get confused by literals.
Defined in:
utils/js_literal_scanner.crConstant Summary
-
REGEX_PRECEDING_CHARS =
['(', '[', '{', ',', ':', ';', '=', '!', '&', '|', '?', '+', '-', '*', '%', '<', '>', '~', '^'] -
Characters that can precede a regex literal (operators/punctuation expecting expression)
-
REGEX_PRECEDING_KEYWORDS =
["return", "case", "throw", "in", "of", "typeof", "instanceof", "void", "delete", "new"] -
Keywords that can precede a regex literal in JavaScript
Class Method Summary
-
.extract_paren_content(content : String, start_pos : Int32) : ScanResult | Nil
Extract content between parentheses while skipping literals Returns the content inside the parentheses (not including the parens)
-
.find_matching_brace(content : String, open_brace_idx : Int32) : Int32 | Nil
Find matching closing brace, skipping literals
-
.find_matching_paren(content : String, open_paren_idx : Int32) : Int32 | Nil
Find matching closing paren, skipping literals
-
.try_skip_literal(content : String, pos : Int32, accumulated : String) : NamedTuple(content: String, pos: Int32) | Nil
Try to skip a literal at the current position Returns updated content string and position if a literal was skipped, nil otherwise
Class Method Detail
Extract content between parentheses while skipping literals Returns the content inside the parentheses (not including the parens)
Find matching closing brace, skipping literals
Find matching closing paren, skipping literals