Skip to content

Commit

Permalink
style and class should be reserved for web
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 3, 2017
1 parent e7e86fd commit 6622839
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Config = {
keyCodes: { [key: string]: number | Array<number> };
// platform
isReservedTag: (x?: string) => boolean;
isReservedAttr: (x?: string) => boolean;
parsePlatformTagName: (x: string) => string;
isUnknownElement: (x?: string) => boolean;
getTagNamespace: (x?: string) => string | void;
Expand Down Expand Up @@ -71,6 +72,12 @@ export default ({
*/
isReservedTag: no,

/**
* Check if an attribute is reserved so that it cannot be used as a component
* prop. This is platform-dependent and may be overwritten.
*/
isReservedAttr: no,

/**
* Check if a tag is an unknown element.
* Platform-dependent.
Expand Down
9 changes: 7 additions & 2 deletions src/core/instance/state.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */

import config from '../config'
import Dep from '../observer/dep'
import Watcher from '../observer/watcher'

Expand Down Expand Up @@ -53,7 +54,11 @@ export function initState (vm: Component) {
if (opts.watch) initWatch(vm, opts.watch)
}

const isReservedProp = { key: 1, ref: 1, slot: 1 }
const isReservedProp = {
key: 1,
ref: 1,
slot: 1
}

function initProps (vm: Component, propsOptions: Object) {
const propsData = vm.$options.propsData || {}
Expand All @@ -69,7 +74,7 @@ function initProps (vm: Component, propsOptions: Object) {
const value = validateProp(key, propsOptions, propsData, vm)
/* istanbul ignore else */
if (process.env.NODE_ENV !== 'production') {
if (isReservedProp[key]) {
if (isReservedProp[key] || config.isReservedAttr(key)) {
warn(
`"${key}" is a reserved attribute and cannot be used as component prop.`,
vm
Expand Down
2 changes: 2 additions & 0 deletions src/entries/web-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import {
query,
mustUseProp,
isReservedTag,
isReservedAttr,
getTagNamespace,
isUnknownElement
} from 'web/util/index'

// install platform specific utils
Vue.config.mustUseProp = mustUseProp
Vue.config.isReservedTag = isReservedTag
Vue.config.isReservedAttr = isReservedAttr
Vue.config.getTagNamespace = getTagNamespace
Vue.config.isUnknownElement = isUnknownElement

Expand Down
4 changes: 4 additions & 0 deletions src/platforms/web/util/attrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import { makeMap } from 'shared/util'

// these are reserved for web because they are directly compiled away
// during template compilation
export const isReservedAttr = makeMap('style,class')

// attributes that should be using props for binding
const acceptValue = makeMap('input,textarea,option,select')
export const mustUseProp = (tag: string, type: ?string, attr: string): boolean => {
Expand Down

0 comments on commit 6622839

Please sign in to comment.