File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
src/platforms/web/compiler/modules
test/unit/features/directives Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ function transformNode (el: ASTElement, options: CompilerOptions) {
23
23
}
24
24
}
25
25
if ( staticClass ) {
26
- el . staticClass = JSON . stringify ( staticClass )
26
+ el . staticClass = JSON . stringify ( staticClass . replace ( / \s + / gi , " " ) . trim ( ) )
27
27
}
28
28
const classBinding = getBindingAttr ( el , 'class' , false /* getStatic */ )
29
29
if ( classBinding ) {
Original file line number Diff line number Diff line change @@ -152,6 +152,39 @@ describe('Directive v-bind:class', () => {
152
152
} ) . then ( done )
153
153
} )
154
154
155
+ // css static classes should only contain a single space in between,
156
+ // as all the text inside of classes is shipped as a JS string
157
+ // and this could lead to useless spacing in static classes
158
+ it ( 'corrects whitespace in staticClass' , done => {
159
+ const vm = new Vue ( {
160
+ template : '<div class=" test1\ntest2\ttest3 test4 test5 \n \n \ntest6\t"></div>' ,
161
+ } ) . $mount ( )
162
+ expect ( vm . $el . className ) . toBe ( 'test1 test2 test3 test4 test5 test6' )
163
+ done ( )
164
+ } )
165
+
166
+ it ( 'corrects whitespace in staticClass merge in a component' , done => {
167
+ const vm = new Vue ( {
168
+ template : `
169
+ <component1 class="staticClass" :class="componentClass1">
170
+ </component1>
171
+ ` ,
172
+ data : {
173
+ componentClass1 : 'componentClass1' ,
174
+ } ,
175
+ components : {
176
+ component1 : {
177
+ template : '<div class="test"></div>'
178
+ } ,
179
+ }
180
+ } ) . $mount ( )
181
+ expect ( vm . $el . className ) . toBe ( 'test staticClass componentClass1' )
182
+ vm . componentClass1 = 'c1'
183
+ waitForUpdate ( ( ) => {
184
+ expect ( vm . $el . className ) . toBe ( 'test staticClass c1' )
185
+ } ) . then ( done )
186
+ } )
187
+
155
188
// a vdom patch edge case where the user has several un-keyed elements of the
156
189
// same tag next to each other, and toggling them.
157
190
it ( 'properly remove staticClass for toggling un-keyed children' , done => {
You can’t perform that action at this time.
0 commit comments