Skip to content

Commit

Permalink
feat(types): Transform
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 20, 2024
1 parent c956ac9 commit 2065353
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -4,4 +4,5 @@
*/

export type { Options } from './interfaces'
export type { Transform } from './types'
export { default as fromDocs } from './util'
8 changes: 4 additions & 4 deletions src/interfaces/__tests__/options.spec-d.ts
Expand Up @@ -3,8 +3,8 @@
* @module docast-util-from-docs/interfaces/tests/unit-d/Options
*/

import type { Root } from '@flex-development/docast'
import type { Fn, Nilable, OneOrMany } from '@flex-development/tutils'
import type { Transform } from '#src/types'
import type { Nilable, OneOrMany } from '@flex-development/tutils'
import type * as mdast from 'mdast-util-from-markdown'
import type * as micromark from 'micromark-util-types'
import type TestSubject from '../options'
Expand All @@ -28,9 +28,9 @@ describe('unit-d:interfaces/Options', () => {
.toEqualTypeOf<Nilable<micromark.Extension[]>>()
})

it('should match [transforms?: Nilable<Fn<[Root], void>[]>]', () => {
it('should match [transforms?: Nilable<Transform[]>]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('transforms')
.toEqualTypeOf<Nilable<Fn<[Root], void>[]>>()
.toEqualTypeOf<Nilable<Transform[]>>()
})
})
8 changes: 4 additions & 4 deletions src/interfaces/options.ts
Expand Up @@ -3,8 +3,8 @@
* @module docast-util-from-docs/interfaces/Options
*/

import type { Root } from '@flex-development/docast'
import type { Fn, Nilable, OneOrMany } from '@flex-development/tutils'
import type { Transform } from '#src/types'
import type { Nilable, OneOrMany } from '@flex-development/tutils'
import type { Code } from 'mdast'
import type * as mdast from 'mdast-util-from-markdown'
import type * as micromark from 'micromark-util-types'
Expand Down Expand Up @@ -41,9 +41,9 @@ interface Options {
/**
* Tree transforms.
*
* @see {@linkcode Root}
* @see {@linkcode Transform}
*/
transforms?: Nilable<Fn<[tree: Root], void>[]>
transforms?: Nilable<Transform[]>
}

export type { Options as default }
11 changes: 3 additions & 8 deletions src/parser.ts
Expand Up @@ -31,7 +31,6 @@ import {
template,
trim,
type Assign,
type Fn,
type Nilable,
type Optional
} from '@flex-development/tutils'
Expand Down Expand Up @@ -64,7 +63,7 @@ import type { VFile } from 'vfile'
import { TokenKind } from './enums'
import type { Options, Token } from './interfaces'
import Lexer from './lexer'
import type { UncommentReplacer } from './types'
import type { Transform, UncommentReplacer } from './types'

declare module 'mdast' {
interface BreakData {
Expand Down Expand Up @@ -1019,13 +1018,9 @@ class Parser {
/**
* Tree transforms.
*
* @const {Fn<[Root], void>[]} transforms
* @const {Transform[]} transforms
*/
const transforms: Fn<[tree: Root], void>[] = fallback(
this.options.transforms,
[],
isNIL
)
const transforms: Transform[] = fallback(this.options.transforms, [], isNIL)

/**
* Dump paragraphs.
Expand Down
17 changes: 17 additions & 0 deletions src/types/__tests__/transform.spec-d.ts
@@ -0,0 +1,17 @@
/**
* @file Type Tests - Transform
* @module docast-util-from-docs/types/tests/unit-d/Transform
*/

import type { Root } from '@flex-development/docast'
import type TestSubject from '../transform'

describe('unit-d:types/Transform', () => {
it('should be callable with [Root]', () => {
expectTypeOf<TestSubject>().parameters.toEqualTypeOf<[Root]>()
})

it('should return void', () => {
expectTypeOf<TestSubject>().returns.toBeVoid()
})
})
1 change: 1 addition & 0 deletions src/types/index.ts
Expand Up @@ -3,4 +3,5 @@
* @module docast-util-from-docs/types
*/

export type { default as Transform } from './transform'
export type { default as UncommentReplacer } from './uncomment-replacer'
20 changes: 20 additions & 0 deletions src/types/transform.ts
@@ -0,0 +1,20 @@
/**
* @file Type Definitions - Transform
* @module docast-util-from-docs/types/Transform
*/

import type { Root } from '@flex-development/docast'

/**
* Transform the docblock syntax `tree`.
*
* @see {@linkcode Root}
*
* @this {void}
*
* @param {Root} tree - docast tree
* @return {void} Nothing
*/
type Transform = (this: void, tree: Root) => void

export type { Transform as default }

0 comments on commit 2065353

Please sign in to comment.