Skip to content

Commit

Permalink
types: align compiler-sfc type exports with v3
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 16, 2022
1 parent b3432ff commit 457fe6d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const isBuiltInDir = makeMap(
`once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`
)

export interface ScriptCompileOptions {
export interface SFCScriptCompileOptions {
/**
* Production mode. Used to determine whether to generate hashed CSS variables
*/
Expand Down Expand Up @@ -87,7 +87,7 @@ export interface ImportBinding {
*/
export function compileScript(
sfc: SFCDescriptor,
options: ScriptCompileOptions = {}
options: SFCScriptCompileOptions = {}
): SFCScriptBlock {
let { filename, script, scriptSetup, source } = sfc
const isProd = !!options.isProd
Expand Down
24 changes: 12 additions & 12 deletions packages/compiler-sfc/src/compileStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
StylePreprocessorResults
} from './stylePreprocessors'

export interface StyleCompileOptions {
export interface SFCStyleCompileOptions {
source: string
filename: string
id: string
Expand All @@ -21,32 +21,32 @@ 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: any | void
rawResult: LazyResult | void
errors: string[]
}

export function compileStyle(
options: StyleCompileOptions
): StyleCompileResults {
options: SFCStyleCompileOptions
): SFCStyleCompileResults {
return doCompileStyle({ ...options, isAsync: false })
}

export function compileStyleAsync(
options: StyleCompileOptions
): Promise<StyleCompileResults> {
options: SFCStyleCompileOptions
): Promise<SFCStyleCompileResults> {
return Promise.resolve(doCompileStyle({ ...options, isAsync: true }))
}

export function doCompileStyle(
options: AsyncStyleCompileOptions
): StyleCompileResults {
options: SFCAsyncStyleCompileOptions
): SFCStyleCompileResults {
const {
filename,
id,
Expand Down Expand Up @@ -94,15 +94,15 @@ export function doCompileStyle(
if (options.isAsync) {
return result
.then(
(result: LazyResult): StyleCompileResults => ({
(result: LazyResult): SFCStyleCompileResults => ({
code: result.css || '',
map: result.map && result.map.toJSON(),
errors,
rawResult: result
})
)
.catch(
(error: Error): StyleCompileResults => ({
(error: Error): SFCStyleCompileResults => ({
code: '',
map: undefined,
errors: [...errors, error.message],
Expand All @@ -127,7 +127,7 @@ export function doCompileStyle(
}

function preprocess(
options: StyleCompileOptions,
options: SFCStyleCompileOptions,
preprocessor: StylePreprocessor
): StylePreprocessorResults {
return preprocessor(
Expand Down
14 changes: 7 additions & 7 deletions packages/compiler-sfc/src/compileTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as _compiler from 'web/entry-compiler'
import { prefixIdentifiers } from './prefixIdentifiers'
import { WarningMessage } from 'types/compiler'

export interface TemplateCompileOptions {
export interface SFCTemplateCompileOptions {
source: string
filename: string
compiler?: VueTemplateCompiler
Expand All @@ -31,7 +31,7 @@ export interface TemplateCompileOptions {
bindings?: BindingMetadata
}

export interface TemplateCompileResult {
export interface SFCTemplateCompileResult {
ast: Object | undefined
code: string
source: string
Expand All @@ -40,8 +40,8 @@ export interface TemplateCompileResult {
}

export function compileTemplate(
options: TemplateCompileOptions
): TemplateCompileResult {
options: SFCTemplateCompileOptions
): SFCTemplateCompileResult {
const { preprocessLang } = options
const preprocessor = preprocessLang && consolidate[preprocessLang]
if (preprocessor) {
Expand All @@ -68,7 +68,7 @@ export function compileTemplate(
}

function preprocess(
options: TemplateCompileOptions,
options: SFCTemplateCompileOptions,
preprocessor: any
): string {
const { source, filename, preprocessOptions } = options
Expand Down Expand Up @@ -99,8 +99,8 @@ function preprocess(
}

function actuallyCompile(
options: TemplateCompileOptions
): TemplateCompileResult {
options: SFCTemplateCompileOptions
): SFCTemplateCompileResult {
const {
source,
compiler = _compiler,
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler-sfc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export { generateCodeFrame } from 'compiler/codeframe'
// types
export { SFCBlock, SFCCustomBlock, SFCDescriptor } from './parseComponent'
export {
TemplateCompileOptions,
TemplateCompileResult
SFCTemplateCompileOptions,
SFCTemplateCompileResult
} from './compileTemplate'
export { StyleCompileOptions, StyleCompileResults } from './compileStyle'
export { ScriptCompileOptions } from './compileScript'
export { SFCStyleCompileOptions, SFCStyleCompileResults } from './compileStyle'
export { SFCScriptCompileOptions } from './compileScript'

0 comments on commit 457fe6d

Please sign in to comment.