aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vue/src/platforms/web/compiler/modules
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/vue/src/platforms/web/compiler/modules')
-rw-r--r--node_modules/vue/src/platforms/web/compiler/modules/class.js48
-rw-r--r--node_modules/vue/src/platforms/web/compiler/modules/index.js9
-rw-r--r--node_modules/vue/src/platforms/web/compiler/modules/model.js94
-rw-r--r--node_modules/vue/src/platforms/web/compiler/modules/style.js51
4 files changed, 202 insertions, 0 deletions
diff --git a/node_modules/vue/src/platforms/web/compiler/modules/class.js b/node_modules/vue/src/platforms/web/compiler/modules/class.js
new file mode 100644
index 00000000..ffdca250
--- /dev/null
+++ b/node_modules/vue/src/platforms/web/compiler/modules/class.js
@@ -0,0 +1,48 @@
+/* @flow */
+
+import { parseText } from 'compiler/parser/text-parser'
+import {
+ getAndRemoveAttr,
+ getBindingAttr,
+ baseWarn
+} from 'compiler/helpers'
+
+function transformNode (el: ASTElement, options: CompilerOptions) {
+ const warn = options.warn || baseWarn
+ const staticClass = getAndRemoveAttr(el, 'class')
+ if (process.env.NODE_ENV !== 'production' && staticClass) {
+ const res = parseText(staticClass, options.delimiters)
+ if (res) {
+ warn(
+ `class="${staticClass}": ` +
+ 'Interpolation inside attributes has been removed. ' +
+ 'Use v-bind or the colon shorthand instead. For example, ' +
+ 'instead of <div class="{{ val }}">, use <div :class="val">.'
+ )
+ }
+ }
+ if (staticClass) {
+ el.staticClass = JSON.stringify(staticClass)
+ }
+ const classBinding = getBindingAttr(el, 'class', false /* getStatic */)
+ if (classBinding) {
+ el.classBinding = classBinding
+ }
+}
+
+function genData (el: ASTElement): string {
+ let data = ''
+ if (el.staticClass) {
+ data += `staticClass:${el.staticClass},`
+ }
+ if (el.classBinding) {
+ data += `class:${el.classBinding},`
+ }
+ return data
+}
+
+export default {
+ staticKeys: ['staticClass'],
+ transformNode,
+ genData
+}
diff --git a/node_modules/vue/src/platforms/web/compiler/modules/index.js b/node_modules/vue/src/platforms/web/compiler/modules/index.js
new file mode 100644
index 00000000..29114a53
--- /dev/null
+++ b/node_modules/vue/src/platforms/web/compiler/modules/index.js
@@ -0,0 +1,9 @@
+import klass from './class'
+import style from './style'
+import model from './model'
+
+export default [
+ klass,
+ style,
+ model
+]
diff --git a/node_modules/vue/src/platforms/web/compiler/modules/model.js b/node_modules/vue/src/platforms/web/compiler/modules/model.js
new file mode 100644
index 00000000..8d784fe4
--- /dev/null
+++ b/node_modules/vue/src/platforms/web/compiler/modules/model.js
@@ -0,0 +1,94 @@
+/* @flow */
+
+/**
+ * Expand input[v-model] with dyanmic type bindings into v-if-else chains
+ * Turn this:
+ * <input v-model="data[type]" :type="type">
+ * into this:
+ * <input v-if="type === 'checkbox'" type="checkbox" v-model="data[type]">
+ * <input v-else-if="type === 'radio'" type="radio" v-model="data[type]">
+ * <input v-else :type="type" v-model="data[type]">
+ */
+
+import {
+ addRawAttr,
+ getBindingAttr,
+ getAndRemoveAttr
+} from 'compiler/helpers'
+
+import {
+ processFor,
+ processElement,
+ addIfCondition,
+ createASTElement
+} from 'compiler/parser/index'
+
+function preTransformNode (el: ASTElement, options: CompilerOptions) {
+ if (el.tag === 'input') {
+ const map = el.attrsMap
+ if (!map['v-model']) {
+ return
+ }
+
+ let typeBinding
+ if (map[':type'] || map['v-bind:type']) {
+ typeBinding = getBindingAttr(el, 'type')
+ }
+ if (!map.type && !typeBinding && map['v-bind']) {
+ typeBinding = `(${map['v-bind']}).type`
+ }
+
+ if (typeBinding) {
+ const ifCondition = getAndRemoveAttr(el, 'v-if', true)
+ const ifConditionExtra = ifCondition ? `&&(${ifCondition})` : ``
+ const hasElse = getAndRemoveAttr(el, 'v-else', true) != null
+ const elseIfCondition = getAndRemoveAttr(el, 'v-else-if', true)
+ // 1. checkbox
+ const branch0 = cloneASTElement(el)
+ // process for on the main node
+ processFor(branch0)
+ addRawAttr(branch0, 'type', 'checkbox')
+ processElement(branch0, options)
+ branch0.processed = true // prevent it from double-processed
+ branch0.if = `(${typeBinding})==='checkbox'` + ifConditionExtra
+ addIfCondition(branch0, {
+ exp: branch0.if,
+ block: branch0
+ })
+ // 2. add radio else-if condition
+ const branch1 = cloneASTElement(el)
+ getAndRemoveAttr(branch1, 'v-for', true)
+ addRawAttr(branch1, 'type', 'radio')
+ processElement(branch1, options)
+ addIfCondition(branch0, {
+ exp: `(${typeBinding})==='radio'` + ifConditionExtra,
+ block: branch1
+ })
+ // 3. other
+ const branch2 = cloneASTElement(el)
+ getAndRemoveAttr(branch2, 'v-for', true)
+ addRawAttr(branch2, ':type', typeBinding)
+ processElement(branch2, options)
+ addIfCondition(branch0, {
+ exp: ifCondition,
+ block: branch2
+ })
+
+ if (hasElse) {
+ branch0.else = true
+ } else if (elseIfCondition) {
+ branch0.elseif = elseIfCondition
+ }
+
+ return branch0
+ }
+ }
+}
+
+function cloneASTElement (el) {
+ return createASTElement(el.tag, el.attrsList.slice(), el.parent)
+}
+
+export default {
+ preTransformNode
+}
diff --git a/node_modules/vue/src/platforms/web/compiler/modules/style.js b/node_modules/vue/src/platforms/web/compiler/modules/style.js
new file mode 100644
index 00000000..2722b92b
--- /dev/null
+++ b/node_modules/vue/src/platforms/web/compiler/modules/style.js
@@ -0,0 +1,51 @@
+/* @flow */
+
+import { parseText } from 'compiler/parser/text-parser'
+import { parseStyleText } from 'web/util/style'
+import {
+ getAndRemoveAttr,
+ getBindingAttr,
+ baseWarn
+} from 'compiler/helpers'
+
+function transformNode (el: ASTElement, options: CompilerOptions) {
+ const warn = options.warn || baseWarn
+ const staticStyle = getAndRemoveAttr(el, 'style')
+ if (staticStyle) {
+ /* istanbul ignore if */
+ if (process.env.NODE_ENV !== 'production') {
+ const res = parseText(staticStyle, options.delimiters)
+ if (res) {
+ warn(
+ `style="${staticStyle}": ` +
+ 'Interpolation inside attributes has been removed. ' +
+ 'Use v-bind or the colon shorthand instead. For example, ' +
+ 'instead of <div style="{{ val }}">, use <div :style="val">.'
+ )
+ }
+ }
+ el.staticStyle = JSON.stringify(parseStyleText(staticStyle))
+ }
+
+ const styleBinding = getBindingAttr(el, 'style', false /* getStatic */)
+ if (styleBinding) {
+ el.styleBinding = styleBinding
+ }
+}
+
+function genData (el: ASTElement): string {
+ let data = ''
+ if (el.staticStyle) {
+ data += `staticStyle:${el.staticStyle},`
+ }
+ if (el.styleBinding) {
+ data += `style:(${el.styleBinding}),`
+ }
+ return data
+}
+
+export default {
+ staticKeys: ['staticStyle'],
+ transformNode,
+ genData
+}