vue3-yuanma/packages/compiler-dom/src/index.ts

70 lines
2.0 KiB
TypeScript
Raw Normal View History

import {
baseCompile,
baseParse,
CompilerOptions,
CodegenResult,
isBuiltInType,
2020-01-02 23:21:56 +00:00
ParserOptions,
2020-02-04 17:20:51 +00:00
RootNode,
noopDirectiveTransform
} from '@vue/compiler-core'
import { parserOptionsMinimal } from './parserOptionsMinimal'
import { parserOptionsStandard } from './parserOptionsStandard'
import { transformStyle } from './transforms/transformStyle'
import { transformVHtml } from './transforms/vHtml'
import { transformVText } from './transforms/vText'
2019-10-10 22:02:51 +00:00
import { transformModel } from './transforms/vModel'
import { transformOn } from './transforms/vOn'
import { transformShow } from './transforms/vShow'
import { TRANSITION, TRANSITION_GROUP } from './runtimeHelpers'
import { warnTransitionChildren } from './transforms/warnTransitionChildren'
export const parserOptions = __BROWSER__
? parserOptionsMinimal
: parserOptionsStandard
export const isBuiltInDOMComponent = (tag: string): symbol | undefined => {
if (isBuiltInType(tag, `Transition`)) {
return TRANSITION
} else if (isBuiltInType(tag, `TransitionGroup`)) {
return TRANSITION_GROUP
}
}
2019-09-20 04:12:37 +00:00
export function compile(
template: string,
options: CompilerOptions = {}
): CodegenResult {
return baseCompile(template, {
...parserOptions,
...options,
nodeTransforms: [
transformStyle,
...(__DEV__ ? [warnTransitionChildren] : []),
...(options.nodeTransforms || [])
],
2019-09-21 21:42:12 +00:00
directiveTransforms: {
2020-02-04 17:20:51 +00:00
cloak: noopDirectiveTransform,
html: transformVHtml,
text: transformVText,
2019-10-10 22:02:51 +00:00
model: transformModel, // override compiler-core
on: transformOn,
show: transformShow,
2019-09-21 21:42:12 +00:00
...(options.directiveTransforms || {})
},
isBuiltInComponent: isBuiltInDOMComponent
2019-09-20 04:12:37 +00:00
})
}
2019-09-22 20:50:57 +00:00
2020-01-02 23:21:56 +00:00
export function parse(template: string, options: ParserOptions = {}): RootNode {
return baseParse(template, {
...parserOptions,
...options
})
}
export * from './runtimeHelpers'
export { transformStyle } from './transforms/transformStyle'
export { createDOMCompilerError, DOMErrorCodes } from './errors'
2019-09-22 20:50:57 +00:00
export * from '@vue/compiler-core'