Skip to content

Commit

Permalink
feat: add warning for v1 boolean attribute syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Jun 22, 2019
1 parent be5f1d0 commit e9397b1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/shared/merge.js
@@ -1,7 +1,7 @@
import deepmerge from 'deepmerge'
import { findIndex } from '../utils/array'
import { applyTemplate } from './template'
import { metaInfoAttributeKeys } from './constants'
import { metaInfoAttributeKeys, booleanHtmlAttributes } from './constants'

export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, contentKeyName }, target, source) {
// we concat the arrays without merging objects contained in,
Expand Down Expand Up @@ -80,6 +80,10 @@ export function merge(target, source, options = {}) {

for (const key in source[attrKey]) {
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]
}
}
Expand Down
32 changes: 32 additions & 0 deletions test/unit/getMetaInfo.test.js
Expand Up @@ -820,4 +820,36 @@ describe('getMetaInfo', () => {
__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'))
})
})

0 comments on commit e9397b1

Please sign in to comment.