|
import * as _babel_types from '@babel/types'; |
|
import { Statement, Expression, TSType, Node, Program, CallExpression, ObjectPattern, TSModuleDeclaration, TSPropertySignature, TSMethodSignature, TSCallSignatureDeclaration, TSFunctionType } from '@babel/types'; |
|
import { RootNode, CompilerOptions, CodegenResult, ParserOptions, CompilerError, SourceLocation, BindingMetadata as BindingMetadata$1 } from '@vue/compiler-core'; |
|
export { BindingMetadata, CompilerError, CompilerOptions, extractIdentifiers, generateCodeFrame, isInDestructureAssignment, isStaticProperty, walkIdentifiers } from '@vue/compiler-core'; |
|
import { RawSourceMap } from 'source-map-js'; |
|
import { ParserPlugin } from '@babel/parser'; |
|
export { parse as babelParse } from '@babel/parser'; |
|
import { Result, LazyResult } from 'postcss'; |
|
import MagicString from 'magic-string'; |
|
export { default as MagicString } from 'magic-string'; |
|
import TS from 'typescript'; |
|
|
|
export interface AssetURLTagConfig { |
|
[name: string]: string[]; |
|
} |
|
export interface AssetURLOptions { |
|
|
|
|
|
|
|
|
|
base?: string | null; |
|
|
|
|
|
|
|
includeAbsolute?: boolean; |
|
tags?: AssetURLTagConfig; |
|
} |
|
|
|
export interface TemplateCompiler { |
|
compile(source: string | RootNode, options: CompilerOptions): CodegenResult; |
|
parse(template: string, options: ParserOptions): RootNode; |
|
} |
|
export interface SFCTemplateCompileResults { |
|
code: string; |
|
ast?: RootNode; |
|
preamble?: string; |
|
source: string; |
|
tips: string[]; |
|
errors: (string | CompilerError)[]; |
|
map?: RawSourceMap; |
|
} |
|
export interface SFCTemplateCompileOptions { |
|
source: string; |
|
ast?: RootNode; |
|
filename: string; |
|
id: string; |
|
scoped?: boolean; |
|
slotted?: boolean; |
|
isProd?: boolean; |
|
ssr?: boolean; |
|
ssrCssVars?: string[]; |
|
inMap?: RawSourceMap; |
|
compiler?: TemplateCompiler; |
|
compilerOptions?: CompilerOptions; |
|
preprocessLang?: string; |
|
preprocessOptions?: any; |
|
|
|
|
|
|
|
|
|
|
|
preprocessCustomRequire?: (id: string) => any; |
|
|
|
|
|
|
|
|
|
transformAssetUrls?: AssetURLOptions | AssetURLTagConfig | boolean; |
|
} |
|
export declare function compileTemplate(options: SFCTemplateCompileOptions): SFCTemplateCompileResults; |
|
|
|
export interface SFCScriptCompileOptions { |
|
|
|
|
|
|
|
|
|
id: string; |
|
|
|
|
|
|
|
isProd?: boolean; |
|
|
|
|
|
|
|
sourceMap?: boolean; |
|
|
|
|
|
|
|
babelParserPlugins?: ParserPlugin[]; |
|
|
|
|
|
|
|
|
|
globalTypeFiles?: string[]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inlineTemplate?: boolean; |
|
|
|
|
|
|
|
|
|
|
|
genDefaultAs?: string; |
|
|
|
|
|
|
|
|
|
|
|
templateOptions?: Partial<SFCTemplateCompileOptions>; |
|
|
|
|
|
|
|
|
|
|
|
hoistStatic?: boolean; |
|
|
|
|
|
|
|
|
|
propsDestructure?: boolean; |
|
|
|
|
|
|
|
|
|
|
|
fs?: { |
|
fileExists(file: string): boolean; |
|
readFile(file: string): string | undefined; |
|
realpath?(file: string): string; |
|
}; |
|
|
|
|
|
|
|
customElement?: boolean | ((filename: string) => boolean); |
|
} |
|
interface ImportBinding { |
|
isType: boolean; |
|
imported: string; |
|
local: string; |
|
source: string; |
|
isFromSetup: boolean; |
|
isUsedInTemplate: boolean; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
export declare function compileScript(sfc: SFCDescriptor, options: SFCScriptCompileOptions): SFCScriptBlock; |
|
|
|
export interface SFCParseOptions { |
|
filename?: string; |
|
sourceMap?: boolean; |
|
sourceRoot?: string; |
|
pad?: boolean | 'line' | 'space'; |
|
ignoreEmpty?: boolean; |
|
compiler?: TemplateCompiler; |
|
templateParseOptions?: ParserOptions; |
|
|
|
|
|
|
|
|
|
parseExpressions?: boolean; |
|
} |
|
export interface SFCBlock { |
|
type: string; |
|
content: string; |
|
attrs: Record<string, string | true>; |
|
loc: SourceLocation; |
|
map?: RawSourceMap; |
|
lang?: string; |
|
src?: string; |
|
} |
|
export interface SFCTemplateBlock extends SFCBlock { |
|
type: 'template'; |
|
ast?: RootNode; |
|
} |
|
export interface SFCScriptBlock extends SFCBlock { |
|
type: 'script'; |
|
setup?: string | boolean; |
|
bindings?: BindingMetadata$1; |
|
imports?: Record<string, ImportBinding>; |
|
scriptAst?: _babel_types.Statement[]; |
|
scriptSetupAst?: _babel_types.Statement[]; |
|
warnings?: string[]; |
|
|
|
|
|
|
|
|
|
|
|
deps?: string[]; |
|
} |
|
export interface SFCStyleBlock extends SFCBlock { |
|
type: 'style'; |
|
scoped?: boolean; |
|
module?: string | boolean; |
|
} |
|
export interface SFCDescriptor { |
|
filename: string; |
|
source: string; |
|
template: SFCTemplateBlock | null; |
|
script: SFCScriptBlock | null; |
|
scriptSetup: SFCScriptBlock | null; |
|
styles: SFCStyleBlock[]; |
|
customBlocks: SFCBlock[]; |
|
cssVars: string[]; |
|
|
|
|
|
|
|
|
|
slotted: boolean; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shouldForceReload: (prevImports: Record<string, ImportBinding>) => boolean; |
|
} |
|
export interface SFCParseResult { |
|
descriptor: SFCDescriptor; |
|
errors: (CompilerError | SyntaxError)[]; |
|
} |
|
export declare function parse(source: string, options?: SFCParseOptions): SFCParseResult; |
|
|
|
type PreprocessLang = 'less' | 'sass' | 'scss' | 'styl' | 'stylus'; |
|
|
|
export interface SFCStyleCompileOptions { |
|
source: string; |
|
filename: string; |
|
id: string; |
|
scoped?: boolean; |
|
trim?: boolean; |
|
isProd?: boolean; |
|
inMap?: RawSourceMap; |
|
preprocessLang?: PreprocessLang; |
|
preprocessOptions?: any; |
|
preprocessCustomRequire?: (id: string) => any; |
|
postcssOptions?: any; |
|
postcssPlugins?: any[]; |
|
|
|
|
|
|
|
map?: RawSourceMap; |
|
} |
|
|
|
|
|
|
|
|
|
interface CSSModulesOptions { |
|
scopeBehaviour?: 'global' | 'local'; |
|
generateScopedName?: string | ((name: string, filename: string, css: string) => string); |
|
hashPrefix?: string; |
|
localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly'; |
|
exportGlobals?: boolean; |
|
globalModulePaths?: RegExp[]; |
|
} |
|
export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions { |
|
isAsync?: boolean; |
|
modules?: boolean; |
|
modulesOptions?: CSSModulesOptions; |
|
} |
|
export interface SFCStyleCompileResults { |
|
code: string; |
|
map: RawSourceMap | undefined; |
|
rawResult: Result | LazyResult | undefined; |
|
errors: Error[]; |
|
modules?: Record<string, string>; |
|
dependencies: Set<string>; |
|
} |
|
export declare function compileStyle(options: SFCStyleCompileOptions): SFCStyleCompileResults; |
|
export declare function compileStyleAsync(options: SFCAsyncStyleCompileOptions): Promise<SFCStyleCompileResults>; |
|
|
|
export declare function rewriteDefault(input: string, as: string, parserPlugins?: ParserPlugin[]): string; |
|
|
|
|
|
|
|
|
|
export declare function rewriteDefaultAST(ast: Statement[], s: MagicString, as: string): void; |
|
|
|
type PropsDestructureBindings = Record<string, |
|
{ |
|
local: string; |
|
default?: Expression; |
|
}>; |
|
export declare function extractRuntimeProps(ctx: TypeResolveContext): string | undefined; |
|
|
|
interface ModelDecl { |
|
type: TSType | undefined; |
|
options: string | undefined; |
|
identifier: string | undefined; |
|
runtimeOptionNodes: Node[]; |
|
} |
|
|
|
declare enum BindingTypes { |
|
|
|
|
|
|
|
DATA = "data", |
|
|
|
|
|
|
|
PROPS = "props", |
|
|
|
|
|
|
|
|
|
PROPS_ALIASED = "props-aliased", |
|
|
|
|
|
|
|
SETUP_LET = "setup-let", |
|
|
|
|
|
|
|
|
|
|
|
SETUP_CONST = "setup-const", |
|
|
|
|
|
|
|
SETUP_REACTIVE_CONST = "setup-reactive-const", |
|
|
|
|
|
|
|
SETUP_MAYBE_REF = "setup-maybe-ref", |
|
|
|
|
|
|
|
SETUP_REF = "setup-ref", |
|
|
|
|
|
|
|
OPTIONS = "options", |
|
|
|
|
|
|
|
LITERAL_CONST = "literal-const" |
|
} |
|
type BindingMetadata = { |
|
[key: string]: BindingTypes | undefined; |
|
} & { |
|
__isScriptSetup?: boolean; |
|
__propsAliases?: Record<string, string>; |
|
}; |
|
|
|
export declare class ScriptCompileContext { |
|
descriptor: SFCDescriptor; |
|
options: Partial<SFCScriptCompileOptions>; |
|
isJS: boolean; |
|
isTS: boolean; |
|
isCE: boolean; |
|
scriptAst: Program | null; |
|
scriptSetupAst: Program | null; |
|
source: string; |
|
filename: string; |
|
s: MagicString; |
|
startOffset: number | undefined; |
|
endOffset: number | undefined; |
|
scope?: TypeScope; |
|
globalScopes?: TypeScope[]; |
|
userImports: Record<string, ImportBinding>; |
|
hasDefinePropsCall: boolean; |
|
hasDefineEmitCall: boolean; |
|
hasDefineExposeCall: boolean; |
|
hasDefaultExportName: boolean; |
|
hasDefaultExportRender: boolean; |
|
hasDefineOptionsCall: boolean; |
|
hasDefineSlotsCall: boolean; |
|
hasDefineModelCall: boolean; |
|
propsCall: CallExpression | undefined; |
|
propsDecl: Node | undefined; |
|
propsRuntimeDecl: Node | undefined; |
|
propsTypeDecl: Node | undefined; |
|
propsDestructureDecl: ObjectPattern | undefined; |
|
propsDestructuredBindings: PropsDestructureBindings; |
|
propsDestructureRestId: string | undefined; |
|
propsRuntimeDefaults: Node | undefined; |
|
emitsRuntimeDecl: Node | undefined; |
|
emitsTypeDecl: Node | undefined; |
|
emitDecl: Node | undefined; |
|
modelDecls: Record<string, ModelDecl>; |
|
optionsRuntimeDecl: Node | undefined; |
|
bindingMetadata: BindingMetadata; |
|
helperImports: Set<string>; |
|
helper(key: string): string; |
|
|
|
|
|
|
|
deps?: Set<string>; |
|
|
|
|
|
|
|
fs?: NonNullable<SFCScriptCompileOptions['fs']>; |
|
constructor(descriptor: SFCDescriptor, options: Partial<SFCScriptCompileOptions>); |
|
getString(node: Node, scriptSetup?: boolean): string; |
|
error(msg: string, node: Node, scope?: TypeScope): never; |
|
} |
|
|
|
export type SimpleTypeResolveOptions = Partial<Pick<SFCScriptCompileOptions, 'globalTypeFiles' | 'fs' | 'babelParserPlugins' | 'isProd'>>; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type SimpleTypeResolveContext = Pick<ScriptCompileContext, 'source' | 'filename' | 'error' | 'helper' | 'getString' | 'propsTypeDecl' | 'propsRuntimeDefaults' | 'propsDestructuredBindings' | 'emitsTypeDecl' | 'isCE'> & Partial<Pick<ScriptCompileContext, 'scope' | 'globalScopes' | 'deps' | 'fs'>> & { |
|
ast: Statement[]; |
|
options: SimpleTypeResolveOptions; |
|
}; |
|
export type TypeResolveContext = ScriptCompileContext | SimpleTypeResolveContext; |
|
type Import = Pick<ImportBinding, 'source' | 'imported'>; |
|
interface WithScope { |
|
_ownerScope: TypeScope; |
|
} |
|
type ScopeTypeNode = Node & WithScope & { |
|
_ns?: TSModuleDeclaration & WithScope; |
|
}; |
|
declare class TypeScope { |
|
filename: string; |
|
source: string; |
|
offset: number; |
|
imports: Record<string, Import>; |
|
types: Record<string, ScopeTypeNode>; |
|
declares: Record<string, ScopeTypeNode>; |
|
constructor(filename: string, source: string, offset?: number, imports?: Record<string, Import>, types?: Record<string, ScopeTypeNode>, declares?: Record<string, ScopeTypeNode>); |
|
isGenericScope: boolean; |
|
resolvedImportSources: Record<string, string>; |
|
exportedTypes: Record<string, ScopeTypeNode>; |
|
exportedDeclares: Record<string, ScopeTypeNode>; |
|
} |
|
interface MaybeWithScope { |
|
_ownerScope?: TypeScope; |
|
} |
|
interface ResolvedElements { |
|
props: Record<string, (TSPropertySignature | TSMethodSignature) & { |
|
_ownerScope: TypeScope; |
|
}>; |
|
calls?: (TSCallSignatureDeclaration | TSFunctionType)[]; |
|
} |
|
|
|
|
|
|
|
|
|
export declare function resolveTypeElements(ctx: TypeResolveContext, node: Node & MaybeWithScope & { |
|
_resolvedElements?: ResolvedElements; |
|
}, scope?: TypeScope, typeParameters?: Record<string, Node>): ResolvedElements; |
|
|
|
|
|
|
|
export declare function registerTS(_loadTS: () => typeof TS): void; |
|
|
|
|
|
|
|
export declare function invalidateTypeCache(filename: string): void; |
|
export declare function inferRuntimeType(ctx: TypeResolveContext, node: Node & MaybeWithScope, scope?: TypeScope): string[]; |
|
|
|
export declare function extractRuntimeEmits(ctx: TypeResolveContext): Set<string>; |
|
|
|
export declare const version: string; |
|
|
|
export declare const parseCache: Map<string, SFCParseResult>; |
|
export declare const errorMessages: { |
|
0: string; |
|
1: string; |
|
2: string; |
|
3: string; |
|
4: string; |
|
5: string; |
|
6: string; |
|
7: string; |
|
8: string; |
|
9: string; |
|
10: string; |
|
11: string; |
|
12: string; |
|
13: string; |
|
14: string; |
|
15: string; |
|
16: string; |
|
17: string; |
|
18: string; |
|
19: string; |
|
20: string; |
|
21: string; |
|
22: string; |
|
23: string; |
|
24: string; |
|
25: string; |
|
26: string; |
|
27: string; |
|
28: string; |
|
29: string; |
|
30: string; |
|
31: string; |
|
32: string; |
|
33: string; |
|
34: string; |
|
35: string; |
|
36: string; |
|
37: string; |
|
38: string; |
|
39: string; |
|
40: string; |
|
41: string; |
|
42: string; |
|
43: string; |
|
44: string; |
|
45: string; |
|
46: string; |
|
47: string; |
|
48: string; |
|
49: string; |
|
50: string; |
|
51: string; |
|
52: string; |
|
53: string; |
|
}; |
|
|
|
export declare const walk: any; |
|
|
|
|
|
|
|
|
|
|
|
|
|
export declare const shouldTransformRef: () => boolean; |
|
|
|
|