Skip to content

Commit

Permalink
feat(nodes): Identifier
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 2c0b95a commit 8cb7e57
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/nodes/__tests__/identifier.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file Type Tests - Identifier
* @module esast/nodes/tests/unit-d/Identifier
*/

import type { Data, Node } from '@flex-development/esast'
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

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

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

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

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

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

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

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

/**
* Info associated with identifiers.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface IdentifierData extends Data {
/**
* Private identifier?
*/
private?: Nilable<boolean>
}

/**
* An identifier.
*
* @see {@linkcode Node}
*
* @extends {Node}
*/
interface Identifier extends Node {
/**
* Info from the ecosystem.
*
* @see {@linkcode IdentifierData}
*/
data?: Optional<IdentifierData>

/**
* Identifier name.
*/
name: string

/**
* Node type.
*/
type: 'identifier'
}

export type { IdentifierData, Identifier 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 Identifier, IdentifierData } from './identifier'
export type { default as Literal } from './literal'
export type { default as BigIntLiteral } from './literal-bigint'
export type { default as BooleanLiteral } from './literal-boolean'
Expand Down

0 comments on commit 8cb7e57

Please sign in to comment.