File tree Expand file tree Collapse file tree 4 files changed +20
-7
lines changed Expand file tree Collapse file tree 4 files changed +20
-7
lines changed Original file line number Diff line number Diff line change 6
6
classify ,
7
7
toArray ,
8
8
commonTagRE ,
9
+ reservedTagRE ,
9
10
warn ,
10
11
isPlainObject
11
12
} from '../../util/index'
@@ -167,9 +168,12 @@ export default function (Vue) {
167
168
} else {
168
169
/* istanbul ignore if */
169
170
if ( process . env . NODE_ENV !== 'production' ) {
170
- if ( type === 'component' && commonTagRE . test ( id ) ) {
171
+ if (
172
+ type === 'component' &&
173
+ ( commonTagRE . test ( id ) || reservedTagRE . test ( id ) )
174
+ ) {
171
175
warn (
172
- 'Do not use built-in HTML elements as component ' +
176
+ 'Do not use built-in or reserved HTML elements as component ' +
173
177
'id: ' + id
174
178
)
175
179
}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { getAttr, getBindAttr } from './dom'
4
4
import { isArray , isPlainObject } from './lang'
5
5
6
6
export const commonTagRE = / ^ ( d i v | p | s p a n | i m g | a | b | i | b r | u l | o l | l i | h 1 | h 2 | h 3 | h 4 | h 5 | h 6 | c o d e | p r e | t a b l e | t h | t d | t r | f o r m | l a b e l | i n p u t | s e l e c t | o p t i o n | n a v | a r t i c l e | s e c t i o n | h e a d e r | f o o t e r ) $ /
7
+ export const reservedTagRE = / ^ ( s l o t | p a r t i a l | c o m p o n e n t ) $ /
7
8
8
9
/**
9
10
* Check if an element is a component, if yes return its
@@ -17,7 +18,7 @@ export const commonTagRE = /^(div|p|span|img|a|b|i|br|ul|ol|li|h1|h2|h3|h4|h5|h6
17
18
export function checkComponentAttr ( el , options ) {
18
19
var tag = el . tagName . toLowerCase ( )
19
20
var hasAttrs = el . hasAttributes ( )
20
- if ( ! commonTagRE . test ( tag ) && tag !== 'component' ) {
21
+ if ( ! commonTagRE . test ( tag ) && ! reservedTagRE . test ( tag ) ) {
21
22
if ( resolveAsset ( options , 'components' , tag ) ) {
22
23
return { id : tag }
23
24
} else {
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import {
10
10
camelize
11
11
} from './lang'
12
12
import { warn } from './debug'
13
- import { commonTagRE } from './component'
13
+ import { commonTagRE , reservedTagRE } from './component'
14
14
15
15
/**
16
16
* Option overwriting strategies are functions that handle
@@ -233,9 +233,9 @@ function guardComponents (options) {
233
233
var ids = Object . keys ( components )
234
234
for ( var i = 0 , l = ids . length ; i < l ; i ++ ) {
235
235
var key = ids [ i ]
236
- if ( commonTagRE . test ( key ) ) {
236
+ if ( commonTagRE . test ( key ) || reservedTagRE . test ( key ) ) {
237
237
process . env . NODE_ENV !== 'production' && warn (
238
- 'Do not use built-in HTML elements as component ' +
238
+ 'Do not use built-in or reserved HTML elements as component ' +
239
239
'id: ' + key
240
240
)
241
241
continue
Original file line number Diff line number Diff line change @@ -161,7 +161,15 @@ describe('Util - Option merging', function () {
161
161
a : { template : 'hi' }
162
162
}
163
163
} )
164
- expect ( hasWarned ( 'Do not use built-in HTML elements' ) ) . toBe ( true )
164
+ expect ( hasWarned ( 'Do not use built-in or reserved HTML elements as component id: a' ) ) . toBe ( true )
165
+ merge ( {
166
+ components : null
167
+ } , {
168
+ components : {
169
+ slot : { template : 'hi' }
170
+ }
171
+ } )
172
+ expect ( hasWarned ( 'Do not use built-in or reserved HTML elements as component id: slot' ) ) . toBe ( true )
165
173
} )
166
174
167
175
it ( 'should ignore non-function el & data in class merge' , function ( ) {
You can’t perform that action at this time.
0 commit comments