Skip to content

Commit 6622839

Browse files
committed
style and class should be reserved for web
1 parent e7e86fd commit 6622839

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

Diff for: src/core/config.js

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type Config = {
1818
keyCodes: { [key: string]: number | Array<number> };
1919
// platform
2020
isReservedTag: (x?: string) => boolean;
21+
isReservedAttr: (x?: string) => boolean;
2122
parsePlatformTagName: (x: string) => string;
2223
isUnknownElement: (x?: string) => boolean;
2324
getTagNamespace: (x?: string) => string | void;
@@ -71,6 +72,12 @@ export default ({
7172
*/
7273
isReservedTag: no,
7374

75+
/**
76+
* Check if an attribute is reserved so that it cannot be used as a component
77+
* prop. This is platform-dependent and may be overwritten.
78+
*/
79+
isReservedAttr: no,
80+
7481
/**
7582
* Check if a tag is an unknown element.
7683
* Platform-dependent.

Diff for: src/core/instance/state.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow */
22

3+
import config from '../config'
34
import Dep from '../observer/dep'
45
import Watcher from '../observer/watcher'
56

@@ -53,7 +54,11 @@ export function initState (vm: Component) {
5354
if (opts.watch) initWatch(vm, opts.watch)
5455
}
5556

56-
const isReservedProp = { key: 1, ref: 1, slot: 1 }
57+
const isReservedProp = {
58+
key: 1,
59+
ref: 1,
60+
slot: 1
61+
}
5762

5863
function initProps (vm: Component, propsOptions: Object) {
5964
const propsData = vm.$options.propsData || {}
@@ -69,7 +74,7 @@ function initProps (vm: Component, propsOptions: Object) {
6974
const value = validateProp(key, propsOptions, propsData, vm)
7075
/* istanbul ignore else */
7176
if (process.env.NODE_ENV !== 'production') {
72-
if (isReservedProp[key]) {
77+
if (isReservedProp[key] || config.isReservedAttr(key)) {
7378
warn(
7479
`"${key}" is a reserved attribute and cannot be used as component prop.`,
7580
vm

Diff for: src/entries/web-runtime.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import {
1313
query,
1414
mustUseProp,
1515
isReservedTag,
16+
isReservedAttr,
1617
getTagNamespace,
1718
isUnknownElement
1819
} from 'web/util/index'
1920

2021
// install platform specific utils
2122
Vue.config.mustUseProp = mustUseProp
2223
Vue.config.isReservedTag = isReservedTag
24+
Vue.config.isReservedAttr = isReservedAttr
2325
Vue.config.getTagNamespace = getTagNamespace
2426
Vue.config.isUnknownElement = isUnknownElement
2527

Diff for: src/platforms/web/util/attrs.js

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import { makeMap } from 'shared/util'
44

5+
// these are reserved for web because they are directly compiled away
6+
// during template compilation
7+
export const isReservedAttr = makeMap('style,class')
8+
59
// attributes that should be using props for binding
610
const acceptValue = makeMap('input,textarea,option,select')
711
export const mustUseProp = (tag: string, type: ?string, attr: string): boolean => {

0 commit comments

Comments
 (0)