446ca8cc761e105ba4e58fb114457d21a95765353ac33b9a5b1377e78005475f3bdea6e84c08af36c68bb8592223958711bb5517f91caf3c5f9a04f20da2e1 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* @flow */
  2. // helper to process dynamic keys for dynamic arguments in v-bind and v-on.
  3. // For example, the following template:
  4. //
  5. // <div id="app" :[key]="value">
  6. //
  7. // compiles to the following:
  8. //
  9. // _c('div', { attrs: bindDynamicKeys({ "id": "app" }, [key, value]) })
  10. import { warn } from 'core/util/debug'
  11. export function bindDynamicKeys (baseObj: Object, values: Array<any>): Object {
  12. for (let i = 0; i < values.length; i += 2) {
  13. const key = values[i]
  14. if (typeof key === 'string' && key) {
  15. baseObj[values[i]] = values[i + 1]
  16. } else if (process.env.NODE_ENV !== 'production' && key !== '' && key !== null) {
  17. // null is a special value for explicitly removing a binding
  18. warn(
  19. `Invalid value for dynamic directive argument (expected string or null): ${key}`,
  20. this
  21. )
  22. }
  23. }
  24. return baseObj
  25. }
  26. // helper to dynamically append modifier runtime markers to event names.
  27. // ensure only append when value is already string, otherwise it will be cast
  28. // to string and cause the type check to miss.
  29. export function prependModifier (value: any, symbol: string): any {
  30. return typeof value === 'string' ? symbol + value : value
  31. }