Skip to content

Commit

Permalink
feat(nodes): ImportDeclaration
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 3a25a9e commit 8aad7c1
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/content/__tests__/declaration-module.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
* @module esast/content/tests/unit-d/moduleDeclaration
*/

import type { ExportDeclarationMap } from '@flex-development/esast'
import type { NodeObject } from '#tests/types'
import type {
ExportDeclarationMap,
ImportDeclaration
} from '@flex-development/esast'
import type * as TestSubject from '../declaration-module'

describe('unit-d:content/moduleDeclaration', () => {
Expand All @@ -23,5 +27,10 @@ describe('unit-d:content/moduleDeclaration', () => {
expectTypeOf<TestSubject.ModuleDeclarationMap>()
.toMatchTypeOf<ExportDeclarationMap>()
})

it('should match NodeObject<ImportDeclaration>', () => {
expectTypeOf<TestSubject.ModuleDeclarationMap>()
.toMatchTypeOf<NodeObject<ImportDeclaration>>()
})
})
})
9 changes: 7 additions & 2 deletions src/content/declaration-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
* @module esast/content/moduleDeclaration
*/

import type { ExportDeclarationMap } from '@flex-development/esast'
import type {
ExportDeclarationMap,
ImportDeclaration
} from '@flex-development/esast'

/**
* Union of registered esast nodes that can occur where a module declaration is
Expand All @@ -27,6 +30,8 @@ type ModuleDeclaration = ModuleDeclarationMap[keyof ModuleDeclarationMap]
* }
* }
*/
interface ModuleDeclarationMap extends ExportDeclarationMap {}
interface ModuleDeclarationMap extends ExportDeclarationMap {
importDeclaration: ImportDeclaration
}

export type { ModuleDeclaration, ModuleDeclarationMap }
51 changes: 51 additions & 0 deletions src/nodes/__tests__/declaration-import.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @file Type Tests - ImportDeclaration
* @module esast/nodes/tests/unit-d/ImportDeclaration
*/

import type {
Data,
ImportKind,
ImportSpecifiers,
Parent,
StringLiteral
} from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'
import type * as TestSubject from '../declaration-import'

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

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

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

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

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

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

describe('ImportDeclarationData', () => {
it('should extend Data', () => {
expectTypeOf<SubjectData>().toMatchTypeOf<Data>()
})
})
})
60 changes: 60 additions & 0 deletions src/nodes/declaration-import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @file Nodes - ImportDeclaration
* @module esast/nodes/ImportDeclaration
*/

import type {
Data,
ImportKind,
ImportSpecifiers,
Parent,
StringLiteral
} from '@flex-development/esast'
import type { Optional } from '@flex-development/tutils'

/**
* Info associated with `import` declarations.
*
* @see {@linkcode Data}
*
* @extends {Data}
*/
interface ImportDeclarationData extends Data {}

/**
* An `import` declaration.
*
* @see {@linkcode Parent}
*
* @extends {Parent}
*/
interface ImportDeclaration extends Parent {
/**
* List of children.
*
* @see {@linkcode ImportSpecifiers}
* @see {@linkcode StringLiteral}
*/
children: [specifiers: ImportSpecifiers, source: StringLiteral]

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

/**
* Import kind.
*
* @see {@linkcode ImportKind}
*/
kind: ImportKind

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

export type { ImportDeclarationData, ImportDeclaration as default }
4 changes: 4 additions & 0 deletions src/nodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export type {
default as FunctionDeclaration,
FunctionDeclarationData
} from './declaration-function'
export type {
default as ImportDeclaration,
ImportDeclarationData
} from './declaration-import'
export type {
default as VariableDeclaration,
VariableDeclarationData
Expand Down

0 comments on commit 8aad7c1

Please sign in to comment.