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 ccabe07
Show file tree
Hide file tree
Showing 6 changed files with 150 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
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 ccabe07

Please sign in to comment.