Skip to content

Commit

Permalink
refactor(nodes): [BlockTag] define children as discriminate union
Browse files Browse the repository at this point in the history
- block tags can only have one type expression. that type expression should be the first child in `children`

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Feb 10, 2024
1 parent 4fdb553 commit cd14f96
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/nodes/__tests__/block-tag.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Tag } from '#src/mixins'
import type { Optional } from '@flex-development/tutils'
import type { BlockTagData, default as TestSubject } from '../block-tag'
import type Parent from '../parent'
import type TypeExpression from '../type-expression'

describe('unit-d:nodes/BlockTag', () => {
it('should extend Parent', () => {
Expand All @@ -18,10 +19,21 @@ describe('unit-d:nodes/BlockTag', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<Tag>()
})

it('should match [children: BlockContent[]]', () => {
it('should match [children: Exclude<BlockTagContent, TypeExpression>[]]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('children')
.toEqualTypeOf<BlockTagContent[]>()
.extract<Exclude<BlockTagContent, TypeExpression>[]>()
.toBeArray()
})

it('should match [children: [TypeExpression, ...Exclude<BlockTagContent, TypeExpression>[]]]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('children')
.extract<[
TypeExpression,
...Exclude<BlockTagContent, TypeExpression>[]
]>()
.toBeArray()
})

it('should match [data?: Optional<BlockTagData>]', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/nodes/block-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Data } from '#src/interfaces'
import type { Tag } from '#src/mixins'
import type { Optional } from '@flex-development/tutils'
import type Parent from './parent'
import type TypeExpression from './type-expression'

/**
* Info associated with block tag nodes.
Expand All @@ -33,7 +34,9 @@ interface BlockTag extends Parent, Tag {
*
* @see {@linkcode BlockTagContent}
*/
children: BlockTagContent[]
children:
| Exclude<BlockTagContent, TypeExpression>[]
| [TypeExpression, ...Exclude<BlockTagContent, TypeExpression>[]]

/**
* Data associated with block tag.
Expand Down

0 comments on commit cd14f96

Please sign in to comment.