Evan You
8 years ago
7 changed files with 111 additions and 107 deletions
@ -0,0 +1,55 @@ |
|||
/* @flow */ |
|||
|
|||
import { extend } from 'shared/util' |
|||
import { detectErrors } from './error-detector' |
|||
import { createCompileToFunctionFn } from './to-function' |
|||
|
|||
export function createCompilerCreator (baseCompile: Function): Function { |
|||
return function createCompiler (baseOptions: CompilerOptions) { |
|||
function compile ( |
|||
template: string, |
|||
options?: CompilerOptions |
|||
): CompiledResult { |
|||
const finalOptions = Object.create(baseOptions) |
|||
const errors = [] |
|||
const tips = [] |
|||
finalOptions.warn = (msg, tip) => { |
|||
(tip ? tips : errors).push(msg) |
|||
} |
|||
|
|||
if (options) { |
|||
// merge custom modules
|
|||
if (options.modules) { |
|||
finalOptions.modules = |
|||
(baseOptions.modules || []).concat(options.modules) |
|||
} |
|||
// merge custom directives
|
|||
if (options.directives) { |
|||
finalOptions.directives = extend( |
|||
Object.create(baseOptions.directives), |
|||
options.directives |
|||
) |
|||
} |
|||
// copy other options
|
|||
for (const key in options) { |
|||
if (key !== 'modules' && key !== 'directives') { |
|||
finalOptions[key] = options[key] |
|||
} |
|||
} |
|||
} |
|||
|
|||
const compiled = baseCompile(template, finalOptions) |
|||
if (process.env.NODE_ENV !== 'production') { |
|||
errors.push.apply(errors, detectErrors(compiled.ast)) |
|||
} |
|||
compiled.errors = errors |
|||
compiled.tips = tips |
|||
return compiled |
|||
} |
|||
|
|||
return { |
|||
compile, |
|||
compileToFunctions: createCompileToFunctionFn(compile) |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
/* @flow */ |
|||
|
|||
import { baseOptions } from '../compiler/options' |
|||
import { createCompiler } from 'server/optimizing-compiler/index' |
|||
|
|||
const { compile, compileToFunctions } = createCompiler(baseOptions) |
|||
|
|||
export { |
|||
compile as ssrCompile, |
|||
compileToFunctions as ssrCompileToFunctions |
|||
} |
Loading…
Reference in new issue