@@ -5,7 +5,7 @@ import stringifyProps from '../../utils/stringifyProps';
5
5
import CodeBuilder from '../../utils/CodeBuilder' ;
6
6
import getTailSnippet from '../../utils/getTailSnippet' ;
7
7
import getObject from '../../utils/getObject' ;
8
- import { quoteNameIfNecessary } from '../../utils/quoteIfNecessary' ;
8
+ import { quoteNameIfNecessary , quotePropIfNecessary } from '../../utils/quoteIfNecessary' ;
9
9
import { escape , escapeTemplate , stringify } from '../../utils/stringify' ;
10
10
import Node from './shared/Node' ;
11
11
import Block from '../dom/Block' ;
@@ -219,7 +219,7 @@ export default class Component extends Node {
219
219
updates . push ( deindent `
220
220
if (${ [ ...attribute . dependencies ]
221
221
. map ( dependency => `changed.${ dependency } ` )
222
- . join ( ' || ' ) } ) ${ name_changes } . ${ attribute . name } = ${ attribute . getValue ( ) } ;
222
+ . join ( ' || ' ) } ) ${ name_changes } ${ quotePropIfNecessary ( attribute . name ) } = ${ attribute . getValue ( ) } ;
223
223
` ) ;
224
224
}
225
225
} ) ;
@@ -250,10 +250,10 @@ export default class Component extends Node {
250
250
251
251
const lhs = binding . value . node . type === 'MemberExpression'
252
252
? binding . value . snippet
253
- : `${ head } ${ tail } = childState. ${ binding . name } ` ;
253
+ : `${ head } ${ tail } = childState${ quotePropIfNecessary ( binding . name ) } ` ;
254
254
255
255
setFromChild = deindent `
256
- ${ lhs } = childState. ${ binding . name } ;
256
+ ${ lhs } = childState${ quotePropIfNecessary ( binding . name ) } ;
257
257
258
258
${ [ ...binding . value . dependencies ]
259
259
. map ( ( name : string ) => {
@@ -264,7 +264,7 @@ export default class Component extends Node {
264
264
if ( isStoreProp ) hasStoreBindings = true ;
265
265
else hasLocalBindings = true ;
266
266
267
- return `${ newState } . ${ prop } = ctx. ${ name } ;` ;
267
+ return `${ newState } ${ quotePropIfNecessary ( prop ) } = ctx${ quotePropIfNecessary ( name ) } ;` ;
268
268
} ) }
269
269
` ;
270
270
}
@@ -279,32 +279,32 @@ export default class Component extends Node {
279
279
280
280
if ( binding . value . node . type === 'MemberExpression' ) {
281
281
setFromChild = deindent `
282
- ${ binding . value . snippet } = childState. ${ binding . name } ;
283
- ${ newState } . ${ prop } = ctx. ${ key } ;
282
+ ${ binding . value . snippet } = childState${ quotePropIfNecessary ( binding . name ) } ;
283
+ ${ newState } ${ quotePropIfNecessary ( prop ) } = ctx${ quotePropIfNecessary ( key ) } ;
284
284
` ;
285
285
}
286
286
287
287
else {
288
- setFromChild = `${ newState } . ${ prop } = childState. ${ binding . name } ;` ;
288
+ setFromChild = `${ newState } ${ quotePropIfNecessary ( prop ) } = childState${ quotePropIfNecessary ( binding . name ) } ;` ;
289
289
}
290
290
}
291
291
292
292
statements . push ( deindent `
293
293
if (${ binding . value . snippet } !== void 0) {
294
- ${ name_initial_data } . ${ binding . name } = ${ binding . value . snippet } ;
295
- ${ name_updating } . ${ binding . name } = true;
294
+ ${ name_initial_data } ${ quotePropIfNecessary ( binding . name ) } = ${ binding . value . snippet } ;
295
+ ${ name_updating } ${ quotePropIfNecessary ( binding . name ) } = true;
296
296
}`
297
297
) ;
298
298
299
299
builder . addConditional (
300
- `!${ name_updating } . ${ binding . name } && changed. ${ binding . name } ` ,
300
+ `!${ name_updating } ${ quotePropIfNecessary ( binding . name ) } && changed${ quotePropIfNecessary ( binding . name ) } ` ,
301
301
setFromChild
302
302
) ;
303
303
304
304
updates . push ( deindent `
305
- if (!${ name_updating } . ${ binding . name } && ${ [ ...binding . value . dependencies ] . map ( ( dependency : string ) => `changed.${ dependency } ` ) . join ( ' || ' ) } ) {
306
- ${ name_changes } . ${ binding . name } = ${ binding . value . snippet } ;
307
- ${ name_updating } . ${ binding . name } = ${ binding . value . snippet } !== void 0;
305
+ if (!${ name_updating } ${ quotePropIfNecessary ( binding . name ) } && ${ [ ...binding . value . dependencies ] . map ( ( dependency : string ) => `changed.${ dependency } ` ) . join ( ' || ' ) } ) {
306
+ ${ name_changes } ${ quotePropIfNecessary ( binding . name ) } = ${ binding . value . snippet } ;
307
+ ${ name_updating } ${ quotePropIfNecessary ( binding . name ) } = ${ binding . value . snippet } !== void 0;
308
308
}
309
309
` ) ;
310
310
} ) ;
@@ -329,7 +329,7 @@ export default class Component extends Node {
329
329
330
330
beforecreate = deindent `
331
331
#component.root._beforecreate.push(() => {
332
- ${ name } ._bind({ ${ this . bindings . map ( b => `${ b . name } : 1` ) . join ( ', ' ) } }, ${ name } .get());
332
+ ${ name } ._bind({ ${ this . bindings . map ( b => `${ quoteNameIfNecessary ( b . name ) } : 1` ) . join ( ', ' ) } }, ${ name } .get());
333
333
});
334
334
` ;
335
335
}
@@ -519,7 +519,7 @@ export default class Component extends Node {
519
519
? getTailSnippet ( binding . value . node )
520
520
: '' ;
521
521
522
- return `${ binding . name } : ctx. ${ name } ${ tail } ` ;
522
+ return `${ quoteNameIfNecessary ( binding . name ) } : ctx${ quotePropIfNecessary ( name ) } ${ tail } ` ;
523
523
} ) ;
524
524
525
525
function getAttributeValue ( attribute ) {
@@ -547,14 +547,14 @@ export default class Component extends Node {
547
547
if ( attribute . isSpread ) {
548
548
return attribute . expression . snippet ;
549
549
} else {
550
- return `{ ${ attribute . name } : ${ getAttributeValue ( attribute ) } }` ;
550
+ return `{ ${ quoteNameIfNecessary ( attribute . name ) } : ${ getAttributeValue ( attribute ) } }` ;
551
551
}
552
552
} )
553
553
. concat ( bindingProps . map ( p => `{ ${ p } }` ) )
554
554
. join ( ', ' )
555
555
} )`
556
556
: `{ ${ this . attributes
557
- . map ( attribute => `${ attribute . name } : ${ getAttributeValue ( attribute ) } ` )
557
+ . map ( attribute => `${ quoteNameIfNecessary ( attribute . name ) } : ${ getAttributeValue ( attribute ) } ` )
558
558
. concat ( bindingProps )
559
559
. join ( ', ' ) } }`;
560
560
@@ -585,7 +585,7 @@ export default class Component extends Node {
585
585
if (${ conditions . reverse ( ) . join ( '&&' ) } ) {
586
586
tmp = ${ expression } .data();
587
587
if ('${ name } ' in tmp) {
588
- ctx. ${ binding . name } = tmp.${ name } ;
588
+ ctx${ quotePropIfNecessary ( binding . name ) } = tmp.${ name } ;
589
589
settled = false;
590
590
}
591
591
}
0 commit comments