fix: further align types with v3

This commit is contained in:
Evan You 2022-06-16 17:45:33 +08:00
parent fa2115c031
commit 2726b6d9ff
4 changed files with 21 additions and 33 deletions

View File

@ -1,8 +1,4 @@
import {
BindingMetadata,
VueTemplateCompiler,
VueTemplateCompilerOptions
} from './types'
import { BindingMetadata, TemplateCompiler } from './types'
import assetUrlsModule, {
AssetURLOptions,
TransformAssetUrlsOptions
@ -11,13 +7,13 @@ import srcsetModule from './templateCompilerModules/srcset'
import consolidate from '@vue/consolidate'
import * as _compiler from 'web/entry-compiler'
import { prefixIdentifiers } from './prefixIdentifiers'
import { WarningMessage } from 'types/compiler'
import { CompilerOptions, WarningMessage } from 'types/compiler'
export interface SFCTemplateCompileOptions {
source: string
filename: string
compiler?: VueTemplateCompiler
compilerOptions?: VueTemplateCompilerOptions
compiler?: TemplateCompiler
compilerOptions?: CompilerOptions
transformAssetUrls?: AssetURLOptions | boolean
transformAssetUrlsOptions?: TransformAssetUrlsOptions
preprocessLang?: string
@ -31,7 +27,7 @@ export interface SFCTemplateCompileOptions {
bindings?: BindingMetadata
}
export interface SFCTemplateCompileResult {
export interface SFCTemplateCompileResults {
ast: Object | undefined
code: string
source: string
@ -41,7 +37,7 @@ export interface SFCTemplateCompileResult {
export function compileTemplate(
options: SFCTemplateCompileOptions
): SFCTemplateCompileResult {
): SFCTemplateCompileResults {
const { preprocessLang } = options
const preprocessor = preprocessLang && consolidate[preprocessLang]
if (preprocessor) {
@ -100,7 +96,7 @@ function preprocess(
function actuallyCompile(
options: SFCTemplateCompileOptions
): SFCTemplateCompileResult {
): SFCTemplateCompileResults {
const {
source,
compiler = _compiler,

View File

@ -6,10 +6,17 @@ export { compileScript } from './compileScript'
export { generateCodeFrame } from 'compiler/codeframe'
// types
export { SFCBlock, SFCCustomBlock, SFCDescriptor } from './parseComponent'
export { CompilerOptions } from 'types/compiler'
export { TemplateCompiler } from './types'
export {
SFCBlock,
SFCCustomBlock,
SFCScriptBlock,
SFCDescriptor
} from './parseComponent'
export {
SFCTemplateCompileOptions,
SFCTemplateCompileResult
SFCTemplateCompileResults
} from './compileTemplate'
export { SFCStyleCompileOptions, SFCStyleCompileResults } from './compileStyle'
export { SFCScriptCompileOptions } from './compileScript'

View File

@ -1,5 +1,5 @@
import { SourceMapGenerator } from 'source-map'
import { RawSourceMap, VueTemplateCompiler } from './types'
import { RawSourceMap, TemplateCompiler } from './types'
import {
parseComponent,
VueTemplateCompilerParseOptions,
@ -19,7 +19,7 @@ const emptyRE = /^(?:\/\/)?\s*$/
export interface ParseOptions {
source: string
filename?: string
compiler?: VueTemplateCompiler
compiler?: TemplateCompiler
compilerParseOptions?: VueTemplateCompilerParseOptions
sourceRoot?: string
needMap?: boolean

View File

@ -14,27 +14,12 @@ export interface RawSourceMap extends StartOfSourceMap {
mappings: string
}
export interface VueTemplateCompiler {
export interface TemplateCompiler {
parseComponent(source: string, options?: any): SFCDescriptor
compile(
template: string,
options: VueTemplateCompilerOptions
): VueTemplateCompilerResults
ssrCompile(
template: string,
options: VueTemplateCompilerOptions
): VueTemplateCompilerResults
compile(template: string, options: CompilerOptions): CompiledResult
ssrCompile(template: string, options: CompilerOptions): CompiledResult
}
// we'll just shim this much for now - in the future these types
// should come from vue-template-compiler directly, or this package should be
// part of the vue monorepo.
export type VueTemplateCompilerOptions = CompilerOptions
export type VueTemplateCompilerResults = CompiledResult
export const enum BindingTypes {
/**
* returned from data()