2019-11-29 17:42:04 +00:00
|
|
|
import {
|
|
|
|
baseCompile,
|
2019-12-23 00:44:21 +00:00
|
|
|
baseParse,
|
2019-11-29 17:42:04 +00:00
|
|
|
CompilerOptions,
|
|
|
|
CodegenResult,
|
2019-12-23 00:44:21 +00:00
|
|
|
isBuiltInType,
|
2020-01-02 23:21:56 +00:00
|
|
|
ParserOptions,
|
2020-02-04 17:20:51 +00:00
|
|
|
RootNode,
|
|
|
|
noopDirectiveTransform
|
2019-11-29 17:42:04 +00:00
|
|
|
} from '@vue/compiler-core'
|
2019-09-17 15:57:25 +00:00
|
|
|
import { parserOptionsMinimal } from './parserOptionsMinimal'
|
|
|
|
import { parserOptionsStandard } from './parserOptionsStandard'
|
2019-10-03 20:55:14 +00:00
|
|
|
import { transformStyle } from './transforms/transformStyle'
|
2019-10-08 19:35:57 +00:00
|
|
|
import { transformVHtml } from './transforms/vHtml'
|
2019-10-10 14:18:19 +00:00
|
|
|
import { transformVText } from './transforms/vText'
|
2019-10-10 22:02:51 +00:00
|
|
|
import { transformModel } from './transforms/vModel'
|
2019-10-14 04:33:23 +00:00
|
|
|
import { transformOn } from './transforms/vOn'
|
2019-11-25 03:04:26 +00:00
|
|
|
import { transformShow } from './transforms/vShow'
|
2019-11-29 17:42:04 +00:00
|
|
|
import { TRANSITION, TRANSITION_GROUP } from './runtimeHelpers'
|
2020-02-06 20:53:26 +00:00
|
|
|
import { warnTransitionChildren } from './transforms/warnTransitionChildren'
|
2019-09-17 15:57:25 +00:00
|
|
|
|
2020-02-02 05:05:27 +00:00
|
|
|
export const parserOptions = __BROWSER__
|
|
|
|
? parserOptionsMinimal
|
|
|
|
: parserOptionsStandard
|
2019-12-23 00:44:21 +00:00
|
|
|
|
2020-02-06 20:29:02 +00:00
|
|
|
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 {
|
2019-09-20 16:16:19 +00:00
|
|
|
return baseCompile(template, {
|
2019-12-23 00:44:21 +00:00
|
|
|
...parserOptions,
|
2019-09-20 16:16:19 +00:00
|
|
|
...options,
|
2020-02-06 20:53:26 +00:00
|
|
|
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,
|
2019-10-08 19:35:57 +00:00
|
|
|
html: transformVHtml,
|
2019-10-10 14:18:19 +00:00
|
|
|
text: transformVText,
|
2019-10-10 22:02:51 +00:00
|
|
|
model: transformModel, // override compiler-core
|
2019-10-14 04:33:23 +00:00
|
|
|
on: transformOn,
|
2019-11-25 03:04:26 +00:00
|
|
|
show: transformShow,
|
2019-09-21 21:42:12 +00:00
|
|
|
...(options.directiveTransforms || {})
|
2019-11-29 17:42:04 +00:00
|
|
|
},
|
2020-02-06 20:29:02 +00:00
|
|
|
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 {
|
2019-12-23 00:44:21 +00:00
|
|
|
return baseParse(template, {
|
|
|
|
...parserOptions,
|
|
|
|
...options
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-02-06 20:29:02 +00:00
|
|
|
export * from './runtimeHelpers'
|
2020-02-04 23:37:23 +00:00
|
|
|
export { transformStyle } from './transforms/transformStyle'
|
2020-02-05 19:23:03 +00:00
|
|
|
export { createDOMCompilerError, DOMErrorCodes } from './errors'
|
2019-09-22 20:50:57 +00:00
|
|
|
export * from '@vue/compiler-core'
|