@@ -39,6 +39,20 @@ type NodeTransformOptions = {
3939 parent ?: angular . AST ;
4040} ;
4141
42+ const assignmentOperators = new Set ( [
43+ '=' ,
44+ // https://github.com/angular/angular/pull/62064
45+ '+=' , // addition assignment
46+ '-=' , // subtraction assignment
47+ '*=' , // multiplication assignment
48+ '/=' , // division assignment
49+ '%=' , // remainder assignment
50+ '**=' , // exponentiation assignment
51+ '&&=' , // logical AND assignment
52+ '||=' , // logical OR assignment
53+ '??=' , // nullish coalescing assignment
54+ ] ) ;
55+
4256class Transformer extends Source {
4357 #node;
4458 #text;
@@ -170,6 +184,19 @@ class Transformer extends Source {
170184 ) ;
171185 }
172186
187+ if ( assignmentOperators . has ( operator ) ) {
188+ return this . #create< babel . AssignmentExpression > (
189+ {
190+ ...properties ,
191+ type : 'AssignmentExpression' ,
192+ left : left as babel . MemberExpression ,
193+ operator,
194+ ...node . sourceSpan ,
195+ } ,
196+ { hasParentParens : isInParentParens } ,
197+ ) ;
198+ }
199+
173200 return this . #create< babel . BinaryExpression > (
174201 {
175202 ...properties ,
@@ -263,13 +290,19 @@ class Transformer extends Source {
263290 node instanceof angular . KeyedRead ||
264291 node instanceof angular . SafeKeyedRead
265292 ) {
293+ // TODO: Use `node.sourceSpan.end` directly
294+ // https://github.com/angular/angular/issues/62617
295+ const end =
296+ this . text . charAt ( node . sourceSpan . end - 1 ) === '='
297+ ? this . getCharacterLastIndex ( / \S / , node . sourceSpan . end - 2 ) + 1
298+ : node . sourceSpan . end ;
266299 return this . #transformReceiverAndName(
267300 node . receiver ,
268301 this . #transform< babel . Expression > ( node . key ) ,
269302 {
270303 computed : true ,
271304 optional : node instanceof angular . SafeKeyedRead ,
272- end : node . sourceSpan . end , // ]
305+ end : end , // ]
273306 hasParentParens : isInParentParens ,
274307 } ,
275308 ) ;
@@ -485,14 +518,11 @@ class Transformer extends Source {
485518 node instanceof angular . SafePropertyRead
486519 ) {
487520 const { receiver, name } = node ;
488- const nameEnd =
489- this . getCharacterLastIndex ( / \S / , node . sourceSpan . end - 1 ) + 1 ;
490521 const tName = this . #create< babel . Identifier > (
491522 {
492523 type : 'Identifier' ,
493524 name,
494- start : nameEnd - name . length ,
495- end : nameEnd ,
525+ ...node . nameSpan ,
496526 } ,
497527 isImplicitThis ( receiver , this . #text)
498528 ? { hasParentParens : isInParentParens }
@@ -505,58 +535,6 @@ class Transformer extends Source {
505535 } ) ;
506536 }
507537
508- if ( node instanceof angular . KeyedWrite ) {
509- const key = this . #transform< babel . Expression > ( node . key ) ;
510- const right = this . #transform< babel . Expression > ( node . value ) ;
511- const left = this . #transformReceiverAndName( node . receiver , key , {
512- computed : true ,
513- optional : false ,
514- end : this . getCharacterIndex ( ']' , getOuterEnd ( key ) ) + 1 ,
515- } ) ;
516- return this . #create< babel . AssignmentExpression > (
517- {
518- type : 'AssignmentExpression' ,
519- left : left as babel . MemberExpression ,
520- operator : '=' ,
521- right,
522- start : getOuterStart ( left ) ,
523- end : getOuterEnd ( right ) ,
524- } ,
525- { hasParentParens : isInParentParens } ,
526- ) ;
527- }
528-
529- if ( node instanceof angular . PropertyWrite ) {
530- const { receiver, name, value } = node ;
531- const tValue = this . #transform< babel . Expression > ( value ) ;
532- const nameEnd =
533- this . getCharacterLastIndex (
534- / \S / ,
535- this . getCharacterLastIndex ( '=' , getOuterStart ( tValue ) - 1 ) - 1 ,
536- ) + 1 ;
537- const tName = this . #create< babel . Identifier > ( {
538- type : 'Identifier' ,
539- name,
540- start : nameEnd - name . length ,
541- end : nameEnd ,
542- } ) ;
543- const tReceiverAndName = this . #transformReceiverAndName( receiver , tName , {
544- computed : false ,
545- optional : false ,
546- } ) ;
547- return this . #create< babel . AssignmentExpression > (
548- {
549- type : 'AssignmentExpression' ,
550- left : tReceiverAndName as babel . MemberExpression ,
551- operator : '=' ,
552- right : tValue ,
553- start : getOuterStart ( tReceiverAndName ) ,
554- end : getOuterEnd ( tValue ) ,
555- } ,
556- { hasParentParens : isInParentParens } ,
557- ) ;
558- }
559-
560538 if ( node instanceof angular . TaggedTemplateLiteral ) {
561539 return this . #create< babel . TaggedTemplateExpression > ( {
562540 type : 'TaggedTemplateExpression' ,
@@ -619,8 +597,6 @@ class Transformer extends Source {
619597type SupportedNodes =
620598 | angular . ASTWithSource // Not handled
621599 | angular . PropertyRead
622- | angular . PropertyWrite
623- | angular . KeyedWrite
624600 | angular . Call
625601 | angular . LiteralPrimitive
626602 | angular . Unary
0 commit comments