From a5817edc2fcc4a078886318662d6dcb9fdb4678e Mon Sep 17 00:00:00 2001
From: NoTwoBoy <1244476905@qq.com>
Date: Wed, 20 Nov 2024 19:02:31 +0800
Subject: [PATCH 1/4] fix(compat): don't warn deprecation if compat config is
disabled
---
packages/runtime-core/src/compat/compatConfig.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/runtime-core/src/compat/compatConfig.ts b/packages/runtime-core/src/compat/compatConfig.ts
index de62873ff02..5260969d6ad 100644
--- a/packages/runtime-core/src/compat/compatConfig.ts
+++ b/packages/runtime-core/src/compat/compatConfig.ts
@@ -451,7 +451,7 @@ export function warnDeprecation(
// check user config
const config = getCompatConfigForKey(key, instance)
- if (config === 'suppress-warning') {
+ if (config === false || config === 'suppress-warning') {
return
}
From cdc251e7f2e011a39e15926231f1f283ce111524 Mon Sep 17 00:00:00 2001
From: NoTwoBoy <1244476905@qq.com>
Date: Thu, 21 Nov 2024 10:38:22 +0800
Subject: [PATCH 2/4] chore: add test
---
.../vue-compat/__tests__/compiler.spec.ts | 1 -
.../__tests__/warnDeprecation.spec.ts | 87 +++++++++++++++++++
2 files changed, 87 insertions(+), 1 deletion(-)
create mode 100644 packages/vue-compat/__tests__/warnDeprecation.spec.ts
diff --git a/packages/vue-compat/__tests__/compiler.spec.ts b/packages/vue-compat/__tests__/compiler.spec.ts
index 2ae2f211a10..8891e660778 100644
--- a/packages/vue-compat/__tests__/compiler.spec.ts
+++ b/packages/vue-compat/__tests__/compiler.spec.ts
@@ -16,7 +16,6 @@ afterEach(() => {
Vue.configureCompat({ MODE: 3 })
})
-// COMPILER_V_FOR_REF is tested in ./refInfor.spec.ts
// COMPILER_FILTERS is tested in ./filters.spec.ts
test('COMPILER_IS_ON_ELEMENT', () => {
diff --git a/packages/vue-compat/__tests__/warnDeprecation.spec.ts b/packages/vue-compat/__tests__/warnDeprecation.spec.ts
new file mode 100644
index 00000000000..5319b862e5a
--- /dev/null
+++ b/packages/vue-compat/__tests__/warnDeprecation.spec.ts
@@ -0,0 +1,87 @@
+import Vue from '@vue/compat'
+import {
+ DeprecationTypes,
+ deprecationData,
+ toggleDeprecationWarning,
+} from '../../runtime-core/src/compat/compatConfig'
+
+beforeEach(() => {
+ toggleDeprecationWarning(true)
+ Vue.configureCompat({
+ MODE: 2,
+ GLOBAL_MOUNT: 'suppress-warning',
+ })
+})
+
+afterEach(() => {
+ toggleDeprecationWarning(false)
+ Vue.configureCompat({ MODE: 3 })
+})
+
+describe('should warn deprecation while using compat', () => {
+ test('have no compat config', () => {
+ const vm = new Vue({
+ template: `
hello
`,
+ }).$mount()
+
+ expect(vm.$el).toBeInstanceOf(HTMLDivElement)
+ expect(vm.$el.outerHTML).toBe(`hello
`)
+
+ const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
+ .message as Function
+ expect(message('draggable', false, true)).toHaveBeenWarned()
+ })
+
+ test('set compat config to true', () => {
+ Vue.configureCompat({
+ ATTR_ENUMERATED_COERCION: true,
+ })
+
+ const vm = new Vue({
+ template: `hello
`,
+ }).$mount()
+
+ expect(vm.$el).toBeInstanceOf(HTMLDivElement)
+ expect(vm.$el.outerHTML).toBe(`hello
`)
+
+ const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
+ .message as Function
+ expect(message('draggable', false, true)).toHaveBeenWarned()
+ })
+
+ test('set compat config to "suppress-warning"', () => {
+ Vue.configureCompat({
+ ATTR_ENUMERATED_COERCION: 'suppress-warning',
+ })
+
+ const vm = new Vue({
+ template: `hello
`,
+ }).$mount()
+
+ expect(vm.$el).toBeInstanceOf(HTMLDivElement)
+ expect(vm.$el.outerHTML).toBe(`hello
`)
+
+ const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
+ .message as Function
+ expect(message('draggable', false, true)).not.toHaveBeenWarned()
+ expect(message('draggable', false, false)).not.toHaveBeenWarned()
+ })
+
+ test('set compat config to "suppress-warning"', () => {
+ Vue.configureCompat({
+ ATTR_ENUMERATED_COERCION: false,
+ })
+
+ const vm = new Vue({
+ template: `hello
`,
+ }).$mount()
+
+ expect(vm.$el).toBeInstanceOf(HTMLDivElement)
+ expect(vm.$el.outerHTML).toBe(`hello
`)
+
+ const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
+ .message as Function
+ expect(message('draggable', false, true)).not.toHaveBeenWarned()
+ expect(message('draggable', false, false)).not.toHaveBeenWarned()
+ })
+})
From c5eefdeed655c0c410bcbfd6b4527aa10a6a3dc9 Mon Sep 17 00:00:00 2001
From: NoTwoBoy <1244476905@qq.com>
Date: Thu, 21 Nov 2024 10:39:18 +0800
Subject: [PATCH 3/4] chore: optimize test description
---
packages/vue-compat/__tests__/warnDeprecation.spec.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/vue-compat/__tests__/warnDeprecation.spec.ts b/packages/vue-compat/__tests__/warnDeprecation.spec.ts
index 5319b862e5a..1f3fb88a2e2 100644
--- a/packages/vue-compat/__tests__/warnDeprecation.spec.ts
+++ b/packages/vue-compat/__tests__/warnDeprecation.spec.ts
@@ -67,7 +67,7 @@ describe('should warn deprecation while using compat', () => {
expect(message('draggable', false, false)).not.toHaveBeenWarned()
})
- test('set compat config to "suppress-warning"', () => {
+ test('set compat config to false', () => {
Vue.configureCompat({
ATTR_ENUMERATED_COERCION: false,
})
From 05f5af49b16c20fad685d7a9788fabce8efcaa4b Mon Sep 17 00:00:00 2001
From: NoTwoBoy <1244476905@qq.com>
Date: Thu, 21 Nov 2024 11:20:46 +0800
Subject: [PATCH 4/4] chore: update test
---
packages/runtime-dom/src/modules/attrs.ts | 5 +-
packages/vue-compat/__tests__/misc.spec.ts | 101 +++++++-----------
.../__tests__/warnDeprecation.spec.ts | 87 ---------------
3 files changed, 41 insertions(+), 152 deletions(-)
delete mode 100644 packages/vue-compat/__tests__/warnDeprecation.spec.ts
diff --git a/packages/runtime-dom/src/modules/attrs.ts b/packages/runtime-dom/src/modules/attrs.ts
index 95e0a14854a..55e971c2917 100644
--- a/packages/runtime-dom/src/modules/attrs.ts
+++ b/packages/runtime-dom/src/modules/attrs.ts
@@ -80,13 +80,12 @@ export function compatCoerceAttr(
} else if (
value === false &&
!isSpecialBooleanAttr(key) &&
- compatUtils.isCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, instance)
- ) {
- compatUtils.warnDeprecation(
+ compatUtils.softAssertCompatEnabled(
DeprecationTypes.ATTR_FALSE_VALUE,
instance,
key,
)
+ ) {
el.removeAttribute(key)
return true
}
diff --git a/packages/vue-compat/__tests__/misc.spec.ts b/packages/vue-compat/__tests__/misc.spec.ts
index 1a873633b85..cd2a970bbcf 100644
--- a/packages/vue-compat/__tests__/misc.spec.ts
+++ b/packages/vue-compat/__tests__/misc.spec.ts
@@ -158,35 +158,17 @@ test('CUSTOM_DIR', async () => {
expect(getCalls()).toMatchObject([1, 1, 0, 0, 0])
- expect(
- (deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
- 'bind',
- 'beforeMount',
- ),
- ).toHaveBeenWarned()
- expect(
- (deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
- 'inserted',
- 'mounted',
- ),
- ).toHaveBeenWarned()
+ const message = deprecationData[DeprecationTypes.CUSTOM_DIR]
+ .message as Function
+ expect(message('bind', 'beforeMount')).toHaveBeenWarned()
+ expect(message('inserted', 'mounted')).toHaveBeenWarned()
vm.foo++
await nextTick()
expect(getCalls()).toMatchObject([1, 1, 1, 1, 0])
- expect(
- (deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
- 'update',
- 'updated',
- ),
- ).toHaveBeenWarned()
- expect(
- (deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
- 'componentUpdated',
- 'updated',
- ),
- ).toHaveBeenWarned()
+ expect(message('update', 'updated')).toHaveBeenWarned()
+ expect(message('componentUpdated', 'updated')).toHaveBeenWarned()
})
test('ATTR_FALSE_VALUE', () => {
@@ -196,16 +178,28 @@ test('ATTR_FALSE_VALUE', () => {
expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.hasAttribute('id')).toBe(false)
expect(vm.$el.hasAttribute('foo')).toBe(false)
- expect(
- (deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
- 'id',
- ),
- ).toHaveBeenWarned()
- expect(
- (deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
- 'foo',
- ),
- ).toHaveBeenWarned()
+
+ const message = deprecationData[DeprecationTypes.ATTR_FALSE_VALUE]
+ .message as Function
+ expect(message('id')).toHaveBeenWarned()
+ expect(message('foo')).toHaveBeenWarned()
+})
+
+test(`ATTR_FALSE_VALUE with 'suppress-warning' value shouldn't throw warning`, () => {
+ const vm = new Vue({
+ template: ``,
+ compatConfig: {
+ ATTR_FALSE_VALUE: 'suppress-warning',
+ },
+ }).$mount()
+ expect(vm.$el).toBeInstanceOf(HTMLDivElement)
+ expect(vm.$el.hasAttribute('id')).toBe(false)
+ expect(vm.$el.hasAttribute('foo')).toBe(false)
+
+ const message = deprecationData[DeprecationTypes.ATTR_FALSE_VALUE]
+ .message as Function
+ expect(message('id')).not.toHaveBeenWarned()
+ expect(message('foo')).not.toHaveBeenWarned()
})
test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
@@ -221,16 +215,11 @@ test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
expect(vm.$el.getAttribute('id')).toBe('false')
expect(vm.$el.hasAttribute('foo')).toBe(true)
expect(vm.$el.getAttribute('foo')).toBe('false')
- expect(
- (deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
- 'id',
- ),
- ).not.toHaveBeenWarned()
- expect(
- (deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
- 'foo',
- ),
- ).not.toHaveBeenWarned()
+
+ const message = deprecationData[DeprecationTypes.ATTR_FALSE_VALUE]
+ .message as Function
+ expect(message('id')).not.toHaveBeenWarned()
+ expect(message('foo')).not.toHaveBeenWarned()
})
test('ATTR_ENUMERATED_COERCION', () => {
@@ -242,22 +231,10 @@ test('ATTR_ENUMERATED_COERCION', () => {
expect(vm.$el.getAttribute('draggable')).toBe('false')
expect(vm.$el.getAttribute('spellcheck')).toBe('true')
expect(vm.$el.getAttribute('contenteditable')).toBe('true')
- expect(
- (
- deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
- .message as Function
- )('draggable', null, 'false'),
- ).toHaveBeenWarned()
- expect(
- (
- deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
- .message as Function
- )('spellcheck', 0, 'true'),
- ).toHaveBeenWarned()
- expect(
- (
- deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
- .message as Function
- )('contenteditable', 'foo', 'true'),
- ).toHaveBeenWarned()
+
+ const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
+ .message as Function
+ expect(message('draggable', null, 'false')).toHaveBeenWarned()
+ expect(message('spellcheck', 0, 'true')).toHaveBeenWarned()
+ expect(message('contenteditable', 'foo', 'true')).toHaveBeenWarned()
})
diff --git a/packages/vue-compat/__tests__/warnDeprecation.spec.ts b/packages/vue-compat/__tests__/warnDeprecation.spec.ts
deleted file mode 100644
index 1f3fb88a2e2..00000000000
--- a/packages/vue-compat/__tests__/warnDeprecation.spec.ts
+++ /dev/null
@@ -1,87 +0,0 @@
-import Vue from '@vue/compat'
-import {
- DeprecationTypes,
- deprecationData,
- toggleDeprecationWarning,
-} from '../../runtime-core/src/compat/compatConfig'
-
-beforeEach(() => {
- toggleDeprecationWarning(true)
- Vue.configureCompat({
- MODE: 2,
- GLOBAL_MOUNT: 'suppress-warning',
- })
-})
-
-afterEach(() => {
- toggleDeprecationWarning(false)
- Vue.configureCompat({ MODE: 3 })
-})
-
-describe('should warn deprecation while using compat', () => {
- test('have no compat config', () => {
- const vm = new Vue({
- template: `hello
`,
- }).$mount()
-
- expect(vm.$el).toBeInstanceOf(HTMLDivElement)
- expect(vm.$el.outerHTML).toBe(`hello
`)
-
- const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
- .message as Function
- expect(message('draggable', false, true)).toHaveBeenWarned()
- })
-
- test('set compat config to true', () => {
- Vue.configureCompat({
- ATTR_ENUMERATED_COERCION: true,
- })
-
- const vm = new Vue({
- template: `hello
`,
- }).$mount()
-
- expect(vm.$el).toBeInstanceOf(HTMLDivElement)
- expect(vm.$el.outerHTML).toBe(`hello
`)
-
- const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
- .message as Function
- expect(message('draggable', false, true)).toHaveBeenWarned()
- })
-
- test('set compat config to "suppress-warning"', () => {
- Vue.configureCompat({
- ATTR_ENUMERATED_COERCION: 'suppress-warning',
- })
-
- const vm = new Vue({
- template: `hello
`,
- }).$mount()
-
- expect(vm.$el).toBeInstanceOf(HTMLDivElement)
- expect(vm.$el.outerHTML).toBe(`hello
`)
-
- const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
- .message as Function
- expect(message('draggable', false, true)).not.toHaveBeenWarned()
- expect(message('draggable', false, false)).not.toHaveBeenWarned()
- })
-
- test('set compat config to false', () => {
- Vue.configureCompat({
- ATTR_ENUMERATED_COERCION: false,
- })
-
- const vm = new Vue({
- template: `hello
`,
- }).$mount()
-
- expect(vm.$el).toBeInstanceOf(HTMLDivElement)
- expect(vm.$el.outerHTML).toBe(`hello
`)
-
- const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
- .message as Function
- expect(message('draggable', false, true)).not.toHaveBeenWarned()
- expect(message('draggable', false, false)).not.toHaveBeenWarned()
- })
-})