Skip to content

Commit

Permalink
feat(nodes): VariableDeclarator
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 8, 2024
1 parent 3307bbe commit 58ddf01
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/nodes/__tests__/variable-declarator.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @file Type Tests - VariableDeclarator
* @module esast/nodes/tests/unit-d/VariableDeclarator
*/

import type { Data, Expression, Parent, Pattern } from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'
import type * as TestSubject from '../variable-declarator'

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

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

it('should match [children: [Pattern, Expression] | [Pattern]]', () => {
expectTypeOf<Subject>()
.toHaveProperty('children')
.toEqualTypeOf<[Pattern, Expression] | [Pattern]>()
})

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

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

describe('VariableDeclaratorData', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})
})
})
4 changes: 4 additions & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ export type {
export type { default as Super, SuperData } from './super'
export type { default as SwitchCase, SwitchCaseData } from './switch-case'
export type { default as This, ThisData } from './this'
export type {
default as VariableDeclarator,
VariableDeclaratorData
} from './variable-declarator'
47 changes: 47 additions & 0 deletions src/nodes/variable-declarator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @file Nodes - VariableDeclarator
* @module esast/nodes/VariableDeclarator
*/

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

/**
* Info associated with variable declarators.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface VariableDeclaratorData extends Data {}

/**
* A variable declarator.
*
* @see {@linkcode Parent}
*
* @extends {Parent}
*/
interface VariableDeclarator extends Parent {
/**
* List of children.
*
* @see {@linkcode Expression}
* @see {@linkcode Pattern}
*/
children: [id: Pattern, init: Expression] | [id: Pattern]

/**
* Info from the ecosystem.
*
* @see {@linkcode VariableDeclaratorData}
*/
data?: Optional<VariableDeclaratorData>

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

export type { VariableDeclaratorData, VariableDeclarator as default }

0 comments on commit 58ddf01

Please sign in to comment.