Skip to content

Commit

Permalink
fix: further align types with v3
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 16, 2022
1 parent fa2115c commit 2726b6d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
18 changes: 7 additions & 11 deletions packages/compiler-sfc/src/compileTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
BindingMetadata,
VueTemplateCompiler,
VueTemplateCompilerOptions
} from './types'
import { BindingMetadata, TemplateCompiler } from './types'
import assetUrlsModule, {
AssetURLOptions,
TransformAssetUrlsOptions
Expand All @@ -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
Expand All @@ -31,7 +27,7 @@ export interface SFCTemplateCompileOptions {
bindings?: BindingMetadata
}

export interface SFCTemplateCompileResult {
export interface SFCTemplateCompileResults {
ast: Object | undefined
code: string
source: string
Expand All @@ -41,7 +37,7 @@ export interface SFCTemplateCompileResult {

export function compileTemplate(
options: SFCTemplateCompileOptions
): SFCTemplateCompileResult {
): SFCTemplateCompileResults {
const { preprocessLang } = options
const preprocessor = preprocessLang && consolidate[preprocessLang]
if (preprocessor) {
Expand Down Expand Up @@ -100,7 +96,7 @@ function preprocess(

function actuallyCompile(
options: SFCTemplateCompileOptions
): SFCTemplateCompileResult {
): SFCTemplateCompileResults {
const {
source,
compiler = _compiler,
Expand Down
11 changes: 9 additions & 2 deletions packages/compiler-sfc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 2 additions & 2 deletions packages/compiler-sfc/src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SourceMapGenerator } from 'source-map'
import { RawSourceMap, VueTemplateCompiler } from './types'
import { RawSourceMap, TemplateCompiler } from './types'
import {
parseComponent,
VueTemplateCompilerParseOptions,
Expand All @@ -19,7 +19,7 @@ const emptyRE = /^(?:\/\/)?\s*$/
export interface ParseOptions {
source: string
filename?: string
compiler?: VueTemplateCompiler
compiler?: TemplateCompiler
compilerParseOptions?: VueTemplateCompilerParseOptions
sourceRoot?: string
needMap?: boolean
Expand Down
21 changes: 3 additions & 18 deletions packages/compiler-sfc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2726b6d

Please sign in to comment.