lexter.ts - let -> const, fixed type errors

changed most let variables to const, fixed more type errors
This commit is contained in:
tel0065 2022-03-25 13:17:51 -05:00 committed by GitHub
parent 50ff693d16
commit d19ad8f885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,7 +81,7 @@ export default class Lexer {
}; };
if (text) { if (text) {
// normalize linefeeds // normalize line feeds
text = text.replace('\r\n', '\n'); text = text.replace('\r\n', '\n');
} }
this.restart(text); this.restart(text);
@ -120,13 +120,13 @@ export default class Lexer {
// Until a LineToken is found, or EOF // Until a LineToken is found, or EOF
while (this.pos < this.textLines.length) { while (this.pos < this.textLines.length) {
let line: string = this.textLines[this.pos]; const line: string = this.textLines[this.pos];
let indent: number = Lexer.getIndent(line, this.tabFmt!); const indent: number = Lexer.getIndent(line, this.tabFmt!);
let token: LineToken; let token: LineToken;
for (var r of rules) { for (var r of rules) {
// Does line match pattern? // Does line match pattern?
let match: RegExpMatchArray | null = line.match(r.pattern); const match: RegExpMatchArray | null = line.match(r.pattern);
if (match) { if (match) {
// Yes... // Yes...
if (match.groups) { if (match.groups) {
@ -212,7 +212,7 @@ export default class Lexer {
* @return The indent of `text` with consideration for `tabFmt`. * @return The indent of `text` with consideration for `tabFmt`.
*/ */
static getIndent(text: string, tabFmt: TabInfo): number { static getIndent(text: string, tabFmt: TabInfo): number {
let leadingSpace: number = text.length - text.trimStart().length; const leadingSpace: number = text.length - text.trimStart().length;
let indent: number; let indent: number;
if (tabFmt.hard) { if (tabFmt.hard) {
@ -234,7 +234,7 @@ export default class Lexer {
* @param `line` The line of text. * @param `line` The line of text.
* @return The number of leading spaces of `text`. * @return The number of leading spaces of `text`.
*/ */
static getLeadingSpacesByArithmetic(line: any) { static getLeadingSpacesByArithmetic(line: any): number {
const leadingSpaces: number = line.text.length - line.text.trimStart().length; const leadingSpaces: number = line.text.length - line.text.trimStart().length;
return leadingSpaces; return leadingSpaces;
@ -249,7 +249,7 @@ export default class Lexer {
* @param `text` The line of text. * @param `text` The line of text.
* @return The number of leading spaces of `text` with respect to the index position of the first non-whitespace character. * @return The number of leading spaces of `text` with respect to the index position of the first non-whitespace character.
*/ */
static getLeadingSpacesByIndex(text: any) { static getLeadingSpacesByIndex(text: any): number {
const indexNum: number = text.firstNonWhitespaceCharacterIndex; const indexNum: number = text.firstNonWhitespaceCharacterIndex;
return indexNum; return indexNum;