mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-25 06:50:34 +03:00
fix: add warning for v1 boolean attribute syntax
This commit is contained in:
+5
-1
@@ -1,7 +1,7 @@
|
|||||||
import deepmerge from 'deepmerge'
|
import deepmerge from 'deepmerge'
|
||||||
import { findIndex } from '../utils/array'
|
import { findIndex } from '../utils/array'
|
||||||
import { applyTemplate } from './template'
|
import { applyTemplate } from './template'
|
||||||
import { metaInfoAttributeKeys } from './constants'
|
import { metaInfoAttributeKeys, booleanHtmlAttributes } from './constants'
|
||||||
|
|
||||||
export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) {
|
export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) {
|
||||||
// we concat the arrays without merging objects contained in,
|
// we concat the arrays without merging objects contained in,
|
||||||
@@ -80,6 +80,10 @@ export function merge(target, source, options = {}) {
|
|||||||
|
|
||||||
for (const key in source[attrKey]) {
|
for (const key in source[attrKey]) {
|
||||||
if (source[attrKey].hasOwnProperty(key) && source[attrKey][key] === undefined) {
|
if (source[attrKey].hasOwnProperty(key) && source[attrKey][key] === undefined) {
|
||||||
|
if (booleanHtmlAttributes.includes(key)) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn('VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details')
|
||||||
|
}
|
||||||
delete source[attrKey][key]
|
delete source[attrKey][key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -820,4 +820,36 @@ describe('getMetaInfo', () => {
|
|||||||
__dangerouslyDisableSanitizersByTagID: {}
|
__dangerouslyDisableSanitizersByTagID: {}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test.only('prints warning for boolean attributes with value undefined', () => {
|
||||||
|
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
|
||||||
|
|
||||||
|
const component = new Vue({
|
||||||
|
metaInfo: {
|
||||||
|
htmlAttrs: {
|
||||||
|
amp: undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(getMetaInfo(component)).toEqual({
|
||||||
|
title: undefined,
|
||||||
|
titleChunk: '',
|
||||||
|
titleTemplate: '%s',
|
||||||
|
htmlAttrs: {},
|
||||||
|
headAttrs: {},
|
||||||
|
bodyAttrs: {},
|
||||||
|
meta: [],
|
||||||
|
base: [],
|
||||||
|
link: [],
|
||||||
|
style: [],
|
||||||
|
script: [],
|
||||||
|
noscript: [],
|
||||||
|
__dangerouslyDisableSanitizers: [],
|
||||||
|
__dangerouslyDisableSanitizersByTagID: {}
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(warn).toHaveBeenCalledTimes(1)
|
||||||
|
expect(warn).toHaveBeenCalledWith(expect.stringMatching('the value undefined'))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user