Skip to content

Commit

Permalink
feat(nodes): Directive
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Mar 7, 2024
1 parent 3e6045b commit 423d0bf
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 13 deletions.
37 changes: 37 additions & 0 deletions src/nodes/__tests__/directive.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file Type Tests - Directive
* @module esast/nodes/tests/unit-d/Directive
*/

import type { Data, Literal } from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'
import type * as TestSubject from '../directive'

describe('unit-d:nodes/Directive', () => {
type Subject = TestSubject.default
type SubjectData = TestSubject.DirectiveData

it('should extend Literal', () => {
expectTypeOf<Subject>().toMatchTypeOf<Literal>()
})

it('should match [data?: Optional<DirectiveData>]', () => {
expectTypeOf<Subject>()
.toHaveProperty('data')
.toEqualTypeOf<Optional<SubjectData>>()
})

it('should match [type: "directive"]', () => {
expectTypeOf<Subject>().toHaveProperty('type').toEqualTypeOf<'directive'>()
})

it('should match [value: string]', () => {
expectTypeOf<Subject>().toHaveProperty('value').toEqualTypeOf<string>()
})

describe('DirectiveData', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})
})
})
22 changes: 9 additions & 13 deletions src/nodes/__tests__/identifier.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,34 @@ import type { Nilable, Optional } from '@flex-development/tutils'
import type * as TestSubject from '../identifier'

describe('unit-d:nodes/Identifier', () => {
type Identifier = TestSubject.default
type IdentifierData = TestSubject.IdentifierData
type Subject = TestSubject.default
type SubjectData = TestSubject.IdentifierData

it('should extend Node', () => {
expectTypeOf<Identifier>().toMatchTypeOf<Node>()
expectTypeOf<Subject>().toMatchTypeOf<Node>()
})

it('should match [data?: Optional<IdentifierData>]', () => {
expectTypeOf<Identifier>()
expectTypeOf<Subject>()
.toHaveProperty('data')
.toEqualTypeOf<Optional<IdentifierData>>()
.toEqualTypeOf<Optional<SubjectData>>()
})

it('should match [name: string]', () => {
expectTypeOf<Identifier>()
.toHaveProperty('name')
.toEqualTypeOf<string>()
expectTypeOf<Subject>().toHaveProperty('name').toEqualTypeOf<string>()
})

it('should match [type: "identifier"]', () => {
expectTypeOf<Identifier>()
.toHaveProperty('type')
.toEqualTypeOf<'identifier'>()
expectTypeOf<Subject>().toHaveProperty('type').toEqualTypeOf<'identifier'>()
})

describe('IdentifierData', () => {
it('should extend Data', () => {
expectTypeOf<IdentifierData>().toMatchTypeOf<Data>()
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})

it('should match [private?: Nilable<boolean>]', () => {
expectTypeOf<IdentifierData>()
expectTypeOf<SubjectData>()
.toHaveProperty('private')
.toEqualTypeOf<Nilable<boolean>>()
})
Expand Down
44 changes: 44 additions & 0 deletions src/nodes/directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @file Nodes - Directive
* @module esast/nodes/Directive
*/

import type { Data, Literal } from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'

/**
* Info associated with directives.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface DirectiveData extends Data {}

/**
* A directive.
*
* @see {@linkcode Literal}
*
* @extends {Literal}
*/
interface Directive extends Literal {
/**
* Info from the ecosystem.
*
* @see {@linkcode DirectiveData}
*/
data?: Optional<DirectiveData>

/**
* Node type.
*/
type: 'directive'

/**
* The parsed directive.
*/
value: string
}

export type { DirectiveData, Directive as default }
1 change: 1 addition & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @see https://github.com/syntax-tree/unist#nodes
*/

export type { default as Directive, DirectiveData } from './directive'
export type { default as Identifier, IdentifierData } from './identifier'
export type { default as DefaultIdentifier } from './identifier-default'
export type { default as ImportIdentifier } from './identifier-import'
Expand Down

0 comments on commit 423d0bf

Please sign in to comment.