diff --git a/.changeset/purple-steaks-admire.md b/.changeset/purple-steaks-admire.md new file mode 100644 index 0000000000..1765aa59f9 --- /dev/null +++ b/.changeset/purple-steaks-admire.md @@ -0,0 +1,6 @@ +--- +"@marko/babel-utils": patch +"@marko/compiler": patch +--- + +Improve some typings for the compiler apis. diff --git a/packages/babel-utils/index.d.ts b/packages/babel-utils/index.d.ts index c6ab82d8e2..2785216974 100644 --- a/packages/babel-utils/index.d.ts +++ b/packages/babel-utils/index.d.ts @@ -19,10 +19,10 @@ export interface AttributeDefinition { descriptionMoreURL?: string; }>; } -export type PluginDefinition = { +export interface PluginDefinition { path?: string; hook: Plugin; -}; +} export interface TagDefinition { dir: string; filePath: string; @@ -209,7 +209,7 @@ export function loadFileForImport( export function normalizeTemplateString( quasis: Array, - expressions: t.Expression[] + ...expressions: t.Expression[] ): t.TemplateLiteral; type Loc = { line: number; column: number; index?: number }; diff --git a/packages/compiler/config.d.ts b/packages/compiler/config.d.ts index c30f9ac835..41cad53171 100644 --- a/packages/compiler/config.d.ts +++ b/packages/compiler/config.d.ts @@ -10,7 +10,10 @@ declare const Config: { ignoreUnrecognizedTags?: boolean; sourceMaps?: boolean | "inline" | "both"; translator?: any; - fileSystem?: typeof import("fs"); + fileSystem?: Pick< + typeof import("fs"), + "statSync" | "readFileSync" | "readdirSync" + >; modules?: "esm" | "cjs"; resolveVirtualDependency?: | (( diff --git a/packages/compiler/index.d.ts b/packages/compiler/index.d.ts index 9c1e688127..5154764898 100644 --- a/packages/compiler/index.d.ts +++ b/packages/compiler/index.d.ts @@ -3,7 +3,8 @@ import { TaglibLookup, Diagnostic } from "@marko/babel-utils"; import * as types from "./babel-types"; export { types }; -export type Config = typeof import("./config"); +type _Config = typeof import("./config"); +export interface Config extends _Config {} type Dep = { type: string; @@ -16,21 +17,21 @@ type Dep = { [x: string]: unknown; }; -export type MarkoMeta = { +export interface MarkoMeta { id: string; component?: string; watchFiles: string[]; tags?: string[]; deps: Array; diagnostics: Diagnostic[]; -}; +} -export type CompileResult = { +export interface CompileResult { ast: types.File; code: string; map: SourceMap; meta: MarkoMeta; -}; +} export function configure(config: Config): void;