Skip to content

Commit

Permalink
feat(nodes): ThrowStatement
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 17ab0b9 commit 9c0de9f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/content/__tests__/statement.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import type {
DoWhileStatement,
EmptyStatement,
ExpressionStatement,
IfStatement
IfStatement,
ThrowStatement
} from '@flex-development/esast'
import type * as TestSubject from '../statement'

Expand Down Expand Up @@ -64,5 +65,10 @@ describe('unit-d:content/statement', () => {
expectTypeOf<TestSubject.StatementMap>()
.toMatchTypeOf<NodeObject<IfStatement>>()
})

it('should match NodeObject<ThrowStatement>', () => {
expectTypeOf<TestSubject.StatementMap>()
.toMatchTypeOf<NodeObject<ThrowStatement>>()
})
})
})
4 changes: 3 additions & 1 deletion src/content/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import type {
DoWhileStatement,
EmptyStatement,
ExpressionStatement,
IfStatement
IfStatement,
ThrowStatement
} from '@flex-development/esast'

/**
Expand Down Expand Up @@ -43,6 +44,7 @@ interface StatementMap {
emptyStatement: EmptyStatement
expressionStatement: ExpressionStatement
ifStatement: IfStatement
throwStatement: ThrowStatement
}

export type { Statement, StatementMap }
41 changes: 41 additions & 0 deletions src/nodes/__tests__/statement-throw.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @file Type Tests - ThrowStatement
* @module esast/nodes/tests/unit-d/ThrowStatement
*/

import type { Data, Expression, Parent } from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'
import type * as TestSubject from '../statement-throw'

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

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

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

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

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

describe('ThrowStatementData', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})
})
})
4 changes: 4 additions & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ export type {
ExpressionStatementData
} from './statement-expression'
export type { default as IfStatement, IfStatementData } from './statement-if'
export type {
default as ThrowStatement,
ThrowStatementData
} from './statement-throw'
46 changes: 46 additions & 0 deletions src/nodes/statement-throw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @file Nodes - ThrowStatement
* @module esast/nodes/ThrowStatement
*/

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

/**
* Info associated with `throw` statements.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface ThrowStatementData extends Data {}

/**
* A `throw` statement.
*
* @see {@linkcode Parent}
*
* @extends {Parent}
*/
interface ThrowStatement extends Parent {
/**
* List of children.
*
* @see {@linkcode Expression}
*/
children: [argument: Expression]

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

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

export type { ThrowStatementData, ThrowStatement as default }

0 comments on commit 9c0de9f

Please sign in to comment.