2019-11-29 12:42:04 -05:00
|
|
|
import {
|
|
|
|
baseCompile,
|
2019-12-22 19:44:21 -05:00
|
|
|
baseParse,
|
2019-11-29 12:42:04 -05:00
|
|
|
CompilerOptions,
|
|
|
|
CodegenResult,
|
2019-12-22 19:44:21 -05:00
|
|
|
isBuiltInType,
|
2020-01-02 18:21:56 -05:00
|
|
|
ParserOptions,
|
|
|
|
RootNode
|
2019-11-29 12:42:04 -05:00
|
|
|
} from '@vue/compiler-core'
|
2019-09-17 11:57:25 -04:00
|
|
|
import { parserOptionsMinimal } from './parserOptionsMinimal'
|
|
|
|
import { parserOptionsStandard } from './parserOptionsStandard'
|
2019-10-03 16:55:14 -04:00
|
|
|
import { transformStyle } from './transforms/transformStyle'
|
2019-10-09 15:41:31 +01:00
|
|
|
import { transformCloak } from './transforms/vCloak'
|
2019-10-08 15:35:57 -04:00
|
|
|
import { transformVHtml } from './transforms/vHtml'
|
2019-10-10 15:18:19 +01:00
|
|
|
import { transformVText } from './transforms/vText'
|
2019-10-10 18:02:51 -04:00
|
|
|
import { transformModel } from './transforms/vModel'
|
2019-10-14 12:33:23 +08:00
|
|
|
import { transformOn } from './transforms/vOn'
|
2019-11-25 11:04:26 +08:00
|
|
|
import { transformShow } from './transforms/vShow'
|
2019-11-29 12:42:04 -05:00
|
|
|
import { TRANSITION, TRANSITION_GROUP } from './runtimeHelpers'
|
2019-09-17 11:57:25 -04:00
|
|
|
|
2019-12-22 19:44:21 -05:00
|
|
|
const parserOptions = __BROWSER__ ? parserOptionsMinimal : parserOptionsStandard
|
|
|
|
|
2019-09-20 00:12:37 -04:00
|
|
|
export function compile(
|
|
|
|
template: string,
|
|
|
|
options: CompilerOptions = {}
|
|
|
|
): CodegenResult {
|
2019-09-20 12:16:19 -04:00
|
|
|
return baseCompile(template, {
|
2019-12-22 19:44:21 -05:00
|
|
|
...parserOptions,
|
2019-09-20 12:16:19 -04:00
|
|
|
...options,
|
2019-10-03 16:55:14 -04:00
|
|
|
nodeTransforms: [transformStyle, ...(options.nodeTransforms || [])],
|
2019-09-21 17:42:12 -04:00
|
|
|
directiveTransforms: {
|
2019-10-09 15:41:31 +01:00
|
|
|
cloak: transformCloak,
|
2019-10-08 15:35:57 -04:00
|
|
|
html: transformVHtml,
|
2019-10-10 15:18:19 +01:00
|
|
|
text: transformVText,
|
2019-10-10 18:02:51 -04:00
|
|
|
model: transformModel, // override compiler-core
|
2019-10-14 12:33:23 +08:00
|
|
|
on: transformOn,
|
2019-11-25 11:04:26 +08:00
|
|
|
show: transformShow,
|
2019-09-21 17:42:12 -04:00
|
|
|
...(options.directiveTransforms || {})
|
2019-11-29 12:42:04 -05:00
|
|
|
},
|
|
|
|
isBuiltInComponent: tag => {
|
|
|
|
if (isBuiltInType(tag, `Transition`)) {
|
|
|
|
return TRANSITION
|
|
|
|
} else if (isBuiltInType(tag, `TransitionGroup`)) {
|
|
|
|
return TRANSITION_GROUP
|
|
|
|
}
|
2019-09-21 17:42:12 -04:00
|
|
|
}
|
2019-09-20 00:12:37 -04:00
|
|
|
})
|
|
|
|
}
|
2019-09-22 16:50:57 -04:00
|
|
|
|
2020-01-02 18:21:56 -05:00
|
|
|
export function parse(template: string, options: ParserOptions = {}): RootNode {
|
2019-12-22 19:44:21 -05:00
|
|
|
return baseParse(template, {
|
|
|
|
...parserOptions,
|
|
|
|
...options
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-22 16:50:57 -04:00
|
|
|
export * from '@vue/compiler-core'
|