Skip to content

Commit

Permalink
refactor(content): maps
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Feb 10, 2024
1 parent 144bd25 commit 4fdb553
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/content/__tests__/block-tag.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import type { TypeExpression } from '#src/nodes'
import type mdast from 'mdast'
import type * as TestSubject from '../block-tag'
import type { PhrasingContentMap } from '../phrasing'

Expand All @@ -14,6 +15,12 @@ describe('unit-d:content/BlockTag', () => {
.toMatchTypeOf<PhrasingContentMap>()
})

it('should match [code: mdast.Code]', () => {
expectTypeOf<TestSubject.BlockTagContentMap>()
.toHaveProperty('code')
.toEqualTypeOf<mdast.Code>
})

it('should match [typeExpression: TypeExpression]', () => {
expectTypeOf<TestSubject.BlockTagContentMap>()
.toHaveProperty('typeExpression')
Expand Down
24 changes: 18 additions & 6 deletions src/content/__tests__/description.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe('unit-d:content/Description', () => {
.toEqualTypeOf<mdast.Blockquote>
})

it('should match [code: mdast.Code]', () => {
expectTypeOf<TestSubject.DescriptionContentMap>()
.toHaveProperty('code')
.toEqualTypeOf<mdast.Code>
})

it('should match [definition: mdast.Definition]', () => {
expectTypeOf<TestSubject.DescriptionContentMap>()
.toHaveProperty('definition')
Expand All @@ -44,18 +50,24 @@ describe('unit-d:content/Description', () => {
.toEqualTypeOf<mdast.ListItem>
})

it('should match [paragraph: mdast.Paragraph]', () => {
expectTypeOf<TestSubject.DescriptionContentMap>()
.toHaveProperty('paragraph')
.toEqualTypeOf<mdast.Paragraph>
})

it('should match [table: mdast.Table]', () => {
expectTypeOf<TestSubject.DescriptionContentMap>()
.toHaveProperty('table')
.toEqualTypeOf<mdast.Table>
})

it('should match [tableCell: mdast.TableCell]', () => {
expectTypeOf<TestSubject.DescriptionContentMap>()
.toHaveProperty('tableCell')
.toEqualTypeOf<mdast.TableCell>
})

it('should match [tableRow: mdast.TableRow]', () => {
expectTypeOf<TestSubject.DescriptionContentMap>()
.toHaveProperty('tableRow')
.toEqualTypeOf<mdast.TableRow>
})

it('should match [thematicBreak: mdast.ThematicBreak]', () => {
expectTypeOf<TestSubject.DescriptionContentMap>()
.toHaveProperty('thematicBreak')
Expand Down
8 changes: 1 addition & 7 deletions src/content/__tests__/phrasing.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ import type * as TestSubject from '../phrasing'

describe('unit-d:content/Phrasing', () => {
describe('PhrasingContentMap', () => {
it('should extend <mdast.PhrasingContentMap', () => {
it('should extend mdast.PhrasingContentMap', () => {
expectTypeOf<TestSubject.PhrasingContentMap>()
.toMatchTypeOf<mdast.PhrasingContentMap>()
})

it('should match [code: mdast.Code]', () => {
expectTypeOf<TestSubject.PhrasingContentMap>()
.toHaveProperty('code')
.toEqualTypeOf<mdast.Code>
})

it('should match [inlineTag: InlineTag]', () => {
expectTypeOf<TestSubject.PhrasingContentMap>()
.toHaveProperty('inlineTag')
Expand Down
2 changes: 2 additions & 0 deletions src/content/block-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import type { TypeExpression } from '#src/nodes'
import type mdast from 'mdast'
import type { PhrasingContentMap } from './phrasing'

/**
Expand Down Expand Up @@ -31,6 +32,7 @@ type BlockTagContent = BlockTagContentMap[keyof BlockTagContentMap]
* @extends {PhrasingContentMap}
*/
interface BlockTagContentMap extends PhrasingContentMap {
code: mdast.Code
typeExpression: TypeExpression
}

Expand Down
19 changes: 18 additions & 1 deletion src/content/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@
* @module docast/content/Description
*/

import type { InlineTag } from '#src/nodes'
import type mdast from 'mdast'
import type { PhrasingContentMap } from './phrasing'

declare module 'mdast' {
interface BlockContentMap {
inlineTag: InlineTag
}

interface DefinitionContentMap {
inlineTag: InlineTag
}

interface RootContentMap {
inlineTag: InlineTag
}
}

/**
* Union of registered docast nodes that can occur where description content is
* expected.
Expand All @@ -32,12 +47,14 @@ type DescriptionContent = DescriptionContentMap[keyof DescriptionContentMap]
*/
interface DescriptionContentMap extends PhrasingContentMap {
blockquote: mdast.Blockquote
code: mdast.Code
definition: mdast.Definition
footnoteDefinition: mdast.FootnoteDefinition
list: mdast.List
listItem: mdast.ListItem
paragraph: mdast.Paragraph
table: mdast.Table
tableCell: mdast.TableCell
tableRow: mdast.TableRow
thematicBreak: mdast.ThematicBreak
}

Expand Down
11 changes: 7 additions & 4 deletions src/content/phrasing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
import type { InlineTag } from '#src/nodes'
import type mdast from 'mdast'

declare module 'mdast' {
interface PhrasingContentMap {
inlineTag: InlineTag
}
}

/**
* Union of registered docast nodes that can occur where phrasing content is
* expected.
Expand All @@ -30,9 +36,6 @@ type PhrasingContent = PhrasingContentMap[keyof PhrasingContentMap]
*
* @extends {mdast.PhrasingContentMap}
*/
interface PhrasingContentMap extends mdast.PhrasingContentMap {
code: mdast.Code
inlineTag: InlineTag
}
interface PhrasingContentMap extends mdast.PhrasingContentMap {}

export type { PhrasingContent, PhrasingContentMap }

0 comments on commit 4fdb553

Please sign in to comment.