Skip to content

Commit 4487470

Browse files
committed
feat(nodes): Literal, Node
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 539d9e1 commit 4487470

File tree

13 files changed

+142
-12
lines changed

13 files changed

+142
-12
lines changed

.commitlintrc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { scopes } from '@flex-development/commitlint-config'
1818
const config: UserConfig = {
1919
extends: ['@flex-development'],
2020
rules: {
21-
'scope-enum': [Severity.Error, 'always', scopes(['chore'])]
21+
'scope-enum': [Severity.Error, 'always', scopes(['chore', 'nodes', 'spec'])]
2222
}
2323
}
2424

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
"./package.json": "./package.json"
4848
},
4949
"imports": {
50+
"#interfaces/*": {
51+
"fst": "./src/interfaces/*.mts",
52+
"types": "./dist/interfaces/*.d.mts",
53+
"default": "./dist/interfaces/*.d.mts"
54+
},
5055
"#nodes/*": {
5156
"fst": "./src/nodes/*.mts",
5257
"types": "./dist/nodes/*.d.mts",

src/__tests__/fst.spec-d.mts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/index.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
* @module fst
44
*/
55

6+
export type * from '#interfaces/index'
67
export type * from '#nodes/index'
78
export type * from '#types/index'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @file Type Tests - Data
3+
* @module fst/interfaces/tests/unit-d/Data
4+
*/
5+
6+
import type TestSubject from '#interfaces/data'
7+
import type unist from 'unist'
8+
9+
describe('unit-d:interfaces/Data', () => {
10+
it('should extend unist.Data', () => {
11+
expectTypeOf<TestSubject>().toMatchTypeOf<unist.Data>()
12+
})
13+
})

src/interfaces/data.mts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @file Interfaces - Data
3+
* @module fst/interfaces/Data
4+
*/
5+
6+
import type unist from 'unist'
7+
8+
/**
9+
* Info associated with fst nodes.
10+
*
11+
* This space is guaranteed to never be specified by unist or fst, but it
12+
* can be used in utilities and plugins to store custom data.
13+
*
14+
* @example
15+
* declare module '@flex-development/fst' {
16+
* interface Data {
17+
* // `node.data.url` is typed as `string | undefined`
18+
* url?: string | undefined
19+
* }
20+
* }
21+
*
22+
* @extends {unist.Data}
23+
*/
24+
interface Data extends unist.Data {}
25+
26+
export type { Data as default }

src/interfaces/index.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @file Entry Point - Interfaces
3+
* @module fst/interfaces
4+
*/
5+
6+
export type { default as Data } from '#interfaces/data'

src/nodes/__tests__/.gitkeep

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @file Type Tests - Literal
3+
* @module fst/nodes/tests/unit-d/Literal
4+
*/
5+
6+
import type TestSubject from '#nodes/literal'
7+
import type { Node } from '@flex-development/fst'
8+
import type { Nilable } from '@flex-development/tutils'
9+
10+
describe('unit-d:nodes/Literal', () => {
11+
it('should extend Node', () => {
12+
expectTypeOf<TestSubject>().toMatchTypeOf<Node>()
13+
})
14+
15+
it('should match [value: string | null | undefined]', () => {
16+
expectTypeOf<TestSubject>()
17+
.toHaveProperty('value')
18+
.toEqualTypeOf<Nilable<string>>()
19+
})
20+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @file Type Tests - Node
3+
* @module fst/nodes/tests/unit-d/Node
4+
*/
5+
6+
import type TestSubject from '#nodes/node'
7+
import type { Data } from '@flex-development/fst'
8+
import type { Optional } from '@flex-development/tutils'
9+
import type unist from 'unist'
10+
11+
describe('unit-d:nodes/Node', () => {
12+
it('should extend unist.Node', () => {
13+
expectTypeOf<TestSubject>().toMatchTypeOf<unist.Node>()
14+
})
15+
16+
it('should match [data?: Data | undefined]', () => {
17+
expectTypeOf<TestSubject>()
18+
.toHaveProperty('data')
19+
.toEqualTypeOf<Optional<Data>>()
20+
})
21+
})

0 commit comments

Comments
 (0)