Browse Source

use cached escape

dev
Evan You 8 years ago
parent
commit
9084e8582c
  1. 4
      src/platforms/web/server/modules/attrs.js
  2. 4
      src/platforms/web/server/modules/class.js
  3. 4
      src/platforms/web/server/modules/style.js
  4. 4
      src/platforms/web/server/util.js
  5. 5
      src/platforms/web/util/class.js
  6. 4
      src/server/optimizing-compiler/codegen.js
  7. 6
      src/server/optimizing-compiler/runtime-helpers.js

4
src/platforms/web/server/modules/attrs.js

@ -1,6 +1,6 @@
/* @flow */
import { escape } from '../util'
import { cachedEscape } from '../util'
import {
isDef,
@ -47,7 +47,7 @@ export function renderAttr (key: string, value: string): string {
} else if (isEnumeratedAttr(key)) {
return ` ${key}="${isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true'}"`
} else if (!isFalsyAttrValue(value)) {
return ` ${key}="${typeof value === 'string' ? escape(value) : value}"`
return ` ${key}="${typeof value === 'string' ? cachedEscape(value) : value}"`
}
return ''
}

4
src/platforms/web/server/modules/class.js

@ -1,11 +1,11 @@
/* @flow */
import { escape } from '../util'
import { cachedEscape } from '../util'
import { genClassForVnode } from 'web/util/index'
export default function renderClass (node: VNodeWithData): ?string {
const classList = genClassForVnode(node)
if (classList !== '') {
return ` class="${escape(classList)}"`
return ` class="${cachedEscape(classList)}"`
}
}

4
src/platforms/web/server/modules/style.js

@ -1,6 +1,6 @@
/* @flow */
import { escape } from '../util'
import { cachedEscape } from '../util'
import { hyphenate } from 'shared/util'
import { getStyle } from 'web/util/style'
@ -23,6 +23,6 @@ export function genStyle (style: Object): string {
export default function renderStyle (vnode: VNodeWithData): ?string {
const styleText = genStyle(getStyle(vnode, false))
if (styleText !== '') {
return ` style=${JSON.stringify(escape(styleText))}`
return ` style=${JSON.stringify(cachedEscape(styleText))}`
}
}

4
src/platforms/web/server/util.js

@ -1,6 +1,6 @@
/* @flow */
import { makeMap } from 'shared/util'
import { makeMap, cached } from 'shared/util'
const isAttr = makeMap(
'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
@ -46,6 +46,8 @@ export function escape (s: string) {
return s.replace(/[<>"&]/g, escapeChar)
}
export const cachedEscape = cached(escape)
function escapeChar (a) {
return ESC[a] || a
}

5
src/platforms/web/util/class.js

@ -68,9 +68,10 @@ export function stringifyClass (value: any): string {
}
if (isObject(value)) {
for (const key in value) {
if (value[key]) res += key + ' '
if (res) res += ' '
if (value[key]) res += key
}
return res.slice(0, -1)
return res
}
/* istanbul ignore next */
return res

4
src/server/optimizing-compiler/codegen.js

@ -55,6 +55,10 @@ function genSSRElement (el: ASTElement, state: CodegenState): string {
return genIf(el, state, genSSRElement)
}
// TODO handle <template> tag
// TODO optimize style/class rendering
// TODO optimize merge sibling nodes
switch (el.ssrOptimizability) {
case optimizability.FULL:
// stringify whole tree

6
src/server/optimizing-compiler/runtime-helpers.js

@ -1,6 +1,6 @@
/* @flow */
import { escape } from 'web/server/util'
import { escape, cachedEscape } from 'web/server/util'
import { isObject, extend } from 'shared/util'
import { renderAttr } from 'web/server/modules/attrs'
import { renderClass } from 'web/util/class'
@ -97,7 +97,7 @@ function renderSSRClass (
dynamic: any
): string {
const res = renderClass(staticClass, dynamic)
return res === '' ? res : ` class="${escape(res)}"`
return res === '' ? res : ` class="${cachedEscape(res)}"`
}
function renderSSRStyle (
@ -110,5 +110,5 @@ function renderSSRStyle (
if (dynamic) extend(style, normalizeStyleBinding(dynamic))
if (extra) extend(style, extra)
const res = genStyle(style)
return res === '' ? res : ` style=${JSON.stringify(escape(res))}`
return res === '' ? res : ` style=${JSON.stringify(cachedEscape(res))}`
}

Loading…
Cancel
Save