From 8cb7e5742272d3138144b0dbf614cec39d96db62 Mon Sep 17 00:00:00 2001 From: Lexus Drumgold Date: Thu, 7 Mar 2024 15:30:22 -0500 Subject: [PATCH] feat(nodes): `Identifier` Signed-off-by: Lexus Drumgold --- src/nodes/__tests__/identifier.spec-d.ts | 47 +++++++++++++++++++++++ src/nodes/identifier.ts | 49 ++++++++++++++++++++++++ src/nodes/index.ts | 1 + 3 files changed, 97 insertions(+) create mode 100644 src/nodes/__tests__/identifier.spec-d.ts create mode 100644 src/nodes/identifier.ts diff --git a/src/nodes/__tests__/identifier.spec-d.ts b/src/nodes/__tests__/identifier.spec-d.ts new file mode 100644 index 0000000..34725f9 --- /dev/null +++ b/src/nodes/__tests__/identifier.spec-d.ts @@ -0,0 +1,47 @@ +/** + * @file Type Tests - Identifier + * @module esast/nodes/tests/unit-d/Identifier + */ + +import type { Data, Node } from '@flex-development/esast' +import type { Nilable, Optional } from '@flex-development/tutils' +import type * as TestSubject from '../identifier' + +describe('unit-d:nodes/Identifier', () => { + type Identifier = TestSubject.default + type IdentifierData = TestSubject.IdentifierData + + it('should extend Node', () => { + expectTypeOf().toMatchTypeOf() + }) + + it('should match [data?: Optional]', () => { + expectTypeOf() + .toHaveProperty('data') + .toEqualTypeOf>() + }) + + it('should match [name: string]', () => { + expectTypeOf() + .toHaveProperty('name') + .toEqualTypeOf() + }) + + it('should match [type: "identifier"]', () => { + expectTypeOf() + .toHaveProperty('type') + .toEqualTypeOf<'identifier'>() + }) + + describe('IdentifierData', () => { + it('should extend Data', () => { + expectTypeOf().toMatchTypeOf() + }) + + it('should match [private?: Nilable]', () => { + expectTypeOf() + .toHaveProperty('private') + .toEqualTypeOf>() + }) + }) +}) diff --git a/src/nodes/identifier.ts b/src/nodes/identifier.ts new file mode 100644 index 0000000..a602551 --- /dev/null +++ b/src/nodes/identifier.ts @@ -0,0 +1,49 @@ +/** + * @file Nodes - Identifier + * @module esast/nodes/Identifier + */ + +import type { Data, Node } from '@flex-development/esast' +import type { Nilable, Optional } from '@flex-development/tutils' + +/** + * Info associated with identifiers. + * + * @see {@linkcode Data} + * + * @extends {Data} + */ +interface IdentifierData extends Data { + /** + * Private identifier? + */ + private?: Nilable +} + +/** + * An identifier. + * + * @see {@linkcode Node} + * + * @extends {Node} + */ +interface Identifier extends Node { + /** + * Info from the ecosystem. + * + * @see {@linkcode IdentifierData} + */ + data?: Optional + + /** + * Identifier name. + */ + name: string + + /** + * Node type. + */ + type: 'identifier' +} + +export type { IdentifierData, Identifier as default } diff --git a/src/nodes/index.ts b/src/nodes/index.ts index 6236ea8..66d6ee9 100644 --- a/src/nodes/index.ts +++ b/src/nodes/index.ts @@ -4,6 +4,7 @@ * @see https://github.com/syntax-tree/unist#nodes */ +export type { default as Identifier, IdentifierData } from './identifier' export type { default as Literal } from './literal' export type { default as BigIntLiteral } from './literal-bigint' export type { default as BooleanLiteral } from './literal-boolean'