diff --git a/src/material/schematics/ng-generate/mdc-migration/rules/tree-traversal.ts b/src/material/schematics/ng-generate/mdc-migration/rules/tree-traversal.ts index 75105588813c..481ec8432b73 100644 --- a/src/material/schematics/ng-generate/mdc-migration/rules/tree-traversal.ts +++ b/src/material/schematics/ng-generate/mdc-migration/rules/tree-traversal.ts @@ -158,11 +158,6 @@ export function updateAttribute( const prefix = html.slice(0, index); const suffix = html.slice(index); const attrText = newValue ? `${name}="${newValue}"` : `${name}`; - - if (node.startSourceSpan.start.line === node.startSourceSpan.end.line) { - return `${prefix} ${attrText}${suffix}`; - } - const indentation = parseIndentation(html, node); return prefix + indentation + attrText + suffix; } @@ -174,13 +169,13 @@ function parseIndentation(html: string, node: TmplAstElement): string { // Starting after the start source span's tagname, // read and store each char until we reach a non-whitespace char. - for (let i = startOffset; i < html.length - 1; i++) { + for (let i = startOffset; i < node.startSourceSpan.end.offset - 1; i++) { if (!/\s/.test(html.charAt(i))) { break; } whitespace += html.charAt(i); } - return whitespace; + return whitespace || ' '; } /**