Skip to content

Commit

Permalink
feat(content): PrimitiveMap, Primitive
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Mar 7, 2024
1 parent 423d0bf commit 7b527dd
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions .commitlintrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const config: UserConfig = {
rules: {
'scope-enum': [Severity.Error, 'always', scopes([
'chore',
'content',
'data',
'nodes',
'spec'
Expand Down
61 changes: 61 additions & 0 deletions src/content/__tests__/primitive.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* @file Type Tests - primitive
* @module esast/content/tests/unit-d/primitive
*/

import type {
BigIntLiteral,
BooleanLiteral,
NullLiteral,
NumberLiteral,
StringLiteral,
UndefinedLiteral
} from '@flex-development/esast'
import type * as TestSubject from '../primitive'

describe('unit-d:content/primitive', () => {
describe('Primitive', () => {
it('should equal PrimitiveMap[keyof PrimitiveMap]', () => {
expectTypeOf<TestSubject.Primitive>()
.toEqualTypeOf<TestSubject.PrimitiveMap[keyof TestSubject.PrimitiveMap]>
})
})

describe('PrimitiveMap', () => {
it('should match [bigint: BigIntLiteral]', () => {
expectTypeOf<TestSubject.PrimitiveMap>()
.toHaveProperty('bigint')
.toEqualTypeOf<BigIntLiteral>
})

it('should match [boolean: BooleanLiteral]', () => {
expectTypeOf<TestSubject.PrimitiveMap>()
.toHaveProperty('boolean')
.toEqualTypeOf<BooleanLiteral>
})

it('should match [null: NullLiteral]', () => {
expectTypeOf<TestSubject.PrimitiveMap>()
.toHaveProperty('null')
.toEqualTypeOf<NullLiteral>
})

it('should match [number: NumberLiteral]', () => {
expectTypeOf<TestSubject.PrimitiveMap>()
.toHaveProperty('number')
.toEqualTypeOf<NumberLiteral>
})

it('should match [string: StringLiteral]', () => {
expectTypeOf<TestSubject.PrimitiveMap>()
.toHaveProperty('string')
.toEqualTypeOf<StringLiteral>
})

it('should match [undefined: UndefinedLiteral]', () => {
expectTypeOf<TestSubject.PrimitiveMap>()
.toHaveProperty('undefined')
.toEqualTypeOf<UndefinedLiteral>
})
})
})
6 changes: 6 additions & 0 deletions src/content/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @file Entry Point - Content Model
* @module esast/content
*/

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

import type {
BigIntLiteral,
BooleanLiteral,
NullLiteral,
NumberLiteral,
StringLiteral,
UndefinedLiteral
} from '@flex-development/esast'

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

/**
* Registry of nodes that can occur where a {@linkcode Primitive} is expected.
*
* This interface can be augmented to register custom node types.
*
* @example
* declare module '@flex-development/docast' {
* interface PrimitiveMap {
* custom: CustomPrimitive
* }
* }
*/
interface PrimitiveMap {
bigint: BigIntLiteral
boolean: BooleanLiteral
null: NullLiteral
number: NumberLiteral
string: StringLiteral
undefined: UndefinedLiteral
}

export type { Primitive, PrimitiveMap }
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @module esast
*/

export type * from './content'
export type * from './data'
export type * from './nodes'
export type * from './types'

0 comments on commit 7b527dd

Please sign in to comment.