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(material/schematics): don't insert duplicate @use statements in themingApi #22755

Merged
merged 1 commit into from
Jun 2, 2021

Conversation

jelbourn
Copy link
Member

In the case where a file has mixed legacy and new theming API usage, the script would
add an extra duplicate @use statement.

@jelbourn jelbourn added P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release area: ng-update Issues related to `ng-update` integration labels May 21, 2021
@jelbourn jelbourn requested a review from crisbeto May 21, 2021 22:30
@jelbourn jelbourn requested a review from devversion as a code owner May 21, 2021 22:30
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 21, 2021
@@ -205,6 +205,11 @@ function renameSymbols(content: string,
/** Inserts an `@use` statement in a string. */
function insertUseStatement(content: string, importPath: string, importsToIgnore: string[],
namespace: string): string {
// If the content already has the `@use` import, we don't need to add anything.
if (content.includes(`@use '${importPath}'`)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This doesn't account for imports using double quotes. There's a regex in detectImports that we can modify and reuse here.
  2. I think that we'll have to account for the namespace parameter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use the regex from detectImports to account for both quotes. I don't quite see, though, why we'd need to check the namespace here. My thinking was that if there's an import for the importPath at all, it counts as already imported. I suppose that the file could be using a different namespace/alias, but I'm not particularly worried about supporting that case.

`$another: $mat-pink;`,
].join('\n');

const migratedContent = migrateFileContent(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should invoke the migration through the schematics API like the other tests, rather than calling migrateFileContent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the last comment is addressed.

@@ -207,6 +207,12 @@ function renameSymbols(content: string,
/** Inserts an `@use` statement in a string. */
function insertUseStatement(content: string, importPath: string, importsToIgnore: string[],
namespace: string): string {
// If the content already has the `@use` import, we don't need to add anything.
const alreadyImportedPattern = new RegExp(`@(import|use) +['"]${importPath}['"]`, 'g');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should be just @use not @(import|use).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good catch

… themingApi

In the case where a file has mixed legacy and new theming API usage, the script would
add an extra duplicate `@use` statement.
@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Jun 1, 2021
@mmalerba mmalerba merged commit 0029097 into angular:master Jun 2, 2021
mmalerba pushed a commit that referenced this pull request Jun 2, 2021
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: ng-update Issues related to `ng-update` integration cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants