refactor: move compile into compiler-core

This commit is contained in:
Evan You
2019-09-20 12:16:19 -04:00
parent 3e1973f065
commit 8a923f6a52
12 changed files with 106 additions and 77 deletions

View File

@@ -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'