Commit graph

253 commits

Author SHA1 Message Date
Kristiyan Kostadinov
fb540e169a feat(core): add migration for invalid two-way bindings (#54630)
As a part of #54154, an old parser behavior came up where two-way bindings were parsed by appending `= $event` to the event side. This was problematic, because it allowed some non-writable expressions to be passed into two-way bindings.

These changes introduce a migration that will change the two-way bindings into two separate input/output bindings that represent the old behavior so that in a future version we can throw a parser error for the invalid expressions.

```ts
// Before
@Component({
  template: `<input [(ngModel)]="a && b"/>`
})
export class MyComp {}

// After
@Component({
  template: `<input [ngModel]="a && b" (ngModelChange)="a && (b = $event)"/>`
})
export class MyComp {}
```

PR Close #54630
2024-02-28 18:06:23 +01:00
Kristiyan Kostadinov
71e0c7df69 fix(migrations): resolve infinite loop for a single line element with a long tag name and angle bracket on a new line (#54588)
Fixes an edge case where a single-line elemnt with a long tag name a closing bracket on a new line was putting the control flow migration into an infinite loop.

Fixes #54587.

PR Close #54588
2024-02-23 11:40:27 -08:00
Jessica Janiuk
42d3ddd9ae fix(migrations): Fix cf migration regular expression to include underscores (#54533)
In rare cases people may use an underscore in their component names, which was not accounted for in the formatting portion of the migration.

fixes: #54532

PR Close #54533
2024-02-21 15:25:05 -08:00
Kristiyan Kostadinov
28ad6fc4ad fix(migrations): error in standalone migration when non-array value is used as declarations in TestBed (#54122)
Adds some logic to skip over `TestBed.configureTestingModule` calls where the `declarations` aren't initialized to an array. We can't migrate these cases, because test migrations don't have access to the Angular compiler. Previously the migration would throw a runtime error.

PR Close #54122
2024-01-29 15:40:05 +00:00
Jessica Janiuk
d0b95d5877 fix(migrations): Fix empty switch case offset bug in cf migration (#53839)
This addresses the offset issue caused when a switch case was empty with no spaces or children being affected by the markers that were added, but not accounted for in offset. The markers are not needed for empty content and can be safely removed in this case.

fixes: #53779

PR Close #53839
2024-01-09 12:09:38 -08:00
Jessica Janiuk
fb7c58cda7 fix(migrations): cf migration - detect and error when result is invalid i18n nesting (#53638)
This will gracefully error on templates when the resulting template would have invalid i18n nested structures.

PR Close #53638
2023-12-19 11:01:57 -08:00
Jessica Janiuk
22b95de9bc fix(migrations): cf migration - fix bug in attribute formatting (#53636)
The formatting that would preserve attribute indents completely missed attributes that start on new lines rather than the same line as the opening element.

PR Close #53636
2023-12-19 10:16:29 -08:00
Jessica Janiuk
8e2178792d fix(migrations): cf migration - ensure full check runs for all imports (#53637)
In cases where CommonModule was unsafe to remove but other imports were present, the symbol check would be skipped. This should run for all the possibly removed symbols for safety.

PR Close #53637
2023-12-19 10:11:47 -08:00
Jessica Janiuk
8bf752539f fix(migrations): cf migration - preserve indentation on attribute strings (#53625)
During formatting, attribute indentation is changed, and that can affect internationalized strings. This fix detects if an attribute value string is left open and skips formatting on those lines.

PR Close #53625
2023-12-18 22:38:52 +00:00
Jessica Janiuk
b40bb22a66 fix(migrations): cf migration - improve import declaration handling (#53622)
This should make the import declaration symbol removal a bit more robust and handle more than just CommonModule safely.

PR Close #53622
2023-12-18 22:10:58 +00:00
Jessica Janiuk
1892904070 refactor(migrations): update cf migration to handle module imports better (#53575)
This addresses the case where modules are being used and declared in the same file as the component. It is unclear whether its safe to remove the common module in this case, so best to leave it.

PR Close #53575
2023-12-15 19:58:40 +00:00
Jessica Janiuk
7bb312fcf6 fix(migrations): cf migration - stop removing empty newlines from i18n blocks (#53578)
Since i18n sections are whitespace sensitive, we should avoid removing empty lines when inside an i18n block that were present before.

PR Close #53578
2023-12-15 19:49:04 +00:00
Jessica Janiuk
db6b4a6bc4 fix(migrations): Fix cf migration bug with parsing for loop conditions properly (#53558)
The order of operations for getting for loop parts was inverted resulting in the StringStack to never be reduced.

fixes: #53555

PR Close #53558
2023-12-14 09:33:27 -08:00
Jessica Janiuk
5fa76c372e refactor(migrations): CF migration - add support for not reformatting i18n tags (#53538)
Internationalization is whitespace sensitive. This change updates the formatting code to process for i18n attributes and prevent reformatting those sections of the template.

PR Close #53538
2023-12-13 09:34:54 -08:00
Jessica Janiuk
ce1076785c fix(migrations): cf migration validate structure of ngswitch before migrating (#53530)
This fix handles the common case where an ngswitch might have invalid syntax post migration. This is likely due to using elements other than case or default underneath the ngswitchcase. This will fail out of the migration for that file when these cases are detected with a useful console message.

fixes: #53234

PR Close #53530
2023-12-13 09:23:15 -08:00
Jessica Janiuk
6aa1bb78e8 fix(migrations): cf migration - undo changes when html fails to parse post migration (#53530)
In the case that a template has some sort of structural issue prior to migrating, like a tag that is not properly closed resulting in invalid HTML post migration, this will attempt to parse the html after migrating and revert to the original structure. An error during migration will be reported out instead.

PR Close #53530
2023-12-13 09:23:14 -08:00
Jessica Janiuk
cc02852ac4 fix(migrations): CF migration only remove newlines of changed template content (#53508)
The formatting logic would eliminate all newlines in updated template code. This adds start and end markers for tracking when the formatter is in a block of template code that changed or not. It should leave behind any newlines that are outside of a migrated section.

fixes: #53494

PR Close #53508
2023-12-12 09:03:15 -08:00
Jessica Janiuk
79f791543b fix(migrations): fix cf migration import removal when errors occur (#53502)
When migrating a component and the associated external template, if errors occur, the component should not remove the common module imports. This fix should allow the application to still build in that instance.

PR Close #53502
2023-12-12 09:02:32 -08:00
Jessica Janiuk
a02767956a fix(migrations): CF Migration - ensure bound ngIfElse cases ignore line breaks (#53435)
When using ternaries or other expressions in bound if / else cases, it is possible that line breaks could end up affecting template replacement.

fixes: #53428

PR Close #53435
2023-12-08 14:31:25 -08:00
Jessica Janiuk
1f5c8bf116 fix(migrations): ensure we do not overwrite prior template replacements in migration (#53393)
This fixes a bug where only the last replacement of a template placeholder would apply.

fixes: #53383

PR Close #53393
2023-12-07 09:36:01 -08:00
Jessica Janiuk
2a5a8f6f05 fix(migrations): Change CF Migration ng-template placeholder generation and handling (#53394)
Using more unique characters makes it easier to parse placeholders that may contain JS logic, making it more flexible.

fixes: #53386
fixes: #53385
fixes: #53384

PR Close #53394
2023-12-06 09:42:43 -08:00
Jessica Janiuk
01b18a4248 fix(migrations): handle templates outside of component in cf migration (#53368)
If a template is passed in as an input, the ng-template will not exist in the same component template. This will leave a template placeholder behind. This fix ensures that template placeholder gets turned into a template outlet.

fixes: #53361

PR Close #53368
2023-12-05 17:19:37 -08:00
Jessica Janiuk
5a0ed28c9d fix(migrations): handle nested ng-template replacement safely in CF migration (#53368)
When there are ng-templates nested inside other ng-templates, the replacement and removal of the templates gets disrupted. Re-processing the templates in the file along the way resolves this issue.

fixes: #53362

PR Close #53368
2023-12-05 17:19:36 -08:00
Jessica Janiuk
6f75471307 fix(migrations): CF Migration fix missing alias for bound ngifs (#53296)
Empty aliases are considered the item in an ngFor, and ngIf was skipping that value.

fixes: #53291

PR Close #53296
2023-12-04 21:42:57 -08:00
Jessica Janiuk
aad5e5bd0e fix(migrations): CF Migration add support for ngIf with just a then (#53297)
Prior to this fix, the expectation that anytime then was used, else would always be present. That is not a valid assumption.

fixes: #53287

PR Close #53297
2023-12-01 10:33:53 -08:00
Jessica Janiuk
1c1e8c477b fix(migrations): CF migration - ensure NgIfElse attributes are properly removed (#53298)
the attribute in question was assumed to be at the start of the replaced content, but it could be later, too.

fixes: #53288

PR Close #53298
2023-12-01 10:32:35 -08:00
Jessica Janiuk
2998d482dd fix(migrations): CF Migration - Fix case of aliases on i18n ng-templates preventing removal (#53299)
i18n template removal expected no other attributes to be present, but if a bound ngIf is present with aliases and i18n, that is more than what was expected. Now it should safely remove them appropriately.

fixes: #53289

PR Close #53299
2023-12-01 09:18:31 -08:00
Jessica Janiuk
03e2f1bb25 fix(migrations): fix regexp for else and then in cf migration (#53257)
The regexp for then and else did not ignore alphanumeric characters prior to the then and else. So if a string contained then, for example Authentication, it would incorrectly match as a then clause.

fixes: #53252

PR Close #53257
2023-11-30 09:19:43 -08:00
Jessica Janiuk
f4a96a9160 fix(migrations): handle aliases on bound ngIf migrations (#53261)
This fixes a reported issue where ngIf is used on an ng-template with let aliases.

fixes: #53251

PR Close #53261
2023-11-30 09:19:15 -08:00
Jessica Janiuk
a3599515bb fix(migrations): properly handle ngIfThen cases in CF migration (#53256)
The migration was handling bound casees of [ngIfThenElse] and also needed [ngIfThen].

fixes: #53254

PR Close #53256
2023-11-29 17:34:02 +01:00
Jessica Janiuk
6291c8db09 fix(migrations): fix off by one issue with template removal in CF migration (#53255)
When ng-templates are removed, an extra space was being added when it was unnecessary. This resulted in malformed html if there was no space afterwards.

fixes: #53248

PR Close #53255
2023-11-29 17:33:18 +01:00
Jessica Janiuk
fadfee4324 fix(migrations): cf migration fix migrating empty switch default (#53237)
This should address cases when using ng-containers with ngSwitchCase / ngSwitchDefault
and migrating them safely when they are empty.

fixes: #53235

PR Close #53237
2023-11-29 15:15:50 +01:00
Jessica Janiuk
b2aeaf5d97 fix(migrations): CF migration log warning when collection aliasing detected in @for (#53238)
This logs a warning when an ngFor has a collection aliased, which is not supported with new syntax.

fixes: #53233

PR Close #53238
2023-11-29 10:29:52 +01:00
Jessica Janiuk
c6326289f8 fix(migrations): cf migration removes unnecessary bound ngifelse attribute (#53236)
this removes a no longer necessary attribute in bound ngIfElse cases.

fixes: #53230

PR Close #53236
2023-11-29 09:47:44 +01:00
Jessica Janiuk
f1b7d40057 fix(migrations): fixes CF migration i18n ng-template offsets (#53212)
This addresses an issue where multiple ng-templates are present with i18n attributes. The offsets would be incorrectly accounted for when being replaced with an ng-container.

fixes: #53149

PR Close #53212
2023-11-28 16:44:11 +01:00
Jessica Janiuk
8a52674faa fix(migrations): Update CF migration to skip templates with duplicate ng-template names (#53204)
This adds a message to the console and skips any templates that detect duplicate ng-template names in the same component.
fixes: #53169

PR Close #53204
2023-11-28 16:43:28 +01:00
Jessica Janiuk
53912fdf74 fix(migrations): allows colons in ngIf else cases to migrate (#53076)
This makes sure colons after else and then cases get migrated properly.
fixes: #53150

PR Close #53076
2023-11-28 14:03:28 +01:00
Jessica Janiuk
a738b48717 fix(migrations): fixes control flow migration common module removal (#53076)
Common module removal would not happen when a component used a templateUrl due to the checks being in separate files. This change passes the removal analysis back to the original source file to safely remove CommonModule.

PR Close #53076
2023-11-28 14:03:28 +01:00
Jessica Janiuk
dbca1c9d61 fix(migrations): Add ngForTemplate support to control flow migration (#53076)
This adds code to cover the rare use case of an ngFor with a template param.
fixes: #53068

PR Close #53076
2023-11-28 14:03:28 +01:00
Jessica Janiuk
e6f10e81d2 fix(migrations): control flow migration formatting fixes (#53076)
This fix preserves leading indents in inline templates and also adds better handling for self closing tags

PR Close #53076
2023-11-28 14:03:28 +01:00
Jessica Janiuk
e090b48bf8 fix(migrations): tweaks to formatting in control flow migration (#53058)
This addresses a few minor formatting issues with the control flow migration.

fixes: #53017

PR Close #53058
2023-11-20 10:46:43 -08:00
anthonyfr75
e33f6e0f1a fix(migrations): control flow migration fails for async pipe with unboxing of observable (#52756) (#52972)
Update control flow syntax to use 'as' for proper async pipe handling, accounting for variable whitespace before 'let'.

Fixes #52756

PR Close #52972
2023-11-20 08:58:44 -08:00
Jessica Janiuk
28f6cbf9c9 fix(migrations): fixes migrations of nested switches in control flow (#53010)
This separates out the NgSwitch migration pass from the NgSwitchCase / Default pass, which makes nested switch migrations work.

fixes: #53009

PR Close #53010
2023-11-20 08:56:53 -08:00
Jessica Janiuk
5564d020cd fix(migrations): Fixes control flow migration if then else case (#53006)
With if then else use cases, we now properly account for the length
of the original element's contents when tracking new offsets.

fixes: #52927

PR Close #53006
2023-11-20 08:56:17 -08:00
Jessica Janiuk
6e29e853ed refactor(migrations): Add optional template reformatting after migration (#52939)
This adds the ability to reformat the template with proper indents after the migraion finishes. It is an optional parameter.

PR Close #52939
2023-11-16 09:30:34 -08:00
Jessica Janiuk
8f5124ea95 fix(migrations): Add missing support for ngForOf (#52903)
This adds support to migrate ngForOf and ngForTrackBy when migrating control flow.

PR Close #52903
2023-11-15 14:06:18 +00:00
Jessica Janiuk
42805e3204 fix(migrations): Add support for bound versions of NgIfElse and NgIfThenElse (#52869)
This ensures the bound version of NgIfElse and NgIfThenElse work properly with the migration.

fixes: #52842

PR Close #52869
2023-11-13 22:33:33 +00:00
Jessica Janiuk
0e7b1daa8d fix(migrations): Fixes issue with multiple if elses with same template (#52863)
This should fix the issue where if the same ng-template is used with multiple if / else statements, it replaces all usages properly.
fixes: #52854

PR Close #52863
2023-11-13 18:23:55 +00:00
Jessica Janiuk
17adf0f917 fix(migrations): Add support for removing imports post migration (#52763)
This update removes imports from component decorators and at the top of the files. It only removes standalone imports though. It does not remove CommonModule if that is the only import.

PR Close #52763
2023-11-13 15:21:06 +00:00
Jessica Janiuk
12f979d5c6 fix(migrations): Add support for ng-templates with i18n attributes (#52597)
This makes sure that i18n attributes are preserved on ng-templates being removed during the migration.

fixes: #52517

PR Close #52597
2023-11-08 10:26:20 -08:00