diff --git a/__tests__/types/index.ts b/__tests__/types/index.ts new file mode 100644 index 0000000..7969cdd --- /dev/null +++ b/__tests__/types/index.ts @@ -0,0 +1,6 @@ +/** + * @file Entry Point - Test Types + * @module tests/types + */ + +export type { default as NodeObject } from './node-object' diff --git a/__tests__/types/node-object.ts b/__tests__/types/node-object.ts new file mode 100644 index 0000000..d4518b0 --- /dev/null +++ b/__tests__/types/node-object.ts @@ -0,0 +1,15 @@ +/** + * @file Test Types - NodeObject + * @module tests/types/NodeObject + */ + +import type { Node } from '@flex-development/esast' + +/** + * Create an object mapping a node type to a node. + * + * @template {Node} T - Node to map + */ +type NodeObject = { [K in T['type']]: T } + +export type { NodeObject as default } diff --git a/src/content/__tests__/statement.spec-d.ts b/src/content/__tests__/statement.spec-d.ts index 7e30e49..1f6e00d 100644 --- a/src/content/__tests__/statement.spec-d.ts +++ b/src/content/__tests__/statement.spec-d.ts @@ -3,7 +3,8 @@ * @module esast/content/tests/unit-d/statement */ -import type { EmptyStatement } from '@flex-development/esast' +import type { NodeObject } from '#tests/types' +import type { BlockStatement, EmptyStatement } from '@flex-development/esast' import type * as TestSubject from '../statement' describe('unit-d:content/statement', () => { @@ -15,10 +16,14 @@ describe('unit-d:content/statement', () => { }) describe('StatementMap', () => { - it('should match [emptyStatement: EmptyStatement]', () => { + it('should match NodeObject', () => { expectTypeOf() - .toHaveProperty('emptyStatement') - .toEqualTypeOf + .toMatchTypeOf>() + }) + + it('should match NodeObject', () => { + expectTypeOf() + .toMatchTypeOf>() }) }) }) diff --git a/src/content/statement.ts b/src/content/statement.ts index 5cc27e8..14b6654 100644 --- a/src/content/statement.ts +++ b/src/content/statement.ts @@ -3,7 +3,7 @@ * @module esast/content/statement */ -import type { EmptyStatement } from '@flex-development/esast' +import type { BlockStatement, EmptyStatement } from '@flex-development/esast' /** * Union of registered esast nodes that can occur where a statement is expected. @@ -26,6 +26,7 @@ type Statement = StatementMap[keyof StatementMap] * } */ interface StatementMap { + blockStatement: BlockStatement emptyStatement: EmptyStatement } diff --git a/src/nodes/__tests__/statement-block.spec-d.ts b/src/nodes/__tests__/statement-block.spec-d.ts new file mode 100644 index 0000000..26d47e5 --- /dev/null +++ b/src/nodes/__tests__/statement-block.spec-d.ts @@ -0,0 +1,47 @@ +/** + * @file Type Tests - BlockStatement + * @module esast/nodes/tests/unit-d/BlockStatement + */ + +import type { Data, Parent, Statement } from '@flex-development/esast' +import type { Nilable, Optional } from '@flex-development/tutils' +import type * as TestSubject from '../statement-block' + +describe('unit-d:nodes/BlockStatement', () => { + type Subject = TestSubject.default + type SubjectData = TestSubject.BlockStatementData + + it('should extend Parent', () => { + expectTypeOf().toMatchTypeOf() + }) + + it('should match [children: Statement[]]', () => { + expectTypeOf() + .toHaveProperty('children') + .toEqualTypeOf() + }) + + it('should match [data?: Optional]', () => { + expectTypeOf() + .toHaveProperty('data') + .toEqualTypeOf>() + }) + + it('should match [type: "blockStatement"]', () => { + expectTypeOf() + .toHaveProperty('type') + .toEqualTypeOf<'blockStatement'>() + }) + + describe('BlockStatementData', () => { + it('should extend Data', () => { + expectTypeOf().toMatchTypeOf() + }) + + it('should match [static?: Nilable]', () => { + expectTypeOf() + .toHaveProperty('static') + .toEqualTypeOf>() + }) + }) +}) diff --git a/src/nodes/index.ts b/src/nodes/index.ts index 87b1fb8..23ebf84 100644 --- a/src/nodes/index.ts +++ b/src/nodes/index.ts @@ -20,6 +20,10 @@ export type { default as StringLiteral } from './literal-string' export type { default as UndefinedLiteral } from './literal-undefined' export type { default as Node } from './node' export type { default as Parent } from './parent' +export type { + default as BlockStatement, + BlockStatementData +} from './statement-block' export type { default as EmptyStatement, EmptyStatementData diff --git a/src/nodes/statement-block.ts b/src/nodes/statement-block.ts new file mode 100644 index 0000000..19bb256 --- /dev/null +++ b/src/nodes/statement-block.ts @@ -0,0 +1,55 @@ +/** + * @file Nodes - BlockStatement + * @module esast/nodes/BlockStatement + */ + +import type { Data, Parent, Statement } from '@flex-development/esast' +import type { Nilable, Optional } from '@flex-development/tutils' + +/** + * Info associated with block statements. + * + * @see {@linkcode Data} + * + * @extends {Data} + */ +interface BlockStatementData extends Data { + /** + * Static block statement? + */ + static?: Nilable +} + +/** + * A block statement. + * + * Block statements group zero (`0`) or more statements. The block is delimited + * by a pair of braces ("curly braces") and contains a list of zero (`0`) or + * more statements and declarations. + * + * @see {@linkcode Parent} + * + * @extends {Parent} + */ +interface BlockStatement extends Parent { + /** + * List of children. + * + * @see {@linkcode Statement} + */ + children: Statement[] + + /** + * Info from the ecosystem. + * + * @see {@linkcode BlockStatementData} + */ + data?: Optional + + /** + * Node type. + */ + type: 'blockStatement' +} + +export type { BlockStatementData, BlockStatement as default } diff --git a/tsconfig.json b/tsconfig.json index 9bb7cb0..118baf8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,6 +30,7 @@ "outDir": "dist", "paths": { "#src/*": ["src/*"], + "#tests/*": ["__tests__/*"], "@flex-development/esast": ["src/index"] }, "preserveConstEnums": true,