refactor: move compile into compiler-core
This commit is contained in:
@@ -1,46 +1,23 @@
|
||||
import {
|
||||
parse,
|
||||
transform,
|
||||
generate,
|
||||
CompilerError,
|
||||
Transform,
|
||||
compile as baseCompile,
|
||||
CompilerOptions,
|
||||
CodegenResult
|
||||
} from '@vue/compiler-core'
|
||||
import { parserOptionsMinimal } from './parserOptionsMinimal'
|
||||
import { parserOptionsStandard } from './parserOptionsStandard'
|
||||
|
||||
const parserOptions = __BROWSER__ ? parserOptionsMinimal : parserOptionsStandard
|
||||
|
||||
export interface CompilerOptions {
|
||||
module?: boolean
|
||||
onError?(err: CompilerError): void
|
||||
transforms?: Transform[]
|
||||
}
|
||||
|
||||
export function compile(
|
||||
template: string,
|
||||
options: CompilerOptions = {}
|
||||
): CodegenResult {
|
||||
const {
|
||||
module = false,
|
||||
onError = (err: CompilerError) => {
|
||||
throw err
|
||||
},
|
||||
transforms = []
|
||||
} = options
|
||||
const ast = parse(template, {
|
||||
...parserOptions,
|
||||
onError
|
||||
})
|
||||
transform(ast, {
|
||||
return baseCompile(template, {
|
||||
...options,
|
||||
...(__BROWSER__ ? parserOptionsMinimal : parserOptionsStandard),
|
||||
transforms: [
|
||||
// TODO include core transforms
|
||||
// TODO include DOM transforms
|
||||
...transforms // user transforms
|
||||
],
|
||||
onError
|
||||
// TODO include DOM-specific transforms
|
||||
...(options.transforms || []) // extra user transforms
|
||||
]
|
||||
})
|
||||
return generate(ast, { module })
|
||||
}
|
||||
|
||||
export * from '@vue/compiler-core'
|
||||
|
||||
Reference in New Issue
Block a user