1
1
import { encodeEntities , indent , isLargeString , styleObjToCss , assign , getNodeProps } from './util' ;
2
+ import { ENABLE_PRETTY } from '../env' ;
2
3
3
4
const SHALLOW = { shallow : true } ;
4
5
@@ -43,8 +44,8 @@ function renderToString(vnode, context, opts, inner, isSvgMode) {
43
44
context = context || { } ;
44
45
opts = opts || { } ;
45
46
46
- let pretty = opts . pretty ,
47
- indentChar = typeof pretty === 'string' ? pretty : '\t' ;
47
+ let pretty = ENABLE_PRETTY && opts . pretty ,
48
+ indentChar = pretty && typeof pretty === 'string' ? pretty : '\t' ;
48
49
49
50
// #text nodes
50
51
if ( typeof vnode !== 'object' && ! nodeName ) {
@@ -138,9 +139,11 @@ function renderToString(vnode, context, opts, inner, isSvgMode) {
138
139
}
139
140
140
141
// account for >1 multiline attribute
141
- let sub = s . replace ( / ^ \n \s * / , ' ' ) ;
142
- if ( sub !== s && ! ~ sub . indexOf ( '\n' ) ) s = sub ;
143
- else if ( pretty && ~ s . indexOf ( '\n' ) ) s += '\n' ;
142
+ if ( pretty ) {
143
+ let sub = s . replace ( / ^ \n \s * / , ' ' ) ;
144
+ if ( sub !== s && ! ~ sub . indexOf ( '\n' ) ) s = sub ;
145
+ else if ( pretty && ~ s . indexOf ( '\n' ) ) s += '\n' ;
146
+ }
144
147
145
148
s = `<${ nodeName } ${ s } >` ;
146
149
if ( String ( nodeName ) . match ( / [ \s \n \\ / = ' " \0 < > ] / ) ) throw s ;
@@ -157,13 +160,13 @@ function renderToString(vnode, context, opts, inner, isSvgMode) {
157
160
s += html ;
158
161
}
159
162
else if ( vnode . children ) {
160
- let hasLarge = ~ s . indexOf ( '\n' ) ;
163
+ let hasLarge = pretty && ~ s . indexOf ( '\n' ) ;
161
164
for ( let i = 0 ; i < vnode . children . length ; i ++ ) {
162
165
let child = vnode . children [ i ] ;
163
166
if ( child != null && child !== false ) {
164
167
let childSvgMode = nodeName === 'svg' ? true : nodeName === 'foreignObject' ? false : isSvgMode ,
165
168
ret = renderToString ( child , context , opts , true , childSvgMode ) ;
166
- if ( ! hasLarge && pretty && isLargeString ( ret ) ) hasLarge = true ;
169
+ if ( pretty && ! hasLarge && isLargeString ( ret ) ) hasLarge = true ;
167
170
if ( ret ) pieces . push ( ret ) ;
168
171
}
169
172
}
0 commit comments