From 4327fe6efdd6daebf7ff695eab7764f8dd98add1 Mon Sep 17 00:00:00 2001 From: Ashutosh Varma Date: Tue, 13 Apr 2021 02:16:53 +0530 Subject: [PATCH] decorate all global variable with @lazy Signed-off-by: Ashutosh Varma --- assembly/char.ts | 3 +++ assembly/nfa/matcher.ts | 24 ++++++++++++++++++++---- assembly/nfa/nfa.ts | 8 +++++++- assembly/parser/node.ts | 13 +++++++++++-- assembly/parser/walker.ts | 5 ++++- assembly/regexp.ts | 5 ++++- 6 files changed, 49 insertions(+), 9 deletions(-) diff --git a/assembly/char.ts b/assembly/char.ts index 6028514..1b5aab0 100644 --- a/assembly/char.ts +++ b/assembly/char.ts @@ -1,3 +1,6 @@ +// @ts-ignore +// prettier-ignore +@lazy export const enum Char { None = -1, HorizontalTab = 0x09, diff --git a/assembly/nfa/matcher.ts b/assembly/nfa/matcher.ts index 64b080b..cbfc450 100644 --- a/assembly/nfa/matcher.ts +++ b/assembly/nfa/matcher.ts @@ -10,6 +10,9 @@ import { import { Flags } from "../regexp"; import { Range } from "../util"; +// @ts-ignore +// prettier-ignore +@lazy const enum MatcherType { Character, CharacterRange, @@ -17,7 +20,9 @@ const enum MatcherType { CharacterClass, } -let _flags: Flags; +// @ts-ignore +@lazy + let _flags: Flags; export class Matcher { constructor(readonly type: MatcherType) {} @@ -93,9 +98,20 @@ export class CharacterMatcher extends Matcher { } } -const LOWERCASE_LETTERS = new Range(Char.a, Char.z); -const UPPERCASE_LETTERS = new Range(Char.A, Char.Z); -const UPPER_LOWER_OFFSET = Char.a - Char.A; +// @ts-ignore +// prettier-ignore +@lazy + const LOWERCASE_LETTERS = new Range(Char.a, Char.z); + +// @ts-ignore +// prettier-ignore +@lazy + const UPPERCASE_LETTERS = new Range(Char.A, Char.Z); + +// @ts-ignore +// prettier-ignore +@lazy + const UPPER_LOWER_OFFSET = Char.a - Char.A; export class CharacterRangeMatcher extends Matcher { private ranges: Range[]; diff --git a/assembly/nfa/nfa.ts b/assembly/nfa/nfa.ts index 9953a81..8462fb2 100644 --- a/assembly/nfa/nfa.ts +++ b/assembly/nfa/nfa.ts @@ -15,6 +15,9 @@ import { Char } from "../char"; import { Matcher } from "./matcher"; import { Flags } from "../regexp"; +// @ts-ignore +// prettier-ignore +@lazy export enum MatchResult { // a match has occurred - which is a signal to consume a character Match, @@ -24,7 +27,10 @@ export enum MatchResult { Ignore, } -let _stateId: u32 = 0; +// @ts-ignore +// prettier-ignore +@lazy + let _stateId: u32 = 0; /* eslint @typescript-eslint/no-empty-function: ["error", { "allow": ["constructors", "methods"] }] */ export class State { diff --git a/assembly/parser/node.ts b/assembly/parser/node.ts index 3505379..c530d08 100644 --- a/assembly/parser/node.ts +++ b/assembly/parser/node.ts @@ -1,6 +1,9 @@ import { Char } from "../char"; import { replaceAtIndex } from "../util"; +// @ts-ignore +// prettier-ignore +@lazy export const enum NodeType { AST, Assertion, @@ -15,7 +18,10 @@ export const enum NodeType { Group, } -const emptyNodeArray = new Array(); +// @ts-ignore +// prettier-ignore +@lazy + const emptyNodeArray = new Array(); export abstract class Node { constructor(public type: NodeType) {} @@ -210,7 +216,10 @@ export class AlternationNode extends Node { } } -let _id = 0; +// @ts-ignore +// prettier-ignore +@lazy + let _id = 0; export class GroupNode extends Node { constructor( diff --git a/assembly/parser/walker.ts b/assembly/parser/walker.ts index 88ae4ed..0051a8c 100644 --- a/assembly/parser/walker.ts +++ b/assembly/parser/walker.ts @@ -37,7 +37,10 @@ export function walker(ast: AST, visitor: (node: NodeVisitor) => void): void { // range quantifiers are implemented via 'expansion', which significantly // increases the size of the AST. This imposes a hard limit to prevent // memory-related issues -const QUANTIFIER_LIMIT = 1000; +// @ts-ignore +// prettier-ignore +@lazy + const QUANTIFIER_LIMIT = 1000; function parentAsConcatNode(visitor: NodeVisitor): ConcatenationNode { let concatNode: ConcatenationNode | null = null; diff --git a/assembly/regexp.ts b/assembly/regexp.ts index 8620036..028c58b 100644 --- a/assembly/regexp.ts +++ b/assembly/regexp.ts @@ -69,7 +69,10 @@ export class Match { } } -let gm = new Array(); +// @ts-ignore +// prettier-ignore +@lazy + let gm = new Array(); export class Flags { global: bool = false;