/* @flow */ import { genHandlers } from './events' import baseDirectives from '../directives/index' import { camelize, no, extend } from 'shared/util' import { baseWarn, pluckModuleFunction } from '../helpers' import { emptySlotScopeToken } from '../parser/index' type TransformFunction = (el: ASTElement, code: string) => string; type DataGenFunction = (el: ASTElement) => string; type DirectiveFunction = (el: ASTElement, dir: ASTDirective, warn: Function) => boolean; export class CodegenState { options: CompilerOptions; warn: Function; transforms: Array; dataGenFns: Array; directives: { [key: string]: DirectiveFunction }; maybeComponent: (el: ASTElement) => boolean; onceId: number; staticRenderFns: Array; pre: boolean; constructor (options: CompilerOptions) { this.options = options this.warn = options.warn || baseWarn this.transforms = pluckModuleFunction(options.modules, 'transformCode') this.dataGenFns = pluckModuleFunction(options.modules, 'genData') this.directives = extend(extend({}, baseDirectives), options.directives) const isReservedTag = options.isReservedTag || no this.maybeComponent = (el: ASTElement) => !!el.component || !isReservedTag(el.tag) this.onceId = 0 this.staticRenderFns = [] this.pre = false } } export type CodegenResult = { render: string, staticRenderFns: Array }; export function generate ( ast: ASTElement | void, options: CompilerOptions ): CodegenResult { const state = new CodegenState(options) // fix #11483, Root level