aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vue/src/server/optimizing-compiler/modules.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/vue/src/server/optimizing-compiler/modules.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/vue/src/server/optimizing-compiler/modules.js')
-rw-r--r--node_modules/vue/src/server/optimizing-compiler/modules.js126
1 files changed, 126 insertions, 0 deletions
diff --git a/node_modules/vue/src/server/optimizing-compiler/modules.js b/node_modules/vue/src/server/optimizing-compiler/modules.js
new file mode 100644
index 00000000..69a7be87
--- /dev/null
+++ b/node_modules/vue/src/server/optimizing-compiler/modules.js
@@ -0,0 +1,126 @@
+/* @flow */
+
+import {
+ RAW,
+ // INTERPOLATION,
+ EXPRESSION
+} from './codegen'
+
+import {
+ propsToAttrMap,
+ isRenderableAttr
+} from 'web/server/util'
+
+import {
+ isBooleanAttr,
+ isEnumeratedAttr
+} from 'web/util/attrs'
+
+import type { StringSegment } from './codegen'
+import type { CodegenState } from 'compiler/codegen/index'
+
+type Attr = { name: string; value: string };
+
+const plainStringRE = /^"(?:[^"\\]|\\.)*"$|^'(?:[^'\\]|\\.)*'$/
+
+// let the model AST transform translate v-model into appropriate
+// props bindings
+export function applyModelTransform (el: ASTElement, state: CodegenState) {
+ if (el.directives) {
+ for (let i = 0; i < el.directives.length; i++) {
+ const dir = el.directives[i]
+ if (dir.name === 'model') {
+ state.directives.model(el, dir, state.warn)
+ // remove value for textarea as its converted to text
+ if (el.tag === 'textarea' && el.props) {
+ el.props = el.props.filter(p => p.name !== 'value')
+ }
+ break
+ }
+ }
+ }
+}
+
+export function genAttrSegments (
+ attrs: Array<Attr>
+): Array<StringSegment> {
+ return attrs.map(({ name, value }) => genAttrSegment(name, value))
+}
+
+export function genDOMPropSegments (
+ props: Array<Attr>,
+ attrs: ?Array<Attr>
+): Array<StringSegment> {
+ const segments = []
+ props.forEach(({ name, value }) => {
+ name = propsToAttrMap[name] || name.toLowerCase()
+ if (isRenderableAttr(name) &&
+ !(attrs && attrs.some(a => a.name === name))
+ ) {
+ segments.push(genAttrSegment(name, value))
+ }
+ })
+ return segments
+}
+
+function genAttrSegment (name: string, value: string): StringSegment {
+ if (plainStringRE.test(value)) {
+ // force double quote
+ value = value.replace(/^'|'$/g, '"')
+ // force enumerated attr to "true"
+ if (isEnumeratedAttr(name) && value !== `"false"`) {
+ value = `"true"`
+ }
+ return {
+ type: RAW,
+ value: isBooleanAttr(name)
+ ? ` ${name}="${name}"`
+ : value === '""'
+ ? ` ${name}`
+ : ` ${name}="${JSON.parse(value)}"`
+ }
+ } else {
+ return {
+ type: EXPRESSION,
+ value: `_ssrAttr(${JSON.stringify(name)},${value})`
+ }
+ }
+}
+
+export function genClassSegments (
+ staticClass: ?string,
+ classBinding: ?string
+): Array<StringSegment> {
+ if (staticClass && !classBinding) {
+ return [{ type: RAW, value: ` class=${staticClass}` }]
+ } else {
+ return [{
+ type: EXPRESSION,
+ value: `_ssrClass(${staticClass || 'null'},${classBinding || 'null'})`
+ }]
+ }
+}
+
+export function genStyleSegments (
+ staticStyle: ?string,
+ parsedStaticStyle: ?string,
+ styleBinding: ?string,
+ vShowExpression: ?string
+): Array<StringSegment> {
+ if (staticStyle && !styleBinding && !vShowExpression) {
+ return [{ type: RAW, value: ` style=${JSON.stringify(staticStyle)}` }]
+ } else {
+ return [{
+ type: EXPRESSION,
+ value: `_ssrStyle(${
+ parsedStaticStyle || 'null'
+ },${
+ styleBinding || 'null'
+ }, ${
+ vShowExpression
+ ? `{ display: (${vShowExpression}) ? '' : 'none' }`
+ : 'null'
+ })`
+ }]
+ }
+}