Skip to content

Commit

Permalink
feat(nodes): Property
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 c0bb616 commit a3a9289
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/nodes/__tests__/property.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @file Type Tests - Property
* @module esast/nodes/tests/unit-d/Property
*/

import type {
Data,
Expression,
Identifier,
Parent,
Pattern,
PropertyKind
} from '@flex-development/esast'
import type { Nilable, Optional } from '@flex-development/tutils'
import type * as TestSubject from '../property'

describe('unit-d:nodes/Property', () => {
type Subject = TestSubject.default
type SubjectData = TestSubject.PropertyData

it('should extend Parent', () => {
expectTypeOf<Subject>().toMatchTypeOf<Parent>()
})

it('should match [children: [Expression | Identifier, Expression | Pattern]]', () => {
expectTypeOf<Subject>()
.toHaveProperty('children')
.toEqualTypeOf<[Expression | Identifier, Expression | Pattern]>()
})

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

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

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

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

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

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

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

it('should match [assignment?: Nilable<boolean>]', () => {
expectTypeOf<SubjectData>()
.toHaveProperty('assignment')
.toEqualTypeOf<Nilable<boolean>>()
})
})
})
1 change: 1 addition & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export type {
default as AssignmentPattern,
AssignmentPatternData
} from './pattern-assignment'
export type { default as Property, PropertyData } from './property'
export type { default as MetaProperty, MetaPropertyData } from './property-meta'
export type {
default as BlockStatement,
Expand Down
82 changes: 82 additions & 0 deletions src/nodes/property.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @file Nodes - Property
* @module esast/nodes/Property
*/

import type {
Data,
Expression,
Identifier,
Parent,
Pattern,
PropertyKind
} from '@flex-development/esast'
import type { Nilable, Optional } from '@flex-development/tutils'

/**
* Info associated with properties.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface PropertyData extends Data {
/**
* Assignment property?
*/
assignment?: Nilable<boolean>
}

/**
* A property.
*
* @see {@linkcode Parent}
*
* @extends {Parent}
*/
interface Property extends Parent {
/**
* List of children.
*
* @see {@linkcode Expression}
* @see {@linkcode Identifier}
* @see {@linkcode Pattern}
*/
children: [key: Expression | Identifier, value: Expression | Pattern]

/**
* Boolean indicating if property is computed.
*/
computed: boolean

/**
* Info from the ecosystem.
*
* @see {@linkcode PropertyData}
*/
data?: Optional<PropertyData>

/**
* Property kind.
*
* @see {@linkcode PropertyKind}
*/
kind: PropertyKind

/**
* Boolean indicating if property value is a method.
*/
method: boolean

/**
* Boolean indicating if property was defined using shorthand syntax.
*/
shorthand: boolean

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

export type { PropertyData, Property as default }

0 comments on commit a3a9289

Please sign in to comment.