export interface JsScanOptions { /** Stop at a top-level %> (see header). */ template_delimiter?: boolean; /** Called for each line comment: [start of '//', end) - end excludes the newline. */ on_line_comment?: (start: number, end: number) => void; /** * Called for each top-level code character (not inside a literal or comment, * whitespace included). Return true to stop the scan at that index. */ on_code?: (index: number, ch: string) => boolean | void; /** * Called for each raw newline inside a string or template literal (at any * nesting depth). `continuation` is true when an escaping backslash precedes it * (a line continuation, which contributes nothing to the literal's value). */ on_literal_newline?: (index: number, continuation: boolean) => void; } /** * Scan JavaScript in `text` from `start`. * * Returns the index where the scan stopped: the '%' of a top-level %> in * template-delimiter mode, or the index on_code returned true for. Returns -1 when * the text ran out first (including inside an unterminated string, template or * block comment). */ export declare function scan_js(text: string, start: number, options?: JsScanOptions): number; /** Index of the %> closing the <% %> / <%= %> body that starts at `start`, or -1. */ export declare function find_template_close(text: string, start: number): number; /** A %> hidden inside a line comment of a <% %> / <%= %> body. */ export interface HiddenClose { /** Index of the comment's '//'. */ comment: number; /** Index of the first %> inside the comment. */ close: number; /** * True when the comment looks like it was meant to close the tag: it follows code * on its line or is on the tag's opening line, or the %> ends the line. * A comment on a line of its own that mentions %> mid-sentence is not suspicious. */ suspicious: boolean; } /** * The line comments in the <% %> / <%= %> body starting at `start` that contain %>, * up to the body's closing %> (or the end of text when it has none). A line comment * runs to the end of its line, so each of these %> leaves the tag open. */ export declare function find_hidden_closes(text: string, start: number): HiddenClose[]; /** * Index of the bracket closing the one at open_index ('(', '[' or '{'), counting * all three kinds, or -1. */ export declare function find_matching_bracket(text: string, open_index: number): number; /** One past the ';' ending the statement that starts at `start` (outside brackets), or text.length. */ export declare function find_statement_end(text: string, start: number): number; /** * Replace every line comment in a JS region with spaces (newlines kept, so length * and line structure are unchanged). `template_delimiter` as for scan_js; the scan * stops at a top-level %>, and text from there on is returned untouched. */ export declare function blank_line_comments(text: string, template_delimiter?: boolean): string; /** * The same JavaScript on one line, with the same value. Codegen emits an expression * on the generated line of the source line it starts on, so a multi-line <%= %> is * joined: a newline in code becomes a space, a newline inside a string or template * literal becomes the two-character escape backslash-n, and a line continuation * (backslash + newline) is dropped, as it contributes nothing to the value. * String.raw sees the escape rather than the newline; the cooked value is identical. */ export declare function join_lines(code: string): string; export interface JoinedCode { /** The code on one line (join_lines). */ code: string; /** * For each source line after the first, the index in `code` where that line's * text begins, or -1 when the newline before it is not top-level code (it is * inside a string, template literal, interpolation or block comment). Within one * source line the joined text is character-for-character the original, so a * position in it maps back to the source by its offset from the line's start. */ line_starts: number[]; } /** join_lines, also reporting where each joined source line begins (for sourcemaps). */ export declare function join_lines_mapped(code: string): JoinedCode; /** * For each line of `text`, whether it starts in code - false when the newline before * it is inside a string, template literal or block comment, so the line is part of * that literal or comment. Line 0 always starts in code. */ export declare function code_line_starts(text: string, template_delimiter?: boolean): boolean[]; /** * Remove the statement-ending semicolons at the end of an expression * (`x;` and `x;;` -> `x`; a comment after the semicolon is kept), so the expression * can be wrapped in parentheses. * Only top-level code semicolons count - never one inside a literal or comment. */ export declare function strip_trailing_semicolons(code: string): string; /** True when `code` has a comma outside every bracket, literal and comment - a comma expression. */ export declare function has_top_level_comma(code: string): boolean; //# sourceMappingURL=js_scanner.d.ts.map