Skip to content

Commit

Permalink
feat(content): RootChild, RootMap
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 8dbae2e commit f849aeb
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/content/__tests__/root.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @file Type Tests - root
* @module esast/content/tests/unit-d/root
*/

import type { NodeObject } from '#tests/types'
import type { Comment, Directive, StatementMap } from '@flex-development/esast'
import type * as TestSubject from '../root'

describe('unit-d:content/root', () => {
describe('RootChild', () => {
it('should equal RootMap[keyof RootMap]', () => {
// Arrange
type Expect = TestSubject.RootMap[keyof TestSubject.RootMap]

// Expect
expectTypeOf<TestSubject.RootChild>().toEqualTypeOf<Expect>
})
})

describe('RootMap', () => {
it('should extend StatementMap', () => {
expectTypeOf<TestSubject.RootMap>().toMatchTypeOf<StatementMap>()
})

it('should match NodeObject<Comment>', () => {
expectTypeOf<TestSubject.RootMap>().toMatchTypeOf<NodeObject<Comment>>()
})

it('should match NodeObject<Directive>', () => {
expectTypeOf<TestSubject.RootMap>().toMatchTypeOf<NodeObject<Directive>>()
})
})
})
2 changes: 1 addition & 1 deletion src/content/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Expression = ExpressionMap[keyof ExpressionMap]
* This interface can be augmented to register custom node types.
*
* @example
* declare module '@flex-development/docast' {
* declare module '@flex-development/esast' {
* interface ExpressionMap {
* customExpression: CustomExpression
* }
Expand Down
1 change: 1 addition & 0 deletions src/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export type * from './expression'
export type * from './literal'
export type * from './pattern'
export type * from './primitive'
export type * from './root'
export type * from './statement'
2 changes: 1 addition & 1 deletion src/content/literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type LiteralValue = LiteralMap[keyof LiteralMap]
* This interface can be augmented to register custom node types.
*
* @example
* declare module '@flex-development/docast' {
* declare module '@flex-development/esast' {
* interface LiteralMap {
* custom: CustomLiteral
* }
Expand Down
2 changes: 1 addition & 1 deletion src/content/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Pattern = PatternMap[keyof PatternMap]
* This interface can be augmented to register custom node types.
*
* @example
* declare module '@flex-development/docast' {
* declare module '@flex-development/esast' {
* interface PatternMap {
* customPattern: CustomPattern
* }
Expand Down
36 changes: 36 additions & 0 deletions src/content/root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @file Content - root
* @module esast/content/root
*/

import type { Comment, Directive, StatementMap } from '@flex-development/esast'

/**
* Union of registered esast nodes that can occur where a root child node is
* expected.
*
* To register custom esast nodes, augment {@linkcode RootMap}. They will
* be added to this union automatically.
*/
type RootChild = RootMap[keyof RootMap]

/**
* Registry of nodes that can occur where a {@linkcode RootChild} is expected.
*
* This interface can be augmented to register custom node types.
*
* @example
* declare module '@flex-development/esast' {
* interface RootMap {
* customNode: CustomNode
* }
* }
*
* @extends {StatementMap}
*/
interface RootMap extends StatementMap {
comment: Comment
directive: Directive
}

export type { RootChild, RootMap }
2 changes: 1 addition & 1 deletion src/content/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Statement = StatementMap[keyof StatementMap]
* This interface can be augmented to register custom node types.
*
* @example
* declare module '@flex-development/docast' {
* declare module '@flex-development/esast' {
* interface StatementMap {
* customStatement: CustomStatement
* }
Expand Down

0 comments on commit f849aeb

Please sign in to comment.