Skip to content

Commit 2065353

Browse files
committed
feat(types): Transform
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent c956ac9 commit 2065353

File tree

7 files changed

+50
-16
lines changed

7 files changed

+50
-16
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
*/
55

66
export type { Options } from './interfaces'
7+
export type { Transform } from './types'
78
export { default as fromDocs } from './util'

src/interfaces/__tests__/options.spec-d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @module docast-util-from-docs/interfaces/tests/unit-d/Options
44
*/
55

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

31-
it('should match [transforms?: Nilable<Fn<[Root], void>[]>]', () => {
31+
it('should match [transforms?: Nilable<Transform[]>]', () => {
3232
expectTypeOf<TestSubject>()
3333
.toHaveProperty('transforms')
34-
.toEqualTypeOf<Nilable<Fn<[Root], void>[]>>()
34+
.toEqualTypeOf<Nilable<Transform[]>>()
3535
})
3636
})

src/interfaces/options.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @module docast-util-from-docs/interfaces/Options
44
*/
55

6-
import type { Root } from '@flex-development/docast'
7-
import type { Fn, Nilable, OneOrMany } from '@flex-development/tutils'
6+
import type { Transform } from '#src/types'
7+
import type { Nilable, OneOrMany } from '@flex-development/tutils'
88
import type { Code } from 'mdast'
99
import type * as mdast from 'mdast-util-from-markdown'
1010
import type * as micromark from 'micromark-util-types'
@@ -41,9 +41,9 @@ interface Options {
4141
/**
4242
* Tree transforms.
4343
*
44-
* @see {@linkcode Root}
44+
* @see {@linkcode Transform}
4545
*/
46-
transforms?: Nilable<Fn<[tree: Root], void>[]>
46+
transforms?: Nilable<Transform[]>
4747
}
4848

4949
export type { Options as default }

src/parser.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
template,
3232
trim,
3333
type Assign,
34-
type Fn,
3534
type Nilable,
3635
type Optional
3736
} from '@flex-development/tutils'
@@ -64,7 +63,7 @@ import type { VFile } from 'vfile'
6463
import { TokenKind } from './enums'
6564
import type { Options, Token } from './interfaces'
6665
import Lexer from './lexer'
67-
import type { UncommentReplacer } from './types'
66+
import type { Transform, UncommentReplacer } from './types'
6867

6968
declare module 'mdast' {
7069
interface BreakData {
@@ -1019,13 +1018,9 @@ class Parser {
10191018
/**
10201019
* Tree transforms.
10211020
*
1022-
* @const {Fn<[Root], void>[]} transforms
1021+
* @const {Transform[]} transforms
10231022
*/
1024-
const transforms: Fn<[tree: Root], void>[] = fallback(
1025-
this.options.transforms,
1026-
[],
1027-
isNIL
1028-
)
1023+
const transforms: Transform[] = fallback(this.options.transforms, [], isNIL)
10291024

10301025
/**
10311026
* Dump paragraphs.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @file Type Tests - Transform
3+
* @module docast-util-from-docs/types/tests/unit-d/Transform
4+
*/
5+
6+
import type { Root } from '@flex-development/docast'
7+
import type TestSubject from '../transform'
8+
9+
describe('unit-d:types/Transform', () => {
10+
it('should be callable with [Root]', () => {
11+
expectTypeOf<TestSubject>().parameters.toEqualTypeOf<[Root]>()
12+
})
13+
14+
it('should return void', () => {
15+
expectTypeOf<TestSubject>().returns.toBeVoid()
16+
})
17+
})

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
* @module docast-util-from-docs/types
44
*/
55

6+
export type { default as Transform } from './transform'
67
export type { default as UncommentReplacer } from './uncomment-replacer'

src/types/transform.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @file Type Definitions - Transform
3+
* @module docast-util-from-docs/types/Transform
4+
*/
5+
6+
import type { Root } from '@flex-development/docast'
7+
8+
/**
9+
* Transform the docblock syntax `tree`.
10+
*
11+
* @see {@linkcode Root}
12+
*
13+
* @this {void}
14+
*
15+
* @param {Root} tree - docast tree
16+
* @return {void} Nothing
17+
*/
18+
type Transform = (this: void, tree: Root) => void
19+
20+
export type { Transform as default }

0 commit comments

Comments
 (0)