@@ -3,7 +3,7 @@ import stringifyProps from '../../utils/stringifyProps';
3
3
import CodeBuilder from '../../utils/CodeBuilder' ;
4
4
import getTailSnippet from '../../utils/getTailSnippet' ;
5
5
import getObject from '../../utils/getObject' ;
6
- import { quoteNameIfNecessary } from '../../utils/quoteIfNecessary' ;
6
+ import { quoteNameIfNecessary , quotePropIfNecessary } from '../../utils/quoteIfNecessary' ;
7
7
import { escape , escapeTemplate , stringify } from '../../utils/stringify' ;
8
8
import Node from './shared/Node' ;
9
9
import Block from '../dom/Block' ;
@@ -145,7 +145,7 @@ export default class Component extends Node {
145
145
const attributeObject = usesSpread
146
146
? '{}'
147
147
: stringifyProps (
148
- this . attributes . map ( attr => `${ attr . name } : ${ attr . getValue ( ) } ` )
148
+ this . attributes . map ( attr => `${ quoteNameIfNecessary ( attr . name ) } : ${ attr . getValue ( ) } ` )
149
149
) ;
150
150
151
151
if ( this . attributes . length || this . bindings . length ) {
@@ -216,7 +216,7 @@ export default class Component extends Node {
216
216
updates . push ( deindent `
217
217
if (${ [ ...attribute . dependencies ]
218
218
. map ( dependency => `changed.${ dependency } ` )
219
- . join ( ' || ' ) } ) ${ name_changes } . ${ attribute . name } = ${ attribute . getValue ( ) } ;
219
+ . join ( ' || ' ) } ) ${ name_changes } ${ quotePropIfNecessary ( attribute . name ) } = ${ attribute . getValue ( ) } ;
220
220
` ) ;
221
221
}
222
222
} ) ;
@@ -247,10 +247,10 @@ export default class Component extends Node {
247
247
248
248
const lhs = binding . value . node . type === 'MemberExpression'
249
249
? binding . value . snippet
250
- : `${ head } ${ tail } = childState. ${ binding . name } ` ;
250
+ : `${ head } ${ tail } = childState${ quotePropIfNecessary ( binding . name ) } ` ;
251
251
252
252
setFromChild = deindent `
253
- ${ lhs } = childState. ${ binding . name } ;
253
+ ${ lhs } = childState${ quotePropIfNecessary ( binding . name ) } ;
254
254
255
255
${ [ ...binding . value . dependencies ]
256
256
. map ( ( name : string ) => {
@@ -261,7 +261,7 @@ export default class Component extends Node {
261
261
if ( isStoreProp ) hasStoreBindings = true ;
262
262
else hasLocalBindings = true ;
263
263
264
- return `${ newState } . ${ prop } = ctx. ${ name } ;` ;
264
+ return `${ newState } ${ quotePropIfNecessary ( prop ) } = ctx${ quotePropIfNecessary ( name ) } ;` ;
265
265
} ) }
266
266
` ;
267
267
}
@@ -276,32 +276,32 @@ export default class Component extends Node {
276
276
277
277
if ( binding . value . node . type === 'MemberExpression' ) {
278
278
setFromChild = deindent `
279
- ${ binding . value . snippet } = childState. ${ binding . name } ;
280
- ${ newState } . ${ prop } = ctx. ${ key } ;
279
+ ${ binding . value . snippet } = childState${ quotePropIfNecessary ( binding . name ) } ;
280
+ ${ newState } ${ quotePropIfNecessary ( prop ) } = ctx${ quotePropIfNecessary ( key ) } ;
281
281
` ;
282
282
}
283
283
284
284
else {
285
- setFromChild = `${ newState } . ${ prop } = childState. ${ binding . name } ;` ;
285
+ setFromChild = `${ newState } ${ quotePropIfNecessary ( prop ) } = childState${ quotePropIfNecessary ( binding . name ) } ;` ;
286
286
}
287
287
}
288
288
289
289
statements . push ( deindent `
290
290
if (${ binding . value . snippet } !== void 0) {
291
- ${ name_initial_data } . ${ binding . name } = ${ binding . value . snippet } ;
292
- ${ name_updating } . ${ binding . name } = true;
291
+ ${ name_initial_data } ${ quotePropIfNecessary ( binding . name ) } = ${ binding . value . snippet } ;
292
+ ${ name_updating } ${ quotePropIfNecessary ( binding . name ) } = true;
293
293
}`
294
294
) ;
295
295
296
296
builder . addConditional (
297
- `!${ name_updating } . ${ binding . name } && changed. ${ binding . name } ` ,
297
+ `!${ name_updating } ${ quotePropIfNecessary ( binding . name ) } && changed${ quotePropIfNecessary ( binding . name ) } ` ,
298
298
setFromChild
299
299
) ;
300
300
301
301
updates . push ( deindent `
302
- if (!${ name_updating } . ${ binding . name } && ${ [ ...binding . value . dependencies ] . map ( ( dependency : string ) => `changed.${ dependency } ` ) . join ( ' || ' ) } ) {
303
- ${ name_changes } . ${ binding . name } = ${ binding . value . snippet } ;
304
- ${ name_updating } . ${ binding . name } = ${ binding . value . snippet } !== void 0;
302
+ if (!${ name_updating } ${ quotePropIfNecessary ( binding . name ) } && ${ [ ...binding . value . dependencies ] . map ( ( dependency : string ) => `changed.${ dependency } ` ) . join ( ' || ' ) } ) {
303
+ ${ name_changes } ${ quotePropIfNecessary ( binding . name ) } = ${ binding . value . snippet } ;
304
+ ${ name_updating } ${ quotePropIfNecessary ( binding . name ) } = ${ binding . value . snippet } !== void 0;
305
305
}
306
306
` ) ;
307
307
} ) ;
@@ -326,7 +326,7 @@ export default class Component extends Node {
326
326
327
327
beforecreate = deindent `
328
328
#component.root._beforecreate.push(() => {
329
- ${ name } ._bind({ ${ this . bindings . map ( b => `${ b . name } : 1` ) . join ( ', ' ) } }, ${ name } .get());
329
+ ${ name } ._bind({ ${ this . bindings . map ( b => `${ quoteNameIfNecessary ( b . name ) } : 1` ) . join ( ', ' ) } }, ${ name } .get());
330
330
});
331
331
` ;
332
332
}
@@ -524,7 +524,7 @@ export default class Component extends Node {
524
524
? getTailSnippet ( binding . value . node )
525
525
: '' ;
526
526
527
- return `${ binding . name } : ctx. ${ name } ${ tail } ` ;
527
+ return `${ quoteNameIfNecessary ( binding . name ) } : ctx${ quotePropIfNecessary ( name ) } ${ tail } ` ;
528
528
} ) ;
529
529
530
530
function getAttributeValue ( attribute ) {
@@ -552,14 +552,14 @@ export default class Component extends Node {
552
552
if ( attribute . isSpread ) {
553
553
return attribute . expression . snippet ;
554
554
} else {
555
- return `{ ${ attribute . name } : ${ getAttributeValue ( attribute ) } }` ;
555
+ return `{ ${ quoteNameIfNecessary ( attribute . name ) } : ${ getAttributeValue ( attribute ) } }` ;
556
556
}
557
557
} )
558
558
. concat ( bindingProps . map ( p => `{ ${ p } }` ) )
559
559
. join ( ', ' )
560
560
} )`
561
561
: `{ ${ this . attributes
562
- . map ( attribute => `${ attribute . name } : ${ getAttributeValue ( attribute ) } ` )
562
+ . map ( attribute => `${ quoteNameIfNecessary ( attribute . name ) } : ${ getAttributeValue ( attribute ) } ` )
563
563
. concat ( bindingProps )
564
564
. join ( ', ' ) } }`;
565
565
@@ -590,7 +590,7 @@ export default class Component extends Node {
590
590
if (${ conditions . reverse ( ) . join ( '&&' ) } ) {
591
591
tmp = ${ expression } .data();
592
592
if ('${ name } ' in tmp) {
593
- ctx. ${ binding . name } = tmp.${ name } ;
593
+ ctx${ quotePropIfNecessary ( binding . name ) } = tmp.${ name } ;
594
594
settled = false;
595
595
}
596
596
}
0 commit comments