Skip to content

Commit

Permalink
refactor(nodes)!: object properties
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed May 17, 2024
1 parent ea66e06 commit bc47090
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 160 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/esast.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('unit-d:esast', () => {
| mdast.Nodes
| TestSubject.Comment
| TestSubject.ExpressionStatement
| TestSubject.ShorthandProperty
| TestSubject.MethodProperty
| TestSubject.TemplateLiteral
>

Expand All @@ -52,9 +52,9 @@ describe('unit-d:esast', () => {
.toBeNever()
})

it('should not include ShorthandProperty', () => {
it('should not include MethodProperty', () => {
expectTypeOf<Subject>()
.extract<TestSubject.ShorthandProperty>()
.extract<TestSubject.MethodProperty>()
.toBeNever()
})

Expand Down
15 changes: 0 additions & 15 deletions src/nodes/__tests__/property-renamed.spec-d.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/nodes/__tests__/property-shorthand.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ describe('unit-d:nodes/ShorthandProperty', () => {
expectTypeOf<Subject>().toHaveProperty('assignment').toEqualTypeOf<false>()
})

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

it('should match [kind: Extract<PropertyKind, "init">]', () => {
expectTypeOf<Subject>()
.toHaveProperty('kind')
Expand Down
8 changes: 5 additions & 3 deletions src/nodes/definition-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import type {
FunctionExpression,
MethodKind,
ModifierList,
Parent
Parent,
PropertyName
} from '@flex-development/esast'

/**
Expand All @@ -38,6 +39,7 @@ interface MethodDefinition extends Parent {
* @see {@linkcode Expression}
* @see {@linkcode FunctionExpression}
* @see {@linkcode ModifierList}
* @see {@linkcode PropertyName}
*/
children:
| [
Expand All @@ -53,7 +55,7 @@ interface MethodDefinition extends Parent {
...comments: InternalComments,
value: FunctionExpression
]
| [name: Expression, ...comments: Comments, value: FunctionExpression]
| [name: PropertyName, ...comments: Comments, value: FunctionExpression]

/**
* Boolean indicating if method name is computed.
Expand Down Expand Up @@ -85,4 +87,4 @@ interface MethodDefinition extends Parent {
type: 'methodDefinition'
}

export type { MethodDefinitionData, MethodDefinition as default }
export type { MethodDefinition as default, MethodDefinitionData }
18 changes: 4 additions & 14 deletions src/nodes/expression-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import type {
Comment,
Data,
MethodProperty,
Parent,
ShorthandProperty,
SimpleProperty,
Property,
SpreadElement
} from '@flex-development/esast'

Expand All @@ -34,18 +32,10 @@ interface ObjectExpression extends Parent {
* List of children.
*
* @see {@linkcode Comment}
* @see {@linkcode MethodProperty}
* @see {@linkcode ShorthandProperty}
* @see {@linkcode SimpleProperty}
* @see {@linkcode Property}
* @see {@linkcode SpreadElement}
*/
children: (
| Comment
| MethodProperty
| ShorthandProperty
| SimpleProperty
| SpreadElement
)[]
children: (Comment | Property | SpreadElement)[]

/**
* Info from the ecosystem.
Expand All @@ -60,4 +50,4 @@ interface ObjectExpression extends Parent {
type: 'objectExpression'
}

export type { ObjectExpressionData, ObjectExpression as default }
export type { ObjectExpression as default, ObjectExpressionData }
1 change: 0 additions & 1 deletion src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ export type {
export type { default as Property, PropertyData } from './property'
export type { default as AssignmentProperty } from './property-assignment'
export type { default as MethodProperty } from './property-method'
export type { default as RenamedProperty } from './property-renamed'
export type { default as ShorthandProperty } from './property-shorthand'
export type { default as SimpleProperty } from './property-simple'
export type { default as Root, RootData } from './root'
Expand Down
4 changes: 3 additions & 1 deletion src/nodes/pattern-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type {
Comment,
Data,
Expression,
Nothing,
Parent,
Pattern
Expand All @@ -32,10 +33,11 @@ interface ArrayPattern extends Parent {
* List of children.
*
* @see {@linkcode Comment}
* @see {@linkcode Expression}
* @see {@linkcode Nothing}
* @see {@linkcode Pattern}
*/
children: (Comment | Nothing | Pattern)[]
children: (Comment | Expression | Nothing | Pattern)[]

/**
* Info from the ecosystem.
Expand Down
20 changes: 5 additions & 15 deletions src/nodes/pattern-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
*/

import type {
AssignmentProperty,
Comment,
Data,
Parent,
RenamedProperty,
RestElement,
ShorthandProperty
Property,
RestElement
} from '@flex-development/esast'

/**
Expand All @@ -33,19 +31,11 @@ interface ObjectPattern extends Parent {
/**
* List of children.
*
* @see {@linkcode AssignmentProperty}
* @see {@linkcode Comment}
* @see {@linkcode RenamedProperty}
* @see {@linkcode Property}
* @see {@linkcode RestElement}
* @see {@linkcode ShorthandProperty}
*/
children: (
| AssignmentProperty
| Comment
| RenamedProperty
| RestElement
| ShorthandProperty
)[]
children: (Comment | Property | RestElement)[]

/**
* Info from the ecosystem.
Expand All @@ -60,4 +50,4 @@ interface ObjectPattern extends Parent {
type: 'objectPattern'
}

export type { ObjectPatternData, ObjectPattern as default }
export type { ObjectPattern as default, ObjectPatternData }
10 changes: 7 additions & 3 deletions src/nodes/property-assignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import type { InternalComments } from '#internal'
import type {
ArrayPattern,
AssignmentExpression,
AssignmentPattern,
Comments,
Expression,
Identifier,
ObjectPattern,
Property,
PropertyKind,
Expand All @@ -32,9 +34,11 @@ interface AssignmentProperty extends Property {
* List of children.
*
* @see {@linkcode ArrayPattern}
* @see {@linkcode AssignmentExpression}
* @see {@linkcode AssignmentPattern}
* @see {@linkcode Comments}
* @see {@linkcode Expression}
* @see {@linkcode Identifier}
* @see {@linkcode ObjectPattern}
* @see {@linkcode PropertyName}
*/
Expand All @@ -43,14 +47,14 @@ interface AssignmentProperty extends Property {
...comments: Comments,
key: Expression,
...comments: InternalComments,
value: ArrayPattern | AssignmentPattern | ObjectPattern
value: ArrayPattern | AssignmentPattern | Identifier | ObjectPattern
]
| [
key: PropertyName,
...comments: Comments,
value: ArrayPattern | AssignmentPattern | ObjectPattern
value: ArrayPattern | AssignmentPattern | Identifier | ObjectPattern
]
| [assignment: AssignmentPattern]
| [assignment: AssignmentExpression | AssignmentPattern]

/**
* Property kind.
Expand Down
32 changes: 3 additions & 29 deletions src/nodes/property-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@
* @module esast/nodes/MethodProperty
*/

import type { InternalComments } from '#internal'
import type {
Comments,
Expression,
FunctionExpression,
ModifierList,
Property,
PropertyName
} from '@flex-development/esast'
import type { MethodDefinition, Property } from '@flex-development/esast'

/**
* A method property.
Expand All @@ -29,27 +21,9 @@ interface MethodProperty extends Property {
/**
* List of children.
*
* @see {@linkcode Comments}
* @see {@linkcode Expression}
* @see {@linkcode FunctionExpression}
* @see {@linkcode PropertyName}
* @see {@linkcode ModifierList}
* @see {@linkcode MethodDefinition}
*/
children:
| [
...comments: Comments,
key: Expression,
...comments: InternalComments,
value: FunctionExpression
]
| [
modifiers: ModifierList,
...comments: Comments,
key: Expression,
...comments: InternalComments,
value: FunctionExpression
]
| [key: PropertyName, ...comments: Comments, value: FunctionExpression]
children: [MethodDefinition]

/**
* Boolean indicating if property value is a method.
Expand Down
40 changes: 0 additions & 40 deletions src/nodes/property-renamed.ts

This file was deleted.

24 changes: 15 additions & 9 deletions src/nodes/property-shorthand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
* @module esast/nodes/ShorthandProperty
*/

import type { InternalComments } from '#internal'
import type {
Identifier,
Comments,
Expression,
Property,
PropertyKind
PropertyKind,
PropertyName
} from '@flex-development/esast'

/**
Expand All @@ -25,14 +28,17 @@ interface ShorthandProperty extends Property {
/**
* List of children.
*
* @see {@linkcode Identifier}
* @see {@linkcode Comments}
* @see {@linkcode Expression}
* @see {@linkcode PropertyName}
*/
children: [key: Identifier]

/**
* Boolean indicating if property is computed.
*/
computed: false
children:
| [
...comments: Comments,
key: Expression,
...comments: InternalComments
]
| [key: PropertyName]

/**
* Property kind.
Expand Down
9 changes: 2 additions & 7 deletions src/nodes/property-simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { InternalComments } from '#internal'
import type {
Comments,
Expression,
FunctionExpression,
Property,
PropertyKind,
PropertyName
Expand Down Expand Up @@ -38,13 +37,9 @@ interface SimpleProperty extends Property {
...comments: Comments,
key: Expression,
...comments: InternalComments,
value: Exclude<Expression, FunctionExpression>
]
| [
key: PropertyName,
...comments: Comments,
value: Exclude<Expression, FunctionExpression>
value: Expression
]
| [key: PropertyName, ...comments: Comments, value: Expression]

/**
* Property kind.
Expand Down
Loading

0 comments on commit bc47090

Please sign in to comment.