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

65 lines
1.9 KiB
TypeScript
Raw Normal View History

import {
baseCompile,
baseParse,
CompilerOptions,
CodegenResult,
2020-01-03 07:21:56 +08:00
ParserOptions,
2020-02-05 01:20:51 +08:00
RootNode,
2020-02-07 14:06:51 +08:00
noopDirectiveTransform,
NodeTransform,
DirectiveTransform
} from '@vue/compiler-core'
import { parserOptions } from './parserOptions'
import { transformStyle } from './transforms/transformStyle'
import { transformVHtml } from './transforms/vHtml'
import { transformVText } from './transforms/vText'
2019-10-11 06:02:51 +08:00
import { transformModel } from './transforms/vModel'
import { transformOn } from './transforms/vOn'
import { transformShow } from './transforms/vShow'
import { warnTransitionChildren } from './transforms/warnTransitionChildren'
import { stringifyStatic } from './transforms/stringifyStatic'
export { parserOptions }
export const DOMNodeTransforms: NodeTransform[] = [
transformStyle,
...(__DEV__ ? [warnTransitionChildren] : [])
]
export const DOMDirectiveTransforms: Record<string, DirectiveTransform> = {
cloak: noopDirectiveTransform,
html: transformVHtml,
text: transformVText,
model: transformModel, // override compiler-core
on: transformOn, // override compiler-core
show: transformShow
2020-02-07 14:06:51 +08:00
}
2019-09-20 12:12:37 +08:00
export function compile(
template: string,
options: CompilerOptions = {}
): CodegenResult {
return baseCompile(template, {
...parserOptions,
...options,
nodeTransforms: [...DOMNodeTransforms, ...(options.nodeTransforms || [])],
2019-09-22 05:42:12 +08:00
directiveTransforms: {
...DOMDirectiveTransforms,
2019-09-22 05:42:12 +08:00
...(options.directiveTransforms || {})
},
transformHoist: __BROWSER__ ? null : stringifyStatic
2019-09-20 12:12:37 +08:00
})
}
2019-09-23 04:50:57 +08:00
2020-01-03 07:21:56 +08: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-23 04:50:57 +08:00
export * from '@vue/compiler-core'