fix(compiler-core): handle base-transition

This commit is contained in:
Evan You 2019-11-29 12:02:31 -05:00
parent 52239d137c
commit 52134a88d0
4 changed files with 31 additions and 8 deletions

View File

@ -10,7 +10,8 @@ import {
PORTAL, PORTAL,
RESOLVE_DYNAMIC_COMPONENT, RESOLVE_DYNAMIC_COMPONENT,
SUSPENSE, SUSPENSE,
KEEP_ALIVE KEEP_ALIVE,
BASE_TRANSITION
} from '../../src/runtimeHelpers' } from '../../src/runtimeHelpers'
import { import {
CallExpression, CallExpression,
@ -356,6 +357,30 @@ describe('compiler: element transform', () => {
assert(`KeepAlive`) assert(`KeepAlive`)
}) })
test('should handle <BaseTransition>', () => {
function assert(tag: string) {
const { root, node } = parseWithElementTransform(
`<${tag}><span /></${tag}>`
)
expect(root.components.length).toBe(0)
expect(root.helpers).toContain(BASE_TRANSITION)
expect(node.callee).toBe(CREATE_VNODE)
expect(node.arguments).toMatchObject([
BASE_TRANSITION,
`null`,
createObjectMatcher({
default: {
type: NodeTypes.JS_FUNCTION_EXPRESSION
},
_compiled: `[true]`
})
])
}
assert(`base-transition`)
assert(`BaseTransition`)
})
test('error on v-bind with no argument', () => { test('error on v-bind with no argument', () => {
const onError = jest.fn() const onError = jest.fn()
parseWithElementTransform(`<div v-bind/>`, { onError }) parseWithElementTransform(`<div v-bind/>`, { onError })

View File

@ -31,7 +31,7 @@ import { extend } from '@vue/shared'
// Portal and Fragment are native types, not components // Portal and Fragment are native types, not components
const isBuiltInComponent = /*#__PURE__*/ makeMap( const isBuiltInComponent = /*#__PURE__*/ makeMap(
`suspense,keep-alive,keepalive,transition`, `suspense,keep-alive,keepalive,base-transition`,
true true
) )

View File

@ -2,7 +2,6 @@ export const FRAGMENT = Symbol(__DEV__ ? `Fragment` : ``)
export const PORTAL = Symbol(__DEV__ ? `Portal` : ``) export const PORTAL = Symbol(__DEV__ ? `Portal` : ``)
export const SUSPENSE = Symbol(__DEV__ ? `Suspense` : ``) export const SUSPENSE = Symbol(__DEV__ ? `Suspense` : ``)
export const KEEP_ALIVE = Symbol(__DEV__ ? `KeepAlive` : ``) export const KEEP_ALIVE = Symbol(__DEV__ ? `KeepAlive` : ``)
export const TRANSITION = Symbol(__DEV__ ? `Transition` : ``)
export const BASE_TRANSITION = Symbol(__DEV__ ? `BaseTransition` : ``) export const BASE_TRANSITION = Symbol(__DEV__ ? `BaseTransition` : ``)
export const OPEN_BLOCK = Symbol(__DEV__ ? `openBlock` : ``) export const OPEN_BLOCK = Symbol(__DEV__ ? `openBlock` : ``)
export const CREATE_BLOCK = Symbol(__DEV__ ? `createBlock` : ``) export const CREATE_BLOCK = Symbol(__DEV__ ? `createBlock` : ``)
@ -32,7 +31,6 @@ export const helperNameMap: any = {
[PORTAL]: `Portal`, [PORTAL]: `Portal`,
[SUSPENSE]: `Suspense`, [SUSPENSE]: `Suspense`,
[KEEP_ALIVE]: `KeepAlive`, [KEEP_ALIVE]: `KeepAlive`,
[TRANSITION]: `Transition`,
[BASE_TRANSITION]: `BaseTransition`, [BASE_TRANSITION]: `BaseTransition`,
[OPEN_BLOCK]: `openBlock`, [OPEN_BLOCK]: `openBlock`,
[CREATE_BLOCK]: `createBlock`, [CREATE_BLOCK]: `createBlock`,

View File

@ -28,7 +28,7 @@ import {
PORTAL, PORTAL,
SUSPENSE, SUSPENSE,
KEEP_ALIVE, KEEP_ALIVE,
TRANSITION BASE_TRANSITION
} from '../runtimeHelpers' } from '../runtimeHelpers'
import { getInnerRange, isVSlot, toValidAssetId, findProp } from '../utils' import { getInnerRange, isVSlot, toValidAssetId, findProp } from '../utils'
import { buildSlots } from './vSlot' import { buildSlots } from './vSlot'
@ -60,7 +60,7 @@ export const transformElement: NodeTransform = (node, context) => {
const isPortal = isBuiltInType(tag, 'Portal') const isPortal = isBuiltInType(tag, 'Portal')
const isSuspense = isBuiltInType(tag, 'Suspense') const isSuspense = isBuiltInType(tag, 'Suspense')
const isKeepAlive = isBuiltInType(tag, 'KeepAlive') const isKeepAlive = isBuiltInType(tag, 'KeepAlive')
const isTransition = isBuiltInType(tag, 'Transition') const isBaseTransition = isBuiltInType(tag, 'BaseTransition')
const isComponent = tagType === ElementTypes.COMPONENT const isComponent = tagType === ElementTypes.COMPONENT
let hasProps = props.length > 0 let hasProps = props.length > 0
@ -102,8 +102,8 @@ export const transformElement: NodeTransform = (node, context) => {
nodeType = context.helper(SUSPENSE) nodeType = context.helper(SUSPENSE)
} else if (isKeepAlive) { } else if (isKeepAlive) {
nodeType = context.helper(KEEP_ALIVE) nodeType = context.helper(KEEP_ALIVE)
} else if (isTransition) { } else if (isBaseTransition) {
nodeType = context.helper(TRANSITION) nodeType = context.helper(BASE_TRANSITION)
} else if (isComponent) { } else if (isComponent) {
// user component w/ resolve // user component w/ resolve
context.helper(RESOLVE_COMPONENT) context.helper(RESOLVE_COMPONENT)