Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,26 @@ class RegExpParserState {
return this._flags
}

public onFlags(
public onRegExpFlags(
start: number,
end: number,
global: boolean,
ignoreCase: boolean,
multiline: boolean,
unicode: boolean,
sticky: boolean,
dotAll: boolean,
hasIndices: boolean,
{
global,
ignoreCase,
multiline,
unicode,
sticky,
dotAll,
hasIndices,
}: {
global: boolean
ignoreCase: boolean
multiline: boolean
unicode: boolean
sticky: boolean
dotAll: boolean
hasIndices: boolean
},
): void {
this._flags = {
type: "Flags",
Expand Down
69 changes: 50 additions & 19 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,31 @@ export namespace RegExpValidator {
*/
onLiteralLeave?: (start: number, end: number) => void

/**
* A function that is called when the validator found flags.
* @param start The 0-based index of the first character.
* @param end The next 0-based index of the last character.
* @param flags.global `g` flag.
* @param flags.ignoreCase `i` flag.
* @param flags.multiline `m` flag.
* @param flags.unicode `u` flag.
* @param flags.sticky `y` flag.
* @param flags.dotAll `s` flag.
* @param flags.hasIndices `d` flag.
*/
onRegExpFlags?: (
start: number,
end: number,
flags: {
global: boolean
ignoreCase: boolean
multiline: boolean
unicode: boolean
sticky: boolean
dotAll: boolean
hasIndices: boolean
},
) => void
/**
* A function that is called when the validator found flags.
* @param start The 0-based index of the first character.
Expand All @@ -160,6 +185,8 @@ export namespace RegExpValidator {
* @param sticky `y` flag.
* @param dotAll `s` flag.
* @param hasIndices `d` flag.
*
* @deprecated Use `onRegExpFlags` instead.
*/
onFlags?: (
start: number,
Expand Down Expand Up @@ -535,17 +562,15 @@ export class RegExpValidator {
this.raise(`Invalid flag '${source[i]}'`)
}
}
this.onFlags(
start,
end,
this.onRegExpFlags(start, end, {
global,
ignoreCase,
multiline,
unicode,
sticky,
dotAll,
hasIndices,
)
})
}

/**
Expand Down Expand Up @@ -599,28 +624,34 @@ export class RegExpValidator {
}
}

private onFlags(
private onRegExpFlags(
start: number,
end: number,
global: boolean,
ignoreCase: boolean,
multiline: boolean,
unicode: boolean,
sticky: boolean,
dotAll: boolean,
hasIndices: boolean,
flags: {
global: boolean
ignoreCase: boolean
multiline: boolean
unicode: boolean
sticky: boolean
dotAll: boolean
hasIndices: boolean
},
): void {
if (this._options.onRegExpFlags) {
this._options.onRegExpFlags(start, end, flags)
}
// Backward compatibility
if (this._options.onFlags) {
this._options.onFlags(
start,
end,
global,
ignoreCase,
multiline,
unicode,
sticky,
dotAll,
hasIndices,
flags.global,
flags.ignoreCase,
flags.multiline,
flags.unicode,
flags.sticky,
flags.dotAll,
flags.hasIndices,
)
}
}
Expand Down