Skip to content

Commit

Permalink
feat(nodes): This
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 8, 2024
1 parent d923036 commit 7f3b48b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/content/__tests__/expression.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* @module esast/content/tests/unit-d/expression
*/

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

describe('unit-d:content/expression', () => {
Expand All @@ -22,10 +23,14 @@ describe('unit-d:content/expression', () => {
expectTypeOf<TestSubject.ExpressionMap>().toMatchTypeOf<LiteralMap>()
})

it('should match [identifier: Identifier]', () => {
it('should match NodeObject<Identifier>', () => {
expectTypeOf<TestSubject.ExpressionMap>()
.toHaveProperty('identifier')
.toEqualTypeOf<Identifier>
.toMatchTypeOf<NodeObject<Identifier>>()
})

it('should match NodeObject<This>', () => {
expectTypeOf<TestSubject.ExpressionMap>()
.toMatchTypeOf<NodeObject<This>>()
})
})
})
3 changes: 2 additions & 1 deletion src/content/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module esast/content/expression
*/

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

/**
* Union of registered esast nodes that can occur where an expression is
Expand All @@ -30,6 +30,7 @@ type Expression = ExpressionMap[keyof ExpressionMap]
*/
interface ExpressionMap extends LiteralMap {
identifier: Identifier
this: This
}

export type { Expression, ExpressionMap }
33 changes: 33 additions & 0 deletions src/nodes/__tests__/this.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file Type Tests - This
* @module esast/nodes/tests/unit-d/This
*/

import type { Data, Node } from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'
import type * as TestSubject from '../this'

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

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

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

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

describe('ThisData', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})
})
})
1 change: 1 addition & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ export type {
default as ThrowStatement,
ThrowStatementData
} from './statement-throw'
export type { default as This, ThisData } from './this'
39 changes: 39 additions & 0 deletions src/nodes/this.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @file Nodes - This
* @module esast/nodes/This
*/

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

/**
* Info associated with `this` keywords.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface ThisData extends Data {}

/**
* The `this` keyword.
*
* @see {@linkcode Node}
*
* @extends {Node}
*/
interface This extends Node {
/**
* Info from the ecosystem.
*
* @see {@linkcode ThisData}
*/
data?: Optional<ThisData>

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

export type { ThisData, This as default }

0 comments on commit 7f3b48b

Please sign in to comment.