Skip to content

Commit

Permalink
feat(nodes): ForInStatement, ForOfStatement
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 cd30760 commit 6025de8
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/content/__tests__/statement.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type {
DoWhileStatement,
EmptyStatement,
ExpressionStatement,
ForInStatement,
ForOfStatement,
IfStatement,
ThrowStatement
} from '@flex-development/esast'
Expand Down Expand Up @@ -66,6 +68,16 @@ describe('unit-d:content/statement', () => {
.toMatchTypeOf<NodeObject<ExpressionStatement>>()
})

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

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

it('should match NodeObject<IfStatement>', () => {
expectTypeOf<TestSubject.StatementMap>()
.toMatchTypeOf<NodeObject<IfStatement>>()
Expand Down
4 changes: 4 additions & 0 deletions src/content/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import type {
DoWhileStatement,
EmptyStatement,
ExpressionStatement,
ForInStatement,
ForOfStatement,
IfStatement,
ThrowStatement
} from '@flex-development/esast'
Expand Down Expand Up @@ -46,6 +48,8 @@ interface StatementMap extends DeclarationMap {
doWhileStatement: DoWhileStatement
emptyStatement: EmptyStatement
expressionStatement: ExpressionStatement
forInStatement: ForInStatement
forOfStatement: ForOfStatement
ifStatement: IfStatement
throwStatement: ThrowStatement
}
Expand Down
35 changes: 35 additions & 0 deletions src/nodes/__tests__/statement-for-in.spec-d.ts
Original file line number Diff line number Diff line change
@@ -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<Subject>().toMatchTypeOf<ForXStatement>()
})

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

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

describe('ForInStatementData', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})
})
})
41 changes: 41 additions & 0 deletions src/nodes/__tests__/statement-for-of.spec-d.ts
Original file line number Diff line number Diff line change
@@ -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<Subject>().toMatchTypeOf<ForXStatement>()
})

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

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

describe('ForOfStatementData', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})

it('should match [await?: Nilable<boolean>]', () => {
expectTypeOf<SubjectData>()
.toHaveProperty('await')
.toEqualTypeOf<Nilable<boolean>>()
})
})
})
35 changes: 35 additions & 0 deletions src/nodes/__tests__/statement-for-x.spec-d.ts
Original file line number Diff line number Diff line change
@@ -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<TestSubject>().toMatchTypeOf<Parent>()
})

it('should match [children: [Pattern | VariableDeclaration, Expression, Statement]]', () => {
// Arrange
type Expect = [Pattern | VariableDeclaration, Expression, Statement]

// Expect
expectTypeOf<TestSubject>()
.toHaveProperty('children')
.toEqualTypeOf<Expect>()
})

it('should match [type: `for${Uppercase<string>}${string}`]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('type')
.toEqualTypeOf<`for${Uppercase<string>}${string}`>()
})
})
9 changes: 9 additions & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
39 changes: 39 additions & 0 deletions src/nodes/statement-for-in.ts
Original file line number Diff line number Diff line change
@@ -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<ForInStatementData>

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

export type { ForInStatementData, ForInStatement as default }
44 changes: 44 additions & 0 deletions src/nodes/statement-for-of.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>
}

/**
* A `for...of` statement.
*
* @see {@linkcode ForXStatement}
*
* @extends {ForXStatement}
*/
interface ForOfStatement extends ForXStatement {
/**
* Info from the ecosystem.
*
* @see {@linkcode ForOfStatementData}
*/
data?: Optional<ForOfStatementData>

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

export type { ForOfStatementData, ForOfStatement as default }
42 changes: 42 additions & 0 deletions src/nodes/statement-for-x.ts
Original file line number Diff line number Diff line change
@@ -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>}${string}`
}

export type { ForXStatement as default }

0 comments on commit 6025de8

Please sign in to comment.