Skip to content

Commit

Permalink
feat(nodes): StaticBlock
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 7e234fe commit 4e6af0f
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/content/__tests__/statement.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
IfStatement,
LabeledStatement,
ReturnStatement,
StaticBlock,
SwitchStatement,
ThrowStatement,
TryStatement,
Expand Down Expand Up @@ -105,6 +106,11 @@ describe('unit-d:content/statement', () => {
.toMatchTypeOf<NodeObject<ReturnStatement>>()
})

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

it('should match NodeObject<SwitchStatement>', () => {
expectTypeOf<TestSubject.StatementMap>()
.toMatchTypeOf<NodeObject<SwitchStatement>>()
Expand Down
2 changes: 2 additions & 0 deletions src/content/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
IfStatement,
LabeledStatement,
ReturnStatement,
StaticBlock,
SwitchStatement,
ThrowStatement,
TryStatement,
Expand Down Expand Up @@ -61,6 +62,7 @@ interface StatementMap extends DeclarationMap {
ifStatement: IfStatement
labeledStatement: LabeledStatement
returnStatement: ReturnStatement
staticBlock: StaticBlock
switchStatement: SwitchStatement
throwStatement: ThrowStatement
tryStatement: TryStatement
Expand Down
8 changes: 1 addition & 7 deletions src/nodes/__tests__/statement-block.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Comment, Data, Parent, Statement } from '@flex-development/esast'
import type { Nilable, Optional } from '@flex-development/tutils'
import type { Optional } from '@flex-development/tutils'
import type * as TestSubject from '../statement-block'

describe('unit-d:nodes/BlockStatement', () => {
Expand Down Expand Up @@ -37,11 +37,5 @@ describe('unit-d:nodes/BlockStatement', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})

it('should match [static?: Nilable<boolean>]', () => {
expectTypeOf<SubjectData>()
.toHaveProperty('static')
.toEqualTypeOf<Nilable<boolean>>()
})
})
})
41 changes: 41 additions & 0 deletions src/nodes/__tests__/static-block.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @file Type Tests - StaticBlock
* @module esast/nodes/tests/unit-d/StaticBlock
*/

import type { Comment, Data, Parent, Statement } from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'
import type * as TestSubject from '../static-block'

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

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

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

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

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

describe('StaticBlockData', () => {
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 @@ -202,6 +202,7 @@ export type {
default as WithStatement,
WithStatementData
} from './statement-with'
export type { default as StaticBlock, StaticBlockData } from './static-block'
export type { default as Super, SuperData } from './super'
export type { default as SwitchCase, SwitchCaseData } from './switch-case'
export type {
Expand Down
9 changes: 2 additions & 7 deletions src/nodes/statement-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type { Comment, Data, Parent, Statement } from '@flex-development/esast'
import type { Nilable, Optional } from '@flex-development/tutils'
import type { Optional } from '@flex-development/tutils'

/**
* Info associated with block statements.
Expand All @@ -13,12 +13,7 @@ import type { Nilable, Optional } from '@flex-development/tutils'
*
* @extends {Data}
*/
interface BlockStatementData extends Data {
/**
* Static block statement?
*/
static?: Nilable<boolean>
}
interface BlockStatementData extends Data {}

/**
* A block statement.
Expand Down
49 changes: 49 additions & 0 deletions src/nodes/static-block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @file Nodes - StaticBlock
* @module esast/nodes/StaticBlock
*/

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

/**
* Info associated with static initialization blocks.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface StaticBlockData extends Data {}

/**
* A [static initialization block][1].
*
* [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Classes/Static_initialization_blocks
*
* @see {@linkcode Parent}
*
* @extends {Parent}
*/
interface StaticBlock extends Parent {
/**
* List of children.
*
* @see {@linkcode Comment}
* @see {@linkcode Statement}
*/
children: (Comment | Statement)[]

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

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

export type { StaticBlockData, StaticBlock as default }

0 comments on commit 4e6af0f

Please sign in to comment.