From 58ddf01515d198179e9ea076a8bdf3b7284c1008 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Fri, 8 Mar 2024 17:39:26 -0500 Subject: [PATCH] feat(nodes): `VariableDeclarator` Signed-off-by: Lexus Drumgold --- .../__tests__/variable-declarator.spec-d.ts | 41 ++++++++++++++++ src/nodes/index.ts | 4 ++ src/nodes/variable-declarator.ts | 47 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/nodes/__tests__/variable-declarator.spec-d.ts create mode 100644 src/nodes/variable-declarator.ts diff --git a/src/nodes/__tests__/variable-declarator.spec-d.ts b/src/nodes/__tests__/variable-declarator.spec-d.ts new file mode 100644 index 0000000..307079a --- /dev/null +++ b/src/nodes/__tests__/variable-declarator.spec-d.ts @@ -0,0 +1,41 @@ +/** + * @file Type Tests - VariableDeclarator + * @module esast/nodes/tests/unit-d/VariableDeclarator + */ + +import type { Data, Expression, Parent, Pattern } from '@flex-development/esast' +import type { Optional } from '@flex-development/tutils' +import type * as TestSubject from '../variable-declarator' + +describe('unit-d:nodes/VariableDeclarator', () => { + type Subject = TestSubject.default + type SubjectData = TestSubject.VariableDeclaratorData + + it('should extend Parent', () => { + expectTypeOf().toMatchTypeOf() + }) + + it('should match [children: [Pattern, Expression] | [Pattern]]', () => { + expectTypeOf() + .toHaveProperty('children') + .toEqualTypeOf<[Pattern, Expression] | [Pattern]>() + }) + + it('should match [data?: Optional]', () => { + expectTypeOf() + .toHaveProperty('data') + .toEqualTypeOf>() + }) + + it('should match [type: "variableDeclarator"]', () => { + expectTypeOf() + .toHaveProperty('type') + .toEqualTypeOf<'variableDeclarator'>() + }) + + describe('VariableDeclaratorData', () => { + it('should extend Data', () => { + expectTypeOf().toMatchTypeOf() + }) + }) +}) diff --git a/src/nodes/index.ts b/src/nodes/index.ts index 1e18252..90c9ebf 100644 --- a/src/nodes/index.ts +++ b/src/nodes/index.ts @@ -80,3 +80,7 @@ export type { export type { default as Super, SuperData } from './super' export type { default as SwitchCase, SwitchCaseData } from './switch-case' export type { default as This, ThisData } from './this' +export type { + default as VariableDeclarator, + VariableDeclaratorData +} from './variable-declarator' diff --git a/src/nodes/variable-declarator.ts b/src/nodes/variable-declarator.ts new file mode 100644 index 0000000..a24358c --- /dev/null +++ b/src/nodes/variable-declarator.ts @@ -0,0 +1,47 @@ +/** + * @file Nodes - VariableDeclarator + * @module esast/nodes/VariableDeclarator + */ + +import type { Data, Expression, Parent, Pattern } from '@flex-development/esast' +import type { Optional } from '@flex-development/tutils' + +/** + * Info associated with variable declarators. + * + * @see {@linkcode Data} + * + * @extends {Data} + */ +interface VariableDeclaratorData extends Data {} + +/** + * A variable declarator. + * + * @see {@linkcode Parent} + * + * @extends {Parent} + */ +interface VariableDeclarator extends Parent { + /** + * List of children. + * + * @see {@linkcode Expression} + * @see {@linkcode Pattern} + */ + children: [id: Pattern, init: Expression] | [id: Pattern] + + /** + * Info from the ecosystem. + * + * @see {@linkcode VariableDeclaratorData} + */ + data?: Optional + + /** + * Node type. + */ + type: 'variableDeclarator' +} + +export type { VariableDeclaratorData, VariableDeclarator as default }