import { CompilerOptions } from './options' ; import { baseParse } from './parse' ; import { transform , NodeTransform , DirectiveTransform } from './transform' ; import { generate , CodegenResult } from './codegen' ; import { RootNode } from './ast' ; import { isString , extend } from '@vue/shared' ; import { transformIf } from './transforms/vIf' ; import { transformFor } from './transforms/vFor' ; import { transformExpression } from './transforms/transformExpression' ; import { transformSlotOutlet } from './transforms/transformSlotOutlet' ; import { transformElement } from './transforms/transformElement' ; import { transformOn } from './transforms/vOn' ; import { transformBind } from './transforms/vBind' ; import { trackSlotScopes , trackVForSlotScopes } from './transforms/vSlot' ; import { transformText } from './transforms/transformText' ; import { transformOnce } from './transforms/vOnce' ; import { transformModel } from './transforms/vModel' ; import { transformFilter } from './compat/transformFilter' ; import { defaultOnError , createCompilerError , ErrorCodes } from './errors' ; import { transformMemo } from './transforms/vMemo' ; export type TransformPreset = [ NodeTransform [ ] , Record < string , DirectiveTransform > ] ; export function getBaseTransformPreset ( prefixIdentifiers ? ) { return [ [ transformOnce , transformIf , transformMemo , transformFor , ... ( __COMPAT__ ? [ transformFilter ] : [ ] ) , ... ( ! __BROWSER__ && prefixIdentifiers ? [ trackVForSlotScopes , transformExpression ] : __BROWSER__ && __DEV__ ? [ transformExpression ] : [ ] ) , transformSlotOutlet , transformElement , trackSlotScopes , transformText ] , { on : transformOn , bind : transformBind , model : transformModel } ] ; } export function baseCompile ( template , options = { } ) { const onError = options . onError || defaultOnError ; const isModuleMode = options . mode === 'module' ; if ( __BROWSER__ ) { if ( options . prefixIdentifiers === true ) { onError ( createCompilerError ( ErrorCodes . X_PREFIX_ID_NOT_SUPPORTED ) ) ; } else if ( isModuleMode ) { onError ( createCompilerError ( ErrorCodes . X_MODULE_MODE_NOT_SUPPORTED ) ) ; } } const prefixIdentifiers = ! __BROWSER__ && ( options . prefixIdentifiers === true || isModuleMode ) ; if ( ! prefixIdentifiers && options . cacheHandlers ) { onError ( createCompilerError ( ErrorCodes . X_CACHE_HANDLER_NOT_SUPPORTED ) ) ; } if ( options . scopeId && ! isModuleMode ) { onError ( createCompilerError ( ErrorCodes . X_SCOPE_ID_NOT_SUPPORTED ) ) ; } const ast = isString ( template ) ? baseParse ( template , options ) : template ; const [ nodeTransforms , directiveTransforms ] = getBaseTransformPreset ( prefixIdentifiers ) ; transform ( ast , extend ( { } , options , { prefixIdentifiers , nodeTransforms : [ ... nodeTransforms , ... ( options . nodeTransforms || [ ] ) ] , directiveTransforms : extend ( { } , directiveTransforms , options . directiveTransforms || { } ) } ) ) ; return generate ( ast , extend ( { } , options , { prefixIdentifiers } ) ) ; }