Skip to content

Commit

Permalink
feat(nodes): ChainExpression
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 7abbb11 commit 59a5663
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/content/__tests__/expression.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
AwaitExpression,
BinaryExpression,
CallExpression,
ChainExpression,
FunctionExpression,
Identifier,
LiteralMap,
Expand Down Expand Up @@ -61,6 +62,11 @@ describe('unit-d:content/expression', () => {
.toMatchTypeOf<NodeObject<CallExpression>>()
})

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

it('should match NodeObject<FunctionExpression>', () => {
expectTypeOf<TestSubject.ExpressionMap>()
.toMatchTypeOf<NodeObject<FunctionExpression>>()
Expand Down
2 changes: 2 additions & 0 deletions src/content/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
AwaitExpression,
BinaryExpression,
CallExpression,
ChainExpression,
FunctionExpression,
Identifier,
LiteralMap,
Expand Down Expand Up @@ -47,6 +48,7 @@ interface ExpressionMap extends LiteralMap {
awaitExpression: AwaitExpression
binaryExpression: BinaryExpression
callExpression: CallExpression
chainExpression: ChainExpression
functionExpression: FunctionExpression
identifier: Identifier
memberExpression: MemberExpression
Expand Down
46 changes: 46 additions & 0 deletions src/nodes/__tests__/expression-chain.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @file Type Tests - ChainExpression
* @module esast/nodes/tests/unit-d/ChainExpression
*/

import type {
CallExpression,
Data,
MemberExpression,
Parent
} from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'
import type * as TestSubject from '../expression-chain'

describe('unit-d:nodes/ChainExpression', () => {
type Subject = TestSubject.default
type SubjectData = TestSubject.ChainExpressionData

it('should extend Parent', () => {
expectTypeOf<Subject>().toMatchTypeOf<Parent>()
})

it('should match [children: [CallExpression | MemberExpression]]', () => {
expectTypeOf<Subject>()
.toHaveProperty('children')
.toEqualTypeOf<[CallExpression | MemberExpression]>()
})

it('should match [data?: Optional<ChainExpressionData>]', () => {
expectTypeOf<Subject>()
.toHaveProperty('data')
.toEqualTypeOf<Optional<SubjectData>>()
})

it('should match [type: "chainExpression"]', () => {
expectTypeOf<Subject>()
.toHaveProperty('type')
.toEqualTypeOf<'chainExpression'>()
})

describe('ChainExpressionData', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})
})
})
52 changes: 52 additions & 0 deletions src/nodes/expression-chain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @file Nodes - ChainExpression
* @module esast/nodes/ChainExpression
*/

import type {
CallExpression,
Data,
MemberExpression,
Parent
} from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'

/**
* Info associated with chain expressions.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface ChainExpressionData extends Data {}

/**
* A chain expression.
*
* @see {@linkcode Parent}
*
* @extends {Parent}
*/
interface ChainExpression extends Parent {
/**
* List of children.
*
* @see {@linkcode CallExpression}
* @see {@linkcode MemberExpression}
*/
children: [expression: CallExpression | MemberExpression]

/**
* Info from the ecosystem.
*
* @see {@linkcode ChainExpressionData}
*/
data?: Optional<ChainExpressionData>

/**
* Node type.
*/
type: 'chainExpression'
}

export type { ChainExpressionData, ChainExpression as default }
4 changes: 4 additions & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export type {
default as CallExpression,
CallExpressionData
} from './expression-call'
export type {
default as ChainExpression,
ChainExpressionData
} from './expression-chain'
export type {
default as FunctionExpression,
FunctionExpressionData
Expand Down

0 comments on commit 59a5663

Please sign in to comment.