File tree Expand file tree Collapse file tree 3 files changed +43
-11
lines changed
ng-generate/control-flow-migration Expand file tree Collapse file tree 3 files changed +43
-11
lines changed Original file line number Diff line number Diff line change @@ -119,9 +119,8 @@ function runControlFlowMigration(
119119}
120120
121121function sortFilePaths ( names : string [ ] ) : string [ ] {
122- const templateFiles = names . filter ( n => n . endsWith ( '.html' ) ) ;
123- const classFiles = names . filter ( n => ! n . endsWith ( '.html' ) ) ;
124- return [ ...templateFiles , ...classFiles ] ;
122+ names . sort ( ( a , _ ) => a . endsWith ( '.html' ) ? - 1 : 0 ) ;
123+ return names ;
125124}
126125
127126function generateErrorMessage ( path : string , errors : MigrateError [ ] ) : string {
Original file line number Diff line number Diff line change @@ -133,14 +133,12 @@ export class ElementToMigrate {
133133
134134 getTemplateName ( targetStr : string , secondStr ?: string ) : string {
135135 const targetLocation = this . attr . value . indexOf ( targetStr ) ;
136- if ( secondStr ) {
137- const secondTargetLocation = this . attr . value . indexOf ( secondStr ) ;
138- return this . attr . value . slice ( targetLocation + targetStr . length , secondTargetLocation )
139- . trim ( )
140- . split ( ';' ) [ 0 ]
141- . trim ( ) ;
142- }
143- return this . attr . value . slice ( targetLocation + targetStr . length ) . trim ( ) . split ( ';' ) [ 0 ] . trim ( ) ;
136+ const secondTargetLocation = secondStr ? this . attr . value . indexOf ( secondStr ) : undefined ;
137+ return this . attr . value . slice ( targetLocation + targetStr . length , secondTargetLocation )
138+ . replace ( ':' , '' )
139+ . trim ( )
140+ . split ( ';' ) [ 0 ]
141+ . trim ( ) ;
144142 }
145143
146144 start ( offset : number ) : number {
Original file line number Diff line number Diff line change @@ -723,6 +723,41 @@ describe('control flow migration', () => {
723723 ] . join ( '\n' ) ) ;
724724 } ) ;
725725
726+ it ( 'should migrate an if else case with a colon after else' , async ( ) => {
727+ writeFile ( '/comp.ts' , `
728+ import {Component} from '@angular/core';
729+ import {NgIf} from '@angular/common';
730+
731+ @Component({
732+ templateUrl: './comp.html'
733+ })
734+ class Comp {
735+ show = false;
736+ }
737+ ` ) ;
738+
739+ writeFile ( '/comp.html' , [
740+ `<div>` ,
741+ `<span *ngIf="show; else: elseTmpl">Content here</span>` ,
742+ `<ng-template #elseTmpl>Else Content</ng-template>` ,
743+ `</div>` ,
744+ ] . join ( '\n' ) ) ;
745+
746+ await runMigration ( ) ;
747+ const actual = tree . readContent ( '/comp.html' ) ;
748+ const expected = [
749+ `<div>` ,
750+ ` @if (show) {` ,
751+ ` <span>Content here</span>` ,
752+ ` } @else {` ,
753+ ` Else Content` ,
754+ ` }` ,
755+ `</div>` ,
756+ ] . join ( '\n' ) ;
757+
758+ expect ( actual ) . toBe ( expected ) ;
759+ } ) ;
760+
726761 it ( 'should migrate an if else case with no space after ;' , async ( ) => {
727762 writeFile ( '/comp.ts' , `
728763 import {Component} from '@angular/core';
You can’t perform that action at this time.
0 commit comments