Skip to content

Commit

Permalink
feat(content): LiteralMap, LiteralValue
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 7b527dd commit 70bae5f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/content/__tests__/literal.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @file Type Tests - literal
* @module esast/content/tests/unit-d/literal
*/

import type { PrimitiveMap, RegExpLiteral } from '@flex-development/esast'
import type * as TestSubject from '../literal'

describe('unit-d:content/literal', () => {
describe('LiteralMap', () => {
it('should extend PrimitiveMap', () => {
expectTypeOf<TestSubject.LiteralMap>().toMatchTypeOf<PrimitiveMap>()
})

it('should match [regexp: RegExpLiteral]', () => {
expectTypeOf<TestSubject.LiteralMap>()
.toHaveProperty('regexp')
.toEqualTypeOf<RegExpLiteral>
})
})

describe('LiteralValue', () => {
it('should equal LiteralMap[keyof LiteralMap]', () => {
expectTypeOf<TestSubject.LiteralValue>()
.toEqualTypeOf<TestSubject.LiteralMap[keyof TestSubject.LiteralMap]>
})
})
})
1 change: 1 addition & 0 deletions src/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
* @module esast/content
*/

export type * from './literal'
export type * from './primitive'
36 changes: 36 additions & 0 deletions src/content/literal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* @file Content - literal
* @module esast/content/literal
*/

import type { PrimitiveMap, RegExpLiteral } from '@flex-development/esast'

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

/**
* Registry of nodes that can occur where a {@linkcode LiteralValue} is
* expected.
*
* This interface can be augmented to register custom node types.
*
* @example
* declare module '@flex-development/docast' {
* interface LiteralMap {
* custom: CustomLiteral
* }
* }
*
* @extends {PrimitiveMap}
*/
interface LiteralMap extends PrimitiveMap {
regexp: RegExpLiteral
}

export type { LiteralMap, LiteralValue }

0 comments on commit 70bae5f

Please sign in to comment.