75 lines
2.2 KiB
TypeScript
75 lines
2.2 KiB
TypeScript
import * as _unplugin from 'unplugin';
|
|
import { ParserOptions } from '@babel/parser';
|
|
import * as _babel_types from '@babel/types';
|
|
import { Program, Node } from '@babel/types';
|
|
import { FilterPattern } from '@rollup/pluginutils';
|
|
|
|
interface ScriptTagMeta {
|
|
start: number;
|
|
end: number;
|
|
contentStart: number;
|
|
contentEnd: number;
|
|
content: string;
|
|
attrs: Record<string, string>;
|
|
found: boolean;
|
|
ast: Program;
|
|
}
|
|
interface ParsedSFC {
|
|
id?: string;
|
|
template: {
|
|
/** foo-bar -> FooBar */
|
|
components: Set<string>;
|
|
/** v-foo-bar -> fooBar */
|
|
directives: Set<string>;
|
|
identifiers: Set<string>;
|
|
};
|
|
scriptSetup: ScriptTagMeta;
|
|
script: ScriptTagMeta;
|
|
parserOptions: ParserOptions;
|
|
extraDeclarations: Node[];
|
|
}
|
|
interface ScriptSetupTransformOptions {
|
|
astTransforms?: {
|
|
script?: (ast: Program) => Program;
|
|
scriptSetup?: (ast: Program) => Program;
|
|
post?: (ast: Program, sfc: ParsedSFC) => Program;
|
|
};
|
|
reactivityTransform?: boolean;
|
|
importHelpersFrom?: string;
|
|
sourceMap?: boolean;
|
|
}
|
|
interface PluginOptions extends ScriptSetupTransformOptions {
|
|
include?: FilterPattern;
|
|
exclude?: FilterPattern;
|
|
}
|
|
type ResolvedOptions = Required<ScriptSetupTransformOptions>;
|
|
interface SourceMap {
|
|
file: string;
|
|
mappings: string;
|
|
names: string[];
|
|
sources: string[];
|
|
sourcesContent: string[];
|
|
version: number;
|
|
toString(): string;
|
|
toUrl(): string;
|
|
}
|
|
type TransformResult = {
|
|
code: string;
|
|
readonly map: SourceMap | null;
|
|
} | null;
|
|
|
|
declare function shouldTransform(code: string, id: string, options?: ScriptSetupTransformOptions): boolean;
|
|
declare function transform(input: string, id: string, options?: ScriptSetupTransformOptions): Promise<TransformResult>;
|
|
|
|
declare function transformScriptSetup(sfc: ParsedSFC, options?: ScriptSetupTransformOptions): {
|
|
ast: null;
|
|
code: string;
|
|
} | {
|
|
ast: _babel_types.Program;
|
|
code: string;
|
|
};
|
|
|
|
declare const unplugin: _unplugin.UnpluginInstance<PluginOptions, boolean>;
|
|
|
|
export { ParsedSFC, PluginOptions, ResolvedOptions, ScriptSetupTransformOptions, ScriptTagMeta, SourceMap, TransformResult, unplugin as default, shouldTransform, transform, transformScriptSetup, unplugin };
|