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(convert-signal-inputs): handle automatic semicolon insertion issues #294

Merged
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
17 changes: 17 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 @@ -180,6 +180,15 @@ export class RequestInfoComponent implements OnInit {
this.submitter$.next();
}
}`,
issue290: `
import { Component } from '@angular/core';

@Component({})
export class MyCmp {
@Input() inputWithoutType;
noColon = true
}
`,
} as const;

describe('convertSignalInputsGenerator', () => {
Expand Down Expand Up @@ -245,4 +254,12 @@ describe('convertSignalInputsGenerator', () => {
const [updated] = readContent();
expect(updated).toMatchSnapshot();
});

it('should fail for issue #290', async () => {
const readContent = setup('issue290');
await expect(async () => {
await convertSignalInputsGenerator(tree, options);
readContent();
}).rejects.toThrow();
});
});
12 changes: 10 additions & 2 deletions libs/plugin/src/generators/convert-signal-inputs/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,16 @@ export async function convertSignalInputsGenerator(

node.replaceWithText(newProperty.print());

// remove old class property Input
newProperty.remove();
// fail gracefully for nodes not terminated with a semi-colon
try {
// remove old class property Input
newProperty.remove();
} catch (err) {
logger.warn(
`[ngxtension] "${path}" Failed to parse node, check that declarations are terminated with a semicolon and try again`,
);
throw err;
}

// track converted inputs
convertedInputs.add(name);
Expand Down
Loading