66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { Attribute , Element , HtmlParser , Node , ParseTreeResult , visitAll } from '@angular/compiler' ;
9+ import { Attribute , Element , Node , ParseTreeResult , visitAll } from '@angular/compiler' ;
1010import { dirname , join } from 'path' ;
1111import ts from 'typescript' ;
1212
@@ -20,13 +20,12 @@ import {
2020 i18nCollector ,
2121 importRemovals ,
2222 importWithCommonRemovals ,
23- MigrateError ,
24- ParseResult ,
2523 startI18nMarker ,
2624 startMarker ,
2725 Template ,
2826 TemplateCollector ,
2927} from './types' ;
28+ import { MigrateError , parseTemplate } from '../../utils/parse_html' ;
3029
3130const startMarkerRegex = new RegExp ( startMarker , 'gm' ) ;
3231const endMarkerRegex = new RegExp ( endMarker , 'gm' ) ;
@@ -265,36 +264,6 @@ function getNestedCount(etm: ElementToMigrate, aggregator: number[]) {
265264 }
266265}
267266
268- /**
269- * parses the template string into the Html AST
270- */
271- export function parseTemplate ( template : string ) : ParseResult {
272- let parsed : ParseTreeResult ;
273- try {
274- // Note: we use the HtmlParser here, instead of the `parseTemplate` function, because the
275- // latter returns an Ivy AST, not an HTML AST. The HTML AST has the advantage of preserving
276- // interpolated text as text nodes containing a mixture of interpolation tokens and text tokens,
277- // rather than turning them into `BoundText` nodes like the Ivy AST does. This allows us to
278- // easily get the text-only ranges without having to reconstruct the original text.
279- parsed = new HtmlParser ( ) . parse ( template , '' , {
280- // Allows for ICUs to be parsed.
281- tokenizeExpansionForms : true ,
282- // Explicitly disable blocks so that their characters are treated as plain text.
283- tokenizeBlocks : true ,
284- preserveLineEndings : true ,
285- } ) ;
286-
287- // Don't migrate invalid templates.
288- if ( parsed . errors && parsed . errors . length > 0 ) {
289- const errors = parsed . errors . map ( ( e ) => ( { type : 'parse' , error : e } ) ) ;
290- return { tree : undefined , errors} ;
291- }
292- } catch ( e : any ) {
293- return { tree : undefined , errors : [ { type : 'parse' , error : e } ] } ;
294- }
295- return { tree : parsed , errors : [ ] } ;
296- }
297-
298267export function validateMigratedTemplate ( migrated : string , fileName : string ) : MigrateError [ ] {
299268 const parsed = parseTemplate ( migrated ) ;
300269 let errors : MigrateError [ ] = [ ] ;
0 commit comments