Skip to content

Commit

Permalink
feat(content): Expression, ExpressionMap
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 ce857ce commit d49b280
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/content/__tests__/expression.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @file Type Tests - expression
* @module esast/content/tests/unit-d/expression
*/

import type { Identifier, LiteralMap } from '@flex-development/esast'
import type * as TestSubject from '../expression'

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

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

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

it('should match [identifier: Identifier]', () => {
expectTypeOf<TestSubject.ExpressionMap>()
.toHaveProperty('identifier')
.toEqualTypeOf<Identifier>
})
})
})
35 changes: 35 additions & 0 deletions src/content/expression.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file Content - expression
* @module esast/content/expression
*/

import type { Identifier, LiteralMap } from '@flex-development/esast'

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

/**
* Registry of nodes that can occur where an {@linkcode Expression} is expected.
*
* This interface can be augmented to register custom node types.
*
* @example
* declare module '@flex-development/docast' {
* interface ExpressionMap {
* customExpression: CustomExpression
* }
* }
*
* @extends {LiteralMap}
*/
interface ExpressionMap extends LiteralMap {
identifier: Identifier
}

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

export type * from './expression'
export type * from './literal'
export type * from './pattern'
export type * from './primitive'
Expand Down

0 comments on commit d49b280

Please sign in to comment.