Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use type instead of interface #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
88 changes: 44 additions & 44 deletions src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@
/**
* The type which defines common properties for all node types.
*/
export interface NodeBase {
export type NodeBase = {
/** The node type. */
type: Node["type"]

Check failure on line 78 in src/ast.ts

View workflow job for this annotation

GitHub Actions / 🧪 Test ([email protected])

'type' is referenced directly or indirectly in its own type annotation.
/** The parent node. */
parent: Node["parent"]

Check failure on line 80 in src/ast.ts

View workflow job for this annotation

GitHub Actions / 🧪 Test ([email protected])

'parent' is referenced directly or indirectly in its own type annotation.
/** The 0-based index that this node starts. */
start: number
/** The 0-based index that this node ends. */
Expand All @@ -89,7 +89,7 @@
/**
* The root node.
*/
export interface RegExpLiteral extends NodeBase {
export type RegExpLiteral = NodeBase & {
type: "RegExpLiteral"
parent: null
pattern: Pattern
Expand All @@ -99,7 +99,7 @@
/**
* The pattern.
*/
export interface Pattern extends NodeBase {
export type Pattern = NodeBase & {
type: "Pattern"
parent: RegExpLiteral | null
alternatives: Alternative[]
Expand All @@ -109,7 +109,7 @@
* The alternative.
* E.g. `a|b`
*/
export interface Alternative extends NodeBase {
export type Alternative = NodeBase & {
type: "Alternative"
parent: CapturingGroup | Group | LookaroundAssertion | Pattern
elements: Element[]
Expand All @@ -119,7 +119,7 @@
* The uncapturing group.
* E.g. `(?:ab)`
*/
export interface Group extends NodeBase {
export type Group = NodeBase & {
type: "Group"
parent: Alternative | Quantifier
alternatives: Alternative[]
Expand All @@ -129,7 +129,7 @@
* The capturing group.
* E.g. `(ab)`, `(?<name>ab)`
*/
export interface CapturingGroup extends NodeBase {
export type CapturingGroup = NodeBase & {
type: "CapturingGroup"
parent: Alternative | Quantifier
name: string | null
Expand All @@ -146,7 +146,7 @@
* The lookahead assertion.
* E.g. `(?=ab)`, `(?!ab)`
*/
export interface LookaheadAssertion extends NodeBase {
export type LookaheadAssertion = NodeBase & {
type: "Assertion"
parent: Alternative | Quantifier
kind: "lookahead"
Expand All @@ -158,7 +158,7 @@
* The lookbehind assertion.
* E.g. `(?<=ab)`, `(?<!ab)`
*/
export interface LookbehindAssertion extends NodeBase {
export type LookbehindAssertion = NodeBase & {
type: "Assertion"
parent: Alternative
kind: "lookbehind"
Expand All @@ -170,7 +170,7 @@
* The quantifier.
* E.g. `a?`, `a*`, `a+`, `a{1,2}`, `a??`, `a*?`, `a+?`, `a{1,2}?`
*/
export interface Quantifier extends NodeBase {
export type Quantifier = NodeBase & {
type: "Quantifier"
parent: Alternative
min: number
Expand All @@ -186,7 +186,7 @@
export type CharacterClass =
| ClassRangesCharacterClass
| UnicodeSetsCharacterClass
interface BaseCharacterClass extends NodeBase {
type BaseCharacterClass = NodeBase & {
type: "CharacterClass"
parent:
| Alternative
Expand All @@ -204,7 +204,7 @@
*
* In Unicode sets mode (`v` flag), {@link UnicodeSetsCharacterClass} is used.
*/
export interface ClassRangesCharacterClass extends BaseCharacterClass {
export type ClassRangesCharacterClass = BaseCharacterClass & {
parent: Alternative | Quantifier
unicodeSets: false
elements: ClassRangesCharacterClassElement[]
Expand All @@ -214,7 +214,7 @@
*
* This character class may contain strings.
*/
export interface UnicodeSetsCharacterClass extends BaseCharacterClass {
export type UnicodeSetsCharacterClass = BaseCharacterClass & {
parent:
| Alternative
| ExpressionCharacterClass
Expand All @@ -228,7 +228,7 @@
* The character class.
* E.g. `[a-b]`
*/
export interface CharacterClassRange extends NodeBase {
export type CharacterClassRange = NodeBase & {
type: "CharacterClassRange"
parent: CharacterClass
min: Character
Expand All @@ -249,7 +249,7 @@
* The edge boundary assertion.
* E.g. `^`, `$`
*/
export interface EdgeAssertion extends NodeBase {
export type EdgeAssertion = NodeBase & {
type: "Assertion"
parent: Alternative | Quantifier
kind: "end" | "start"
Expand All @@ -259,7 +259,7 @@
* The word bondary assertion.
* E.g. `\b`, `\B`
*/
export interface WordBoundaryAssertion extends NodeBase {
export type WordBoundaryAssertion = NodeBase & {
type: "Assertion"
parent: Alternative | Quantifier
kind: "word"
Expand All @@ -278,7 +278,7 @@
* The dot.
* E.g. `.`
*/
export interface AnyCharacterSet extends NodeBase {
export type AnyCharacterSet = NodeBase & {
type: "CharacterSet"
parent: Alternative | Quantifier
kind: "any"
Expand All @@ -288,7 +288,7 @@
* The character class escape.
* E.g. `\d`, `\s`, `\w`, `\D`, `\S`, `\W`
*/
export interface EscapeCharacterSet extends NodeBase {
export type EscapeCharacterSet = NodeBase & {
type: "CharacterSet"
parent:
| Alternative
Expand All @@ -307,7 +307,7 @@
export type UnicodePropertyCharacterSet =
| CharacterUnicodePropertyCharacterSet
| StringsUnicodePropertyCharacterSet
interface BaseUnicodePropertyCharacterSet extends NodeBase {
type BaseUnicodePropertyCharacterSet = NodeBase & {
type: "CharacterSet"
parent:
| Alternative
Expand All @@ -321,31 +321,31 @@
value: string | null
negate: boolean
}
export interface CharacterUnicodePropertyCharacterSet
extends BaseUnicodePropertyCharacterSet {
strings: false
value: string | null
negate: boolean
}
export type CharacterUnicodePropertyCharacterSet =
BaseUnicodePropertyCharacterSet & {
strings: false
value: string | null
negate: boolean
}
/** StringsUnicodePropertyCharacterSet is Unicode property escape with property of strings. */
export interface StringsUnicodePropertyCharacterSet
extends BaseUnicodePropertyCharacterSet {
parent:
| Alternative
| ClassIntersection
| ClassSubtraction
| Quantifier
| UnicodeSetsCharacterClass
strings: true
value: null
negate: false
}
export type StringsUnicodePropertyCharacterSet =
BaseUnicodePropertyCharacterSet & {
parent:
| Alternative
| ClassIntersection
| ClassSubtraction
| Quantifier
| UnicodeSetsCharacterClass
strings: true
value: null
negate: false
}

/**
* The expression character class.
* E.g. `[a--b]`, `[a&&b]`,`[^a--b]`, `[^a&&b]`
*/
export interface ExpressionCharacterClass extends NodeBase {
export type ExpressionCharacterClass = NodeBase & {
type: "ExpressionCharacterClass"
parent:
| Alternative
Expand All @@ -368,7 +368,7 @@
* The character class intersection.
* E.g. `a&&b`
*/
export interface ClassIntersection extends NodeBase {
export type ClassIntersection = NodeBase & {
type: "ClassIntersection"
parent: ClassIntersection | ExpressionCharacterClass
left: ClassIntersection | ClassSetOperand
Expand All @@ -379,7 +379,7 @@
* The character class subtraction.
* E.g. `a--b`
*/
export interface ClassSubtraction extends NodeBase {
export type ClassSubtraction = NodeBase & {
type: "ClassSubtraction"
parent: ClassSubtraction | ExpressionCharacterClass
left: ClassSetOperand | ClassSubtraction
Expand All @@ -390,14 +390,14 @@
* The character class string disjunction.
* E.g. `\q{a|b}`
*/
export interface ClassStringDisjunction extends NodeBase {
export type ClassStringDisjunction = NodeBase & {
type: "ClassStringDisjunction"
parent: ClassIntersection | ClassSubtraction | UnicodeSetsCharacterClass
alternatives: StringAlternative[]
}

/** StringAlternative is only used for `\q{alt}`({@link ClassStringDisjunction}). */
export interface StringAlternative extends NodeBase {
export type StringAlternative = NodeBase & {
type: "StringAlternative"
parent: ClassStringDisjunction
elements: Character[]
Expand All @@ -408,7 +408,7 @@
* This includes escape sequences which mean a character.
* E.g. `a`, `あ`, `✿`, `\x65`, `\u0065`, `\u{65}`, `\/`
*/
export interface Character extends NodeBase {
export type Character = NodeBase & {
type: "Character"
parent:
| Alternative
Expand All @@ -425,7 +425,7 @@
* The backreference.
* E.g. `\1`, `\k<name>`
*/
export interface Backreference extends NodeBase {
export type Backreference = NodeBase & {
type: "Backreference"
parent: Alternative | Quantifier
ref: number | string
Expand All @@ -435,7 +435,7 @@
/**
* The flags.
*/
export interface Flags extends NodeBase {
export type Flags = NodeBase & {
type: "Flags"
parent: RegExpLiteral | null
dotAll: boolean
Expand Down
Loading