Skip to content

Commit

Permalink
Fix AS210 error where expressions are never null (#45)
Browse files Browse the repository at this point in the history
* Fix AS210 error where expressions are never null

* fix AssemblyScript 0.27.0 build error

* revert assemblyscript to ^0.25.0 to resolve npm issues
  • Loading branch information
jonathannorris committed Nov 11, 2023
1 parent ffd112f commit c9e1d77
Show file tree
Hide file tree
Showing 4 changed files with 13,537 additions and 9,111 deletions.
2 changes: 1 addition & 1 deletion assembly/nfa/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const enum MatcherType {
CharacterClass,
}
export class Matcher {
@lazy static _flags: Flags;
@lazy static _flags!: Flags;

constructor(readonly type: MatcherType) {}

Expand Down
10 changes: 6 additions & 4 deletions assembly/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,19 @@ export class RegExp {

astWalker(ast, expandRepetitions);

this.nfa = Automata.toNFA(ast, flags);
const nfa = Automata.toNFA(ast, flags);

// find all the group marker states
RegExp.gm = new Array<GroupStartMarkerState>();
nfaWalker(this.nfa.start, (state) => {
nfaWalker(nfa.start, (state) => {
if (state instanceof GroupStartMarkerState) {
const startMarker = state as GroupStartMarkerState;
if (startMarker.capturing) {
RegExp.gm.push(state as GroupStartMarkerState);
}
}
});
this.nfa = nfa;
this.groupMarkers = RegExp.gm;

this.flags = flags;
Expand All @@ -159,7 +160,7 @@ export class RegExp {
let len = str.length;
if (!len) {
const matchStr = recursiveBacktrackingSearch(this.nfa.start, "");
return matchStr != null ? new Match([matchStr!], 0, str) : null;
return matchStr != null ? new Match([matchStr], 0, str) : null;
}

// search for a match at each index within the string
Expand All @@ -182,8 +183,9 @@ export class RegExp {
gm.capture = gm.flagged ? gm.capture : "";
});

const matches: string[] = [matchStr];
const match = new Match(
[matchStr!].concat(lastCapturesForGroup(groupMarkers)),
matches.concat(lastCapturesForGroup(groupMarkers)),
matchIndex,
str
);
Expand Down

0 comments on commit c9e1d77

Please sign in to comment.