-
Notifications
You must be signed in to change notification settings - Fork 26.5k
feat(migrations): ngclass directives to class bindings #62983
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
base: main
Are you sure you want to change the base?
Conversation
81c69f2
to
c96deb3
Compare
Hi @JeanMeche, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look at this.
Let's start with aligning the test cases with the expectations.
We'll go through the implementation after.
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
packages/core/schematics/ng-generate/ngclass-to-class-migration/README.md
Outdated
Show resolved
Hide resolved
packages/core/schematics/ng-generate/ngclass-to-class-migration/README.md
Outdated
Show resolved
Hide resolved
packages/core/schematics/ng-generate/ngclass-to-class-migration/README.md
Outdated
Show resolved
Hide resolved
e17d83c
to
7eed6fb
Compare
Hi @JeanMeche, I fix all your feedbacks. Except for related to the possible flag, I've only just currently update the relevant test case. Let me know if it's OK or if we want to proceed with a flag (if it's worth it). |
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
7eed6fb
to
fa20d78
Compare
@JeanMeche |
fa20d78
to
c2a775c
Compare
@JeanMeche I updated this PR with custom option |
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're missing tests that ensure we remove the unused import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're still missing those tests.
packages/core/schematics/migrations/ngclass-to-class-migration/util.ts
Outdated
Show resolved
Hide resolved
const templateVisitor = new NgComponentTemplateVisitor(typeChecker); | ||
templateVisitor.visitNode(node); | ||
|
||
const replacementsForClass: Replacement[] = []; | ||
let replacementCountForClass = 0; | ||
|
||
templateVisitor.resolvedTemplates.forEach((template) => { | ||
const {migrated, changed, replacementCount} = migrateNgClassBindings( | ||
template.content, | ||
this.config, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the following is text based. We should ensure first that the component is importing NgClass or CommonModule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean specifically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The NgClassCollector
is looking at strings not directive usages. This isn't safe enough. We need to make sure the ngClass
attributes are actually instances of the directive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still need to be addressed.
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
...ges/core/schematics/migrations/ngclass-to-class-migration/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
c2a775c
to
43d4f78
Compare
Deployed adev-preview for 739ea29 to: https://ng-dev-previews-fw--pr-angular-angular-62983-adev-prev-bjeua1yr.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
6036e1e
to
6882761
Compare
6882761
to
b44f7bf
Compare
@JeanMeche |
We'll need a rebase to be able to run the tests with the CI. |
b44f7bf
to
a7eee2a
Compare
Done. branch is up to date with main |
packages/core/schematics/test/ngclass-to-class-migration.spec.ts
Outdated
Show resolved
Hide resolved
3405a84
to
6acbb64
Compare
feat angular#61661 - add migration to convert ngClass to use class
6acbb64
to
739ea29
Compare
Hi @JeanMeche, any news fot this PR? |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Added Migration Feature to migrate ngClass to class
Issue Number: #61661
What is the new behavior?
It'll migrate ngClass to class bindings to follow the style guide Prefer class over ngClass
Now
Before
Does this PR introduce a breaking change?