Skip to content

Commit

Permalink
feat(nodes): Root
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 9, 2024
1 parent 1fbe902 commit 0a118cb
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/nodes/__tests__/root.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @file Type Tests - Root
* @module esast/nodes/tests/unit-d/Root
*/

import type {
Data,
EcmaVersion,
Parent,
RootChild,
SourceMode
} from '@flex-development/esast'
import type { Nilable, Optional } from '@flex-development/tutils'
import type * as TestSubject from '../root'

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

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

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

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

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

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

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

it('should match [ecmaVersion?: Nilable<EcmaVersion>]', () => {
expectTypeOf<SubjectData>()
.toHaveProperty('ecmaVersion')
.toEqualTypeOf<Nilable<EcmaVersion>>()
})
})
})
1 change: 1 addition & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export type {
} from './pattern-object'
export type { default as Property, PropertyData } from './property'
export type { default as MetaProperty, MetaPropertyData } from './property-meta'
export type { default as Root, RootData } from './root'
export type {
default as BlockStatement,
BlockStatementData
Expand Down
68 changes: 68 additions & 0 deletions src/nodes/root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @file Nodes - Root
* @module esast/nodes/Root
*/

import type {
Data,
EcmaVersion,
Parent,
RootChild,
SourceMode
} from '@flex-development/esast'
import type { Nilable, Optional } from '@flex-development/tutils'

/**
* Info associated with documents.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface RootData extends Data {
/**
* ECMAScript version of source document.
*
* @see {@linkcode EcmaVersion}
*/
ecmaVersion?: Nilable<EcmaVersion>
}

/**
* A document fragment or whole document.
*
* Should be used as the root of a tree; must not be used as a child.
*
* @see {@linkcode Parent}
*
* @extends {Parent}
*/
interface Root extends Parent {
/**
* List of children.
*
* @see {@linkcode RootChild}
*/
children: RootChild[]

/**
* Data associated with esast root.
*
* @see {@linkcode RootData}
*/
data?: Optional<RootData>

/**
* Mode source document was parsed in.
*
* @see {@linkcode SourceMode}
*/
mode: SourceMode

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

export type { RootData, Root as default }

0 comments on commit 0a118cb

Please sign in to comment.