types: use more specific type names
This commit is contained in:
parent
fa5390fb6f
commit
a0ee4fbc36
@ -10,7 +10,7 @@ import {
|
||||
} from './stylePreprocessors'
|
||||
import { RawSourceMap } from 'source-map'
|
||||
|
||||
export interface StyleCompileOptions {
|
||||
export interface SFCStyleCompileOptions {
|
||||
source: string
|
||||
filename: string
|
||||
id: string
|
||||
@ -23,11 +23,11 @@ export interface StyleCompileOptions {
|
||||
postcssPlugins?: any[]
|
||||
}
|
||||
|
||||
export interface AsyncStyleCompileOptions extends StyleCompileOptions {
|
||||
export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
|
||||
isAsync?: boolean
|
||||
}
|
||||
|
||||
export interface StyleCompileResults {
|
||||
export interface SFCStyleCompileResults {
|
||||
code: string
|
||||
map: RawSourceMap | undefined
|
||||
rawResult: LazyResult | Result | undefined
|
||||
@ -35,22 +35,25 @@ export interface StyleCompileResults {
|
||||
}
|
||||
|
||||
export function compileStyle(
|
||||
options: StyleCompileOptions
|
||||
): StyleCompileResults {
|
||||
return doCompileStyle({ ...options, isAsync: false }) as StyleCompileResults
|
||||
options: SFCStyleCompileOptions
|
||||
): SFCStyleCompileResults {
|
||||
return doCompileStyle({
|
||||
...options,
|
||||
isAsync: false
|
||||
}) as SFCStyleCompileResults
|
||||
}
|
||||
|
||||
export function compileStyleAsync(
|
||||
options: StyleCompileOptions
|
||||
): Promise<StyleCompileResults> {
|
||||
options: SFCStyleCompileOptions
|
||||
): Promise<SFCStyleCompileResults> {
|
||||
return doCompileStyle({ ...options, isAsync: true }) as Promise<
|
||||
StyleCompileResults
|
||||
SFCStyleCompileResults
|
||||
>
|
||||
}
|
||||
|
||||
export function doCompileStyle(
|
||||
options: AsyncStyleCompileOptions
|
||||
): StyleCompileResults | Promise<StyleCompileResults> {
|
||||
options: SFCAsyncStyleCompileOptions
|
||||
): SFCStyleCompileResults | Promise<SFCStyleCompileResults> {
|
||||
const {
|
||||
filename,
|
||||
id,
|
||||
@ -131,7 +134,7 @@ export function doCompileStyle(
|
||||
}
|
||||
|
||||
function preprocess(
|
||||
options: StyleCompileOptions,
|
||||
options: SFCStyleCompileOptions,
|
||||
preprocessor: StylePreprocessor
|
||||
): StylePreprocessorResults {
|
||||
return preprocessor.render(options.source, options.map, {
|
||||
|
@ -14,7 +14,11 @@ import { transformSrcset } from './templateTransformSrcset'
|
||||
import { isObject } from '@vue/shared'
|
||||
import consolidate from 'consolidate'
|
||||
|
||||
export interface TemplateCompileResults {
|
||||
export interface TemplateCompiler {
|
||||
compile(template: string, options: CompilerOptions): CodegenResult
|
||||
}
|
||||
|
||||
export interface SFCTemplateCompileResults {
|
||||
code: string
|
||||
source: string
|
||||
tips: string[]
|
||||
@ -22,11 +26,7 @@ export interface TemplateCompileResults {
|
||||
map?: RawSourceMap
|
||||
}
|
||||
|
||||
export interface TemplateCompiler {
|
||||
compile(template: string, options: CompilerOptions): CodegenResult
|
||||
}
|
||||
|
||||
export interface TemplateCompileOptions {
|
||||
export interface SFCTemplateCompileOptions {
|
||||
source: string
|
||||
filename: string
|
||||
compiler?: TemplateCompiler
|
||||
@ -37,7 +37,7 @@ export interface TemplateCompileOptions {
|
||||
}
|
||||
|
||||
function preprocess(
|
||||
{ source, filename, preprocessOptions }: TemplateCompileOptions,
|
||||
{ source, filename, preprocessOptions }: SFCTemplateCompileOptions,
|
||||
preprocessor: any
|
||||
): string {
|
||||
// Consolidate exposes a callback based API, but the callback is in fact
|
||||
@ -59,8 +59,8 @@ function preprocess(
|
||||
}
|
||||
|
||||
export function compileTemplate(
|
||||
options: TemplateCompileOptions
|
||||
): TemplateCompileResults {
|
||||
options: SFCTemplateCompileOptions
|
||||
): SFCTemplateCompileResults {
|
||||
const { preprocessLang } = options
|
||||
const preprocessor =
|
||||
preprocessLang && consolidate[preprocessLang as keyof typeof consolidate]
|
||||
@ -104,7 +104,7 @@ function doCompileTemplate({
|
||||
compiler = require('@vue/compiler-dom'),
|
||||
compilerOptions = {},
|
||||
transformAssetUrls
|
||||
}: TemplateCompileOptions): TemplateCompileResults {
|
||||
}: SFCTemplateCompileOptions): SFCTemplateCompileResults {
|
||||
const errors: CompilerError[] = []
|
||||
|
||||
let nodeTransforms: NodeTransform[] = []
|
||||
|
@ -14,8 +14,8 @@ export {
|
||||
} from './parse'
|
||||
export {
|
||||
TemplateCompiler,
|
||||
TemplateCompileOptions,
|
||||
TemplateCompileResults
|
||||
SFCTemplateCompileOptions,
|
||||
SFCTemplateCompileResults
|
||||
} from './compileTemplate'
|
||||
export { StyleCompileOptions, StyleCompileResults } from './compileStyle'
|
||||
export { SFCStyleCompileOptions, SFCStyleCompileResults } from './compileStyle'
|
||||
export { CompilerOptions, generateCodeFrame } from '@vue/compiler-core'
|
||||
|
Loading…
Reference in New Issue
Block a user