0bd4bb07eefcff4849b1d33f0182d064762c0a903d2b142f62a9ec716cfbd6161691bcf664bb19aed5663d38061326f2c06f4fd22ad44fbc91ee97fbe09126 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* @flow */
  2. import { parseText } from 'compiler/parser/text-parser'
  3. import { parseStyleText } from 'web/util/style'
  4. import {
  5. getAndRemoveAttr,
  6. getBindingAttr,
  7. baseWarn
  8. } from 'compiler/helpers'
  9. function transformNode (el: ASTElement, options: CompilerOptions) {
  10. const warn = options.warn || baseWarn
  11. const staticStyle = getAndRemoveAttr(el, 'style')
  12. if (staticStyle) {
  13. /* istanbul ignore if */
  14. if (process.env.NODE_ENV !== 'production') {
  15. const res = parseText(staticStyle, options.delimiters)
  16. if (res) {
  17. warn(
  18. `style="${staticStyle}": ` +
  19. 'Interpolation inside attributes has been removed. ' +
  20. 'Use v-bind or the colon shorthand instead. For example, ' +
  21. 'instead of <div style="{{ val }}">, use <div :style="val">.',
  22. el.rawAttrsMap['style']
  23. )
  24. }
  25. }
  26. el.staticStyle = JSON.stringify(parseStyleText(staticStyle))
  27. }
  28. const styleBinding = getBindingAttr(el, 'style', false /* getStatic */)
  29. if (styleBinding) {
  30. el.styleBinding = styleBinding
  31. }
  32. }
  33. function genData (el: ASTElement): string {
  34. let data = ''
  35. if (el.staticStyle) {
  36. data += `staticStyle:${el.staticStyle},`
  37. }
  38. if (el.styleBinding) {
  39. data += `style:(${el.styleBinding}),`
  40. }
  41. return data
  42. }
  43. export default {
  44. staticKeys: ['staticStyle'],
  45. transformNode,
  46. genData
  47. }