Skip to content

Commit

Permalink
feat(nodes): CatchClause
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Mar 8, 2024
1 parent 9c0de9f commit a9b670b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/nodes/__tests__/catch-clause.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @file Type Tests - CatchClause
* @module esast/nodes/tests/unit-d/CatchClause
*/

import type {
BlockStatement,
Data,
Parent,
Pattern
} from '@flex-development/esast'
import type { Nullable, Optional } from '@flex-development/tutils'
import type * as TestSubject from '../catch-clause'

describe('unit-d:nodes/CatchClause', () => {
type Subject = TestSubject.default
type SubjectData = TestSubject.CatchClauseData

it('should extend Parent', () => {
expectTypeOf<Subject>().toMatchTypeOf<Parent>()
})

it('should match [children: [Nullable<Pattern>, BlockStatement]]', () => {
expectTypeOf<Subject>()
.toHaveProperty('children')
.toEqualTypeOf<[Nullable<Pattern>, BlockStatement]>()
})

it('should match [data?: Optional<CatchClauseData>]', () => {
expectTypeOf<Subject>()
.toHaveProperty('data')
.toEqualTypeOf<Optional<SubjectData>>()
})

it('should match [type: "catchClause"]', () => {
expectTypeOf<Subject>()
.toHaveProperty('type')
.toEqualTypeOf<'catchClause'>()
})

describe('CatchClauseData', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})
})
})
52 changes: 52 additions & 0 deletions src/nodes/catch-clause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @file Nodes - CatchClause
* @module esast/nodes/CatchClause
*/

import type {
BlockStatement,
Data,
Parent,
Pattern
} from '@flex-development/esast'
import type { Nullable, Optional } from '@flex-development/tutils'

/**
* Info associated with `catch` clauses.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface CatchClauseData extends Data {}

/**
* A `catch` clause.
*
* @see {@linkcode Parent}
*
* @extends {Parent}
*/
interface CatchClause extends Parent {
/**
* List of children.
*
* @see {@linkcode BlockStatement}
* @see {@linkcode Pattern}
*/
children: [param: Nullable<Pattern>, body: BlockStatement]

/**
* Info from the ecosystem.
*
* @see {@linkcode CatchClauseData}
*/
data?: Optional<CatchClauseData>

/**
* Node type.
*/
type: 'catchClause'
}

export type { CatchClauseData, CatchClause as default }
1 change: 1 addition & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @see https://github.com/syntax-tree/unist#nodes
*/

export type { default as CatchClause, CatchClauseData } from './catch-clause'
export type {
default as DocblockComment,
DocblockCommentData
Expand Down

0 comments on commit a9b670b

Please sign in to comment.