Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(schematics): valid migration for expandable in template #10123

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,41 @@
['tui-input-tag', 'tui-multi-select', 'tui-input-date'],
);

elements.forEach(({attrs, sourceCodeLocation}) => {
const expandableAttr = findAttr(attrs, 'expandable');

if (!expandableAttr) {
return;
}

const expandableValue = expandableAttr?.value;
const expandableStart =
sourceCodeLocation?.attrs?.[expandableAttr.name]?.startOffset ?? 0;
const expandableEnd =
sourceCodeLocation?.attrs?.[expandableAttr.name]?.endOffset ?? 0;

if (expandableValue === 'false') {
const rowsAttr = findAttr(attrs, 'rows');

const insertTo = (sourceCodeLocation?.startTag?.endOffset ?? 0) - 1;
const insertOffset = templateOffset + insertTo;
const selfClosing = template[insertOffset - 1] === '/';

recorder.insertRight(templateOffset + insertTo, rowsAttr ? '' : '[rows]="1"');
recorder.insertRight(
selfClosing ? insertOffset - 1 : insertOffset,
rowsAttr ? '' : '[rows]="1"',
);
}

if (expandableValue !== 'false' && expandableValue !== 'true') {
recorder.insertRight(
templateOffset + (sourceCodeLocation?.startTag?.startOffset ?? 0),
'<!-- Taiga migration TODO: "expandable" property has been removed. Use "rows" property instead -->\n',
);
}

recorder.remove(
templateOffset + expandableStart,
expandableEnd - expandableStart,
);
});

Check notice on line 66 in projects/cdk/schematics/ng-update/v4/steps/templates/migrate-expandable.ts

View check run for this annotation

codefactor.io / CodeFactor

projects/cdk/schematics/ng-update/v4/steps/templates/migrate-expandable.ts#L30-L66

Complex Method
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const TEMPLATE_BEFORE = `
[formControl]="test"
></tui-input-tag>

<tui-input-tag
[expandable]="false"
[formControl]="test"
/>

<tui-multi-select
[expandable]="false"
>
Expand Down Expand Up @@ -70,6 +75,11 @@ const TEMPLATE_AFTER = `
[formControl]="test"
[rows]="1"></tui-input-tag>

<tui-input-tag
${''}
[formControl]="test"
[rows]="1"/>

<tui-multi-select
${''}
[rows]="1">
Expand Down
Loading