diff --git a/packages/compiler-sfc/src/compileTemplate.ts b/packages/compiler-sfc/src/compileTemplate.ts index d88adc0259..68e5be350a 100644 --- a/packages/compiler-sfc/src/compileTemplate.ts +++ b/packages/compiler-sfc/src/compileTemplate.ts @@ -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, diff --git a/packages/compiler-sfc/src/index.ts b/packages/compiler-sfc/src/index.ts index 083a3ba349..c682912768 100644 --- a/packages/compiler-sfc/src/index.ts +++ b/packages/compiler-sfc/src/index.ts @@ -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' diff --git a/packages/compiler-sfc/src/parse.ts b/packages/compiler-sfc/src/parse.ts index bd6381d13e..48209e8985 100644 --- a/packages/compiler-sfc/src/parse.ts +++ b/packages/compiler-sfc/src/parse.ts @@ -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 diff --git a/packages/compiler-sfc/src/types.ts b/packages/compiler-sfc/src/types.ts index 93564db3ca..c62f74c7bb 100644 --- a/packages/compiler-sfc/src/types.ts +++ b/packages/compiler-sfc/src/types.ts @@ -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()