From 6025de81e8a17399f19d9f30c527dc00dac74de5 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Fri, 8 Mar 2024 19:03:03 -0500 Subject: [PATCH] feat(nodes): `ForInStatement`, `ForOfStatement` Signed-off-by: Lexus Drumgold --- src/content/__tests__/statement.spec-d.ts | 12 +++++ src/content/statement.ts | 4 ++ .../__tests__/statement-for-in.spec-d.ts | 35 +++++++++++++++ .../__tests__/statement-for-of.spec-d.ts | 41 +++++++++++++++++ src/nodes/__tests__/statement-for-x.spec-d.ts | 35 +++++++++++++++ src/nodes/index.ts | 9 ++++ src/nodes/statement-for-in.ts | 39 ++++++++++++++++ src/nodes/statement-for-of.ts | 44 +++++++++++++++++++ src/nodes/statement-for-x.ts | 42 ++++++++++++++++++ 9 files changed, 261 insertions(+) create mode 100644 src/nodes/__tests__/statement-for-in.spec-d.ts create mode 100644 src/nodes/__tests__/statement-for-of.spec-d.ts create mode 100644 src/nodes/__tests__/statement-for-x.spec-d.ts create mode 100644 src/nodes/statement-for-in.ts create mode 100644 src/nodes/statement-for-of.ts create mode 100644 src/nodes/statement-for-x.ts diff --git a/src/content/__tests__/statement.spec-d.ts b/src/content/__tests__/statement.spec-d.ts index 6c3c7c6..60dc1db 100644 --- a/src/content/__tests__/statement.spec-d.ts +++ b/src/content/__tests__/statement.spec-d.ts @@ -13,6 +13,8 @@ import type { DoWhileStatement, EmptyStatement, ExpressionStatement, + ForInStatement, + ForOfStatement, IfStatement, ThrowStatement } from '@flex-development/esast' @@ -66,6 +68,16 @@ describe('unit-d:content/statement', () => { .toMatchTypeOf>() }) + it('should match NodeObject', () => { + expectTypeOf() + .toMatchTypeOf>() + }) + + it('should match NodeObject', () => { + expectTypeOf() + .toMatchTypeOf>() + }) + it('should match NodeObject', () => { expectTypeOf() .toMatchTypeOf>() diff --git a/src/content/statement.ts b/src/content/statement.ts index 242d8a2..fe8cb8a 100644 --- a/src/content/statement.ts +++ b/src/content/statement.ts @@ -12,6 +12,8 @@ import type { DoWhileStatement, EmptyStatement, ExpressionStatement, + ForInStatement, + ForOfStatement, IfStatement, ThrowStatement } from '@flex-development/esast' @@ -46,6 +48,8 @@ interface StatementMap extends DeclarationMap { doWhileStatement: DoWhileStatement emptyStatement: EmptyStatement expressionStatement: ExpressionStatement + forInStatement: ForInStatement + forOfStatement: ForOfStatement ifStatement: IfStatement throwStatement: ThrowStatement } diff --git a/src/nodes/__tests__/statement-for-in.spec-d.ts b/src/nodes/__tests__/statement-for-in.spec-d.ts new file mode 100644 index 0000000..5c23b04 --- /dev/null +++ b/src/nodes/__tests__/statement-for-in.spec-d.ts @@ -0,0 +1,35 @@ +/** + * @file Type Tests - ForInStatement + * @module esast/nodes/tests/unit-d/ForInStatement + */ + +import type { Data, ForXStatement } from '@flex-development/esast' +import type { Optional } from '@flex-development/tutils' +import type * as TestSubject from '../statement-for-in' + +describe('unit-d:nodes/ForInStatement', () => { + type Subject = TestSubject.default + type SubjectData = TestSubject.ForInStatementData + + it('should extend ForXStatement', () => { + expectTypeOf().toMatchTypeOf() + }) + + it('should match [data?: Optional]', () => { + expectTypeOf() + .toHaveProperty('data') + .toEqualTypeOf>() + }) + + it('should match [type: "forInStatement"]', () => { + expectTypeOf() + .toHaveProperty('type') + .toEqualTypeOf<'forInStatement'>() + }) + + describe('ForInStatementData', () => { + it('should extend Data', () => { + expectTypeOf().toMatchTypeOf() + }) + }) +}) diff --git a/src/nodes/__tests__/statement-for-of.spec-d.ts b/src/nodes/__tests__/statement-for-of.spec-d.ts new file mode 100644 index 0000000..262a6da --- /dev/null +++ b/src/nodes/__tests__/statement-for-of.spec-d.ts @@ -0,0 +1,41 @@ +/** + * @file Type Tests - ForOfStatement + * @module esast/nodes/tests/unit-d/ForOfStatement + */ + +import type { Data, ForXStatement } from '@flex-development/esast' +import type { Nilable, Optional } from '@flex-development/tutils' +import type * as TestSubject from '../statement-for-of' + +describe('unit-d:nodes/ForOfStatement', () => { + type Subject = TestSubject.default + type SubjectData = TestSubject.ForOfStatementData + + it('should extend ForXStatement', () => { + expectTypeOf().toMatchTypeOf() + }) + + it('should match [data?: Optional]', () => { + expectTypeOf() + .toHaveProperty('data') + .toEqualTypeOf>() + }) + + it('should match [type: "forOfStatement"]', () => { + expectTypeOf() + .toHaveProperty('type') + .toEqualTypeOf<'forOfStatement'>() + }) + + describe('ForOfStatementData', () => { + it('should extend Data', () => { + expectTypeOf().toMatchTypeOf() + }) + + it('should match [await?: Nilable]', () => { + expectTypeOf() + .toHaveProperty('await') + .toEqualTypeOf>() + }) + }) +}) diff --git a/src/nodes/__tests__/statement-for-x.spec-d.ts b/src/nodes/__tests__/statement-for-x.spec-d.ts new file mode 100644 index 0000000..e1279c2 --- /dev/null +++ b/src/nodes/__tests__/statement-for-x.spec-d.ts @@ -0,0 +1,35 @@ +/** + * @file Type Tests - ForXStatement + * @module esast/nodes/tests/unit-d/ForXStatement + */ + +import type { + Expression, + Parent, + Pattern, + Statement, + VariableDeclaration +} from '@flex-development/esast' +import type TestSubject from '../statement-for-x' + +describe('unit-d:nodes/ForXStatement', () => { + it('should extend Parent', () => { + expectTypeOf().toMatchTypeOf() + }) + + it('should match [children: [Pattern | VariableDeclaration, Expression, Statement]]', () => { + // Arrange + type Expect = [Pattern | VariableDeclaration, Expression, Statement] + + // Expect + expectTypeOf() + .toHaveProperty('children') + .toEqualTypeOf() + }) + + it('should match [type: `for${Uppercase}${string}`]', () => { + expectTypeOf() + .toHaveProperty('type') + .toEqualTypeOf<`for${Uppercase}${string}`>() + }) +}) diff --git a/src/nodes/index.ts b/src/nodes/index.ts index dc25e58..1a43a25 100644 --- a/src/nodes/index.ts +++ b/src/nodes/index.ts @@ -104,6 +104,15 @@ export type { default as ExpressionStatement, ExpressionStatementData } from './statement-expression' +export type { + default as ForInStatement, + ForInStatementData +} from './statement-for-in' +export type { + default as ForOfStatement, + ForOfStatementData +} from './statement-for-of' +export type { default as ForXStatement } from './statement-for-x' export type { default as IfStatement, IfStatementData } from './statement-if' export type { default as ThrowStatement, diff --git a/src/nodes/statement-for-in.ts b/src/nodes/statement-for-in.ts new file mode 100644 index 0000000..678f59b --- /dev/null +++ b/src/nodes/statement-for-in.ts @@ -0,0 +1,39 @@ +/** + * @file Nodes - ForInStatement + * @module esast/nodes/ForInStatement + */ + +import type { Data, ForXStatement } from '@flex-development/esast' +import type { Optional } from '@flex-development/tutils' + +/** + * Info associated with `for...in` statements. + * + * @see {@linkcode Data} + * + * @extends {Data} + */ +interface ForInStatementData extends Data {} + +/** + * A `for...in` statement. + * + * @see {@linkcode ForXStatement} + * + * @extends {ForXStatement} + */ +interface ForInStatement extends ForXStatement { + /** + * Info from the ecosystem. + * + * @see {@linkcode ForInStatementData} + */ + data?: Optional + + /** + * Node type. + */ + type: 'forInStatement' +} + +export type { ForInStatementData, ForInStatement as default } diff --git a/src/nodes/statement-for-of.ts b/src/nodes/statement-for-of.ts new file mode 100644 index 0000000..e7b6576 --- /dev/null +++ b/src/nodes/statement-for-of.ts @@ -0,0 +1,44 @@ +/** + * @file Nodes - ForOfStatement + * @module esast/nodes/ForOfStatement + */ + +import type { Data, ForXStatement } from '@flex-development/esast' +import type { Nilable, Optional } from '@flex-development/tutils' + +/** + * Info associated with `for...of` statements. + * + * @see {@linkcode Data} + * + * @extends {Data} + */ +interface ForOfStatementData extends Data { + /** + * Asynchronous statement? + */ + await?: Nilable +} + +/** + * A `for...of` statement. + * + * @see {@linkcode ForXStatement} + * + * @extends {ForXStatement} + */ +interface ForOfStatement extends ForXStatement { + /** + * Info from the ecosystem. + * + * @see {@linkcode ForOfStatementData} + */ + data?: Optional + + /** + * Node type. + */ + type: 'forOfStatement' +} + +export type { ForOfStatementData, ForOfStatement as default } diff --git a/src/nodes/statement-for-x.ts b/src/nodes/statement-for-x.ts new file mode 100644 index 0000000..72a80a0 --- /dev/null +++ b/src/nodes/statement-for-x.ts @@ -0,0 +1,42 @@ +/** + * @file Nodes - ForXStatement + * @module esast/nodes/ForXStatement + */ + +import type { + Expression, + Parent, + Pattern, + Statement, + VariableDeclaration +} from '@flex-development/esast' + +/** + * A `for...of` or `for...in` statement. + * + * @see {@linkcode Parent} + * + * @extends {Parent} + */ +interface ForXStatement extends Parent { + /** + * List of children. + * + * @see {@linkcode Expression} + * @see {@linkcode Pattern} + * @see {@linkcode Statement} + * @see {@linkcode VariableDeclaration} + */ + children: [ + left: Pattern | VariableDeclaration, + right: Expression, + body: Statement + ] + + /** + * Node type. + */ + type: `for${Uppercase}${string}` +} + +export type { ForXStatement as default }