Skip to content

Commit

Permalink
Add stricter type for CharacterClassEscape value (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjenkinson authored Nov 28, 2023
1 parent 5517b6c commit 697eaca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type Anchor = Base<"anchor"> & {
};

export type CharacterClassEscape = Base<"characterClassEscape"> & {
value: string;
value: 'd' | 'D' | 'w' | 'W' | 's' | 'S';
};

export type Value = Base<"value"> & {
Expand Down
12 changes: 11 additions & 1 deletion test/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { AstNodeType, Identifier, ModifierFlags, parse, RootNode } from "../parser";
import {
AstNodeType,
Identifier,
ModifierFlags,
parse,
RootNode,
} from "../parser";

function assert<T>(input: T): void {}

Expand Down Expand Up @@ -30,6 +36,10 @@ if (defaultNode.type === "characterClass") {
assert<"union">(defaultNode.kind);
}

if (defaultNode.type === "characterClassEscape") {
assert<"d" | "D" | "w" | "W" | "s" | "S">(defaultNode.value);
}

assert<number>(defaultNode.range[0]);
assert<number>(defaultNode.range[1]);
assert<string>(defaultNode.raw);
Expand Down

0 comments on commit 697eaca

Please sign in to comment.