wip: tests for compiler compat

This commit is contained in:
Evan You
2021-04-30 15:50:32 -04:00
parent b4c92ccf6b
commit bd3cc4d2c7
9 changed files with 271 additions and 79 deletions

View File

@@ -4,9 +4,11 @@ import { DeprecationTypes, isCompatEnabled } from './compatConfig'
export function shouldSkipAttr(
key: string,
value: any,
instance: ComponentInternalInstance
): boolean {
if (key === 'is') {
return true
}
if (
(key === 'class' || key === 'style') &&
isCompatEnabled(DeprecationTypes.INSTANCE_ATTRS_CLASS_STYLE, instance)

View File

@@ -114,6 +114,7 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) {
$listeners: getCompatListeners
} as PublicPropertiesMap)
/* istanbul ignore if */
if (isCompatEnabled(DeprecationTypes.PRIVATE_APIS, null)) {
extend(map, {
$vnode: i => i.vnode,

View File

@@ -20,7 +20,8 @@ import {
isReservedProp,
EMPTY_ARR,
def,
extend
extend,
isOn
} from '@vue/shared'
import { warn } from './warning'
import {
@@ -207,7 +208,7 @@ export function updateProps(
// the props.
const propsToUpdate = instance.vnode.dynamicProps!
for (let i = 0; i < propsToUpdate.length; i++) {
const key = propsToUpdate[i]
let key = propsToUpdate[i]
// PROPS flag guarantees rawProps to be non-null
const value = rawProps![key]
if (options) {
@@ -229,8 +230,12 @@ export function updateProps(
)
}
} else {
if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) {
continue
if (__COMPAT__) {
if (isOn(key) && key.endsWith('Native')) {
key = key.slice(0, -6) // remove Native postfix
} else if (shouldSkipAttr(key, instance)) {
continue
}
}
if (value !== attrs[key]) {
attrs[key] = value
@@ -308,7 +313,7 @@ function setFullProps(
const [options, needCastKeys] = instance.propsOptions
let hasAttrsChanged = false
if (rawProps) {
for (const key in rawProps) {
for (let key in rawProps) {
// key, ref are reserved and never passed down
if (isReservedProp(key)) {
continue
@@ -337,8 +342,12 @@ function setFullProps(
// Any non-declared (either as a prop or an emitted event) props are put
// into a separate `attrs` object for spreading. Make sure to preserve
// original key casing
if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) {
continue
if (__COMPAT__) {
if (isOn(key) && key.endsWith('Native')) {
key = key.slice(0, -6) // remove Native postfix
} else if (shouldSkipAttr(key, instance)) {
continue
}
}
if (value !== attrs[key]) {
attrs[key] = value