Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(warn): Warn component names hyphenated into reserved names, fix #8025 #8051

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(warn): Warn component names hyphenated into reserved names
Currently, component names like 'Map' is silently ignored, because they
translated into reserved names but the component names are not exactly
the same as the reserved names. The component names, thus, should be
hyphenated before checking if reserved.

Resolve #8025.
  • Loading branch information
Hyunje Jun committed Apr 19, 2018
commit 248ad53572d2782fc16bfc029b4fc21a6ea15c09
4 changes: 3 additions & 1 deletion src/core/util/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import config from '../config'
import { warn } from './debug'
import { nativeWatch } from './env'
import { set } from '../observer/index'
import { hyphenate } from '../../shared/util'

import {
ASSET_TYPES,
Expand Down Expand Up @@ -260,7 +261,8 @@ export function validateComponentName (name: string) {
'and must start with a letter.'
)
}
if (isBuiltInTag(name) || config.isReservedTag(name)) {
const hyphenatedName = hyphenate(name)
if (isBuiltInTag(hyphenatedName) || config.isReservedTag(hyphenatedName)) {
warn(
'Do not use built-in or reserved HTML elements as component ' +
'id: ' + name
Expand Down
9 changes: 9 additions & 0 deletions test/unit/features/options/components.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ describe('Options components', () => {
expect('Do not use built-in or reserved HTML elements as component').toHaveBeenWarned()
})

it('should warn component names translated into native HTML elements', () => {
new Vue({
components: {
Div: { template: '<div></div>' }
}
})
expect('Do not use built-in or reserved HTML elements as component').toHaveBeenWarned()
})

it('should warn built-in elements', () => {
new Vue({
components: {
Expand Down