Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
feat(typescript): TrextFileResult
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed Oct 10, 2021
1 parent 1ad80b2 commit 4c155ab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export type { default as FileExtension } from './file-extension.type'
export type { default as RegexString } from './regex-string.type'
export type { default as SourceMapComment } from './source-map-comment.type'
export type { default as TrextDefaults } from './trext-defaults.type'
export type { default as TrextFileResult } from './trext-file-result.type'
export type { default as TrextToFn } from './trext-to-fn.type'
export type { default as TrextTo } from './trext-to.type'
37 changes: 37 additions & 0 deletions src/types/trext-file-result.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { BabelFileResult } from '@babel/core'
import type { File } from '@babel/types'

/**
* @file Type Definitions - TrextFileResult
* @module trext/types/TrextFileResult
*/

/**
* Return value of `Trext.trextFile`.
*
* ! Note: For some reason, `@babel/core` does not export the [`FileResult`][1]
* ! type (nor is it correctly defined in the repository). Additionally, [types
* ! needed to correctly implement this type are also not available][2].
*
* @template T - File extension name(s)
*
* [1]: https://github.com/babel/babel/blob/v7.15.8/packages/babel-core/src/transformation/index.ts
* [2]: https://github.com/babel/babel/blob/v7.15.8/packages/babel-core/src/config/validation/options.ts
*/
type TrextFileResult = {
ast: File | null
code: string | null
ignored?: NonNullable<BabelFileResult['ignored']>
map: NonNullable<BabelFileResult['map']>
metadata: Record<never, never> | NonNullable<BabelFileResult['metadata']>

/**
* ! `@babel/core` library does not export `InputOptions` type either.
*
* @see https://github.com/babel/babel/blob/c4b13725aa65446974d8b78b63a7da8ec826ff76/packages/babel-core/src/config/validation/options.ts#L132
*/
options?: Record<string, any>
sourceType: 'module' | 'string'
}

export default TrextFileResult

0 comments on commit 4c155ab

Please sign in to comment.