Skip to content

Commit

Permalink
chore: fix migration self-closing tags (#7005)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirpotekhin authored Mar 15, 2024
1 parent 2b8156b commit e46eb74
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,18 @@ function migrateBadgeValue({
templateOffset: number;
}): void {
const attrValue = valueAttr?.value;
const insertTo = sourceCodeLocation?.endTag.startOffset;
const insertTo = sourceCodeLocation?.startTag.endOffset;
const selfClosing = !sourceCodeLocation?.endTag;

if (!attrValue || !insertTo) {
return;
}

recorder.insertRight(
insertTo + templateOffset,
valueAttr.name === 'value' ? attrValue : `{{ ${attrValue} }}`,
valueAttr.name === 'value'
? attrValue
: `{{ ${attrValue} }}${selfClosing ? '</tui-badge>' : ''}`,
);

const attrOffset = sourceCodeLocation?.attrs?.[valueAttr.name];
Expand All @@ -115,6 +118,10 @@ function migrateBadgeValue({

recorder.remove(templateOffset + startOffset - 1, endOffset - startOffset + 1);
}

if (selfClosing) {
recorder.remove(sourceCodeLocation.startTag.endOffset - 2, 1);
}
}

function addTodo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export function removeClosingTag(
templateOffset: number,
): void {
const {endTag} = sourceCodeLocation;

if (!endTag) {
return;
}

const {startOffset, endOffset} = endTag;

const from = templateOffset + startOffset;
Expand All @@ -60,9 +65,13 @@ export function removeClosingTag(
}

export function closeStartTag(
{startTag}: ElementLocation,
{startTag, endTag}: ElementLocation,
recorder: UpdateRecorder,
templateOffset: number,
): void {
if (!endTag) {
return;
}

recorder.insertRight(templateOffset + startTag.endOffset - 1, '/');
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export class TestComponent {
}`;

const TEMPLATE_BEFORE = `
<tui-badge
status="primary"
[value]="value"
[hoverable]="true"
/>
<tui-badge
status="primary"
[value]="value"
Expand All @@ -60,12 +65,17 @@ const TEMPLATE_AFTER = `
${''}
${''}
>{{ value }}</tui-badge>
<tui-badge
appearance="primary"
${''}
${''}
>{{ value }}</tui-badge>
<tui-badge
appearance="success"
${''}
iconLeft="tuiIconHelpCircle">
iconLeft="tuiIconHelpCircle">Taiga
${''}
Taiga</tui-badge>
</tui-badge>
<!-- Taiga migration TODO: use "<tui-icon>" with "tuiBadge" directive for icon-only badges instead -->
<tui-badge
appearance="success"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const TEMPLATE_BEFORE = `
[showIcons]="true"
[singleColor]="true"
></tui-toggle>
<tui-toggle
formControlName="test"
class="toggle"
/>
`;

const TEMPLATE_AFTER = `
Expand All @@ -62,6 +66,12 @@ const TEMPLATE_AFTER = `
[showIcons]="true"
${''}
/>
<input
tuiToggle
type="checkbox"
formControlName="test"
class="toggle"
/>
`;

describe('ng-update', () => {
Expand Down

0 comments on commit e46eb74

Please sign in to comment.