Skip to content

Commit

Permalink
feat(content): ModuleDeclaration, ModuleDeclarationMap
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 a72c6aa commit 8f0c0be
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
27 changes: 27 additions & 0 deletions src/content/__tests__/declaration-module.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @file Type Tests - moduleDeclaration
* @module esast/content/tests/unit-d/moduleDeclaration
*/

import type { ExportDeclarationMap } from '@flex-development/esast'
import type * as TestSubject from '../declaration-module'

describe('unit-d:content/moduleDeclaration', () => {
describe('ModuleDeclaration', () => {
it('should equal ModuleDeclarationMap[keyof ModuleDeclarationMap]', () => {
// Arrange
type K = keyof TestSubject.ModuleDeclarationMap
type Expect = TestSubject.ModuleDeclarationMap[K]

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

describe('ModuleDeclarationMap', () => {
it('should extend ExportDeclarationMap', () => {
expectTypeOf<TestSubject.ModuleDeclarationMap>()
.toMatchTypeOf<ExportDeclarationMap>()
})
})
})
11 changes: 10 additions & 1 deletion src/content/__tests__/root.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
*/

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

describe('unit-d:content/root', () => {
Expand All @@ -19,6 +24,10 @@ describe('unit-d:content/root', () => {
})

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

it('should extend StatementMap', () => {
expectTypeOf<TestSubject.RootMap>().toMatchTypeOf<StatementMap>()
})
Expand Down
32 changes: 32 additions & 0 deletions src/content/declaration-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @file Content - moduleDeclaration
* @module esast/content/moduleDeclaration
*/

import type { ExportDeclarationMap } from '@flex-development/esast'

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

/**
* Registry of nodes that can occur where a {@linkcode ModuleDeclaration} is
* expected.
*
* This interface can be augmented to register custom node types.
*
* @example
* declare module '@flex-development/esast' {
* interface ModuleDeclarationMap {
* customModuleDeclaration: CustomModuleDeclaration
* }
* }
*/
interface ModuleDeclarationMap extends ExportDeclarationMap {}

export type { ModuleDeclaration, ModuleDeclarationMap }
1 change: 1 addition & 0 deletions src/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

export type * from './declaration'
export type * from './declaration-export'
export type * from './declaration-module'
export type * from './expression'
export type * from './heritage'
export type * from './literal'
Expand Down
14 changes: 10 additions & 4 deletions src/content/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
* @module esast/content/root
*/

import type { Comment, Directive, StatementMap } from '@flex-development/esast'
import type {
Comment,
Directive,
ModuleDeclarationMap,
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.
* To register custom esast nodes, augment {@linkcode RootMap}. They will be
* added to this union automatically.
*/
type RootChild = RootMap[keyof RootMap]

Expand All @@ -26,9 +31,10 @@ type RootChild = RootMap[keyof RootMap]
* }
* }
*
* @extends {ModuleDeclarationMap}
* @extends {StatementMap}
*/
interface RootMap extends StatementMap {
interface RootMap extends ModuleDeclarationMap, StatementMap {
comment: Comment
directive: Directive
}
Expand Down

0 comments on commit 8f0c0be

Please sign in to comment.