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

fix(input-migration): enhance regexp to consider whitespaces when matching against temp… #409

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -4,6 +4,11 @@ exports[`convertSignalInputsGenerator should convert properly 1`] = `
"
import { Component, Input, input } from '@angular/core';

interface Person {
name: string;
lastname: string;
}

@Component({

template: \`
Expand Down Expand Up @@ -51,6 +56,7 @@ import { Component, Input, input } from '@angular/core';
<button (click)="someFunctionWithnormalInput('normalInput', normalInput())"></button>
<button (normalInput)="someFunctionWithnormalInput(normalInput(), 'normalInput')"></button>
<button (eventWithnormalInput)="test = 'normalInput' + normalInput()"></button>
<button (click)="test = person()?.name"></button>

<a>
{{ 'someNormalTextnormalInput' | translate: 'normalInput' }}
Expand All @@ -69,6 +75,17 @@ import { Component, Input, input } from '@angular/core';

<p>{{ data().normalInput }}</p>

<p>{{person()?.name ? person().name : ""}}</p>
<p>{{
person().name
}}</p>

<ng-template #sample let-title="name">
<span>{{title}}</span>
</ng-template>

<ng-template *ngTemplateOutlet="sample; context: {name: person().name}"></ng-template>

\`
})
export class MyCmp {
Expand All @@ -85,6 +102,7 @@ export class MyCmp {
requiredWithAliasAndTransform = input.required<number, number | string>({ alias: 'transformedRequiredAlias', transform: numberAttribute });
withTransformWithoutType = input(booleanAttribute(false), { transform: booleanAttribute });
requiredWithTransformWithoutType = input(numberAttribute(1), { transform: numberAttribute });
person = input<Person>();

@Input() set leaveMeAlone(value: number) {
console.log('setter', value);
Expand Down Expand Up @@ -396,6 +414,7 @@ exports[`convertSignalInputsGenerator should convert properly for templateUrl 2`
<button (click)="someFunctionWithnormalInput('normalInput', normalInput())"></button>
<button (normalInput)="someFunctionWithnormalInput(normalInput(), 'normalInput')"></button>
<button (eventWithnormalInput)="test = 'normalInput' + normalInput()"></button>
<button (click)="test = person?.name"></button>

<a>
{{ 'someNormalTextnormalInput' | translate: 'normalInput' }}
Expand All @@ -413,6 +432,17 @@ exports[`convertSignalInputsGenerator should convert properly for templateUrl 2`
<cmp normalInput="normalInput"></cmp>

<p>{{ data().normalInput }}</p>

<p>{{person?.name ? person.name : ""}}</p>
<p>{{
person.name
}}</p>

<ng-template #sample let-title="name">
<span>{{title}}</span>
</ng-template>

<ng-template *ngTemplateOutlet="sample; context: {name: person.name}"></ng-template>
"
`;

Expand Down
18 changes: 18 additions & 0 deletions libs/plugin/src/generators/convert-signal-inputs/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const template = `<div>{{ inputWithoutType }}</div>
<button (click)="someFunctionWithnormalInput('normalInput', normalInput)"></button>
<button (normalInput)="someFunctionWithnormalInput(normalInput, 'normalInput')"></button>
<button (eventWithnormalInput)="test = 'normalInput' + normalInput"></button>
<button (click)="test = person?.name"></button>

<a>
{{ 'someNormalTextnormalInput' | translate: 'normalInput' }}
Expand All @@ -65,6 +66,17 @@ const template = `<div>{{ inputWithoutType }}</div>
<cmp normalInput="normalInput"></cmp>

<p>{{ data().normalInput }}</p>

<p>{{person?.name ? person.name : ""}}</p>
<p>{{
person.name
}}</p>

<ng-template #sample let-title="name">
<span>{{title}}</span>
</ng-template>

<ng-template *ngTemplateOutlet="sample; context: {name: person.name}"></ng-template>
`;

const filesMap = {
Expand All @@ -91,6 +103,11 @@ export class MyCmp {
component: `
import { Component, Input } from '@angular/core';

interface Person {
name: string;
lastname: string;
}

@Component({
template: \`
${template}
Expand All @@ -110,6 +127,7 @@ export class MyCmp {
@Input({ required: true, alias: 'transformedRequiredAlias', transform: numberAttribute }) requiredWithAliasAndTransform!: number;
@Input({ transform: booleanAttribute }) withTransformWithoutType = false;
@Input({ transform: numberAttribute }) requiredWithTransformWithoutType = 1;
@Input() person: Person;

@Input() set leaveMeAlone(value: number) {
console.log('setter', value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function replaceVariablesInsideInterpolation(
variables: string[],
): string {
// find all interpolations and replace the variables for each interpolation
value = value.replaceAll(/{{(.*?)}}/g, (match) => {
value = value.replaceAll(/{{\s*(.*?)\s*}}/g, (match) => {
const usedVars = [];
for (const variable of variables) {
if (match.includes(variable)) {
Expand Down
Loading