-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Conversation
@@ -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}'`)) { |
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 doesn't account for imports using double quotes. There's a regex in
detectImports
that we can modify and reuse here. - I think that we'll have to account for the
namespace
parameter.
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.
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( |
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 should invoke the migration through the schematics API like the other tests, rather than calling migrateFileContent
.
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.
Done
cfc90e0
to
e89441b
Compare
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.
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'); |
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.
I think that this should be just @use
not @(import|use)
.
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.
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.
e89441b
to
87a3b76
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
In the case where a file has mixed legacy and new theming API usage, the script would
add an extra duplicate
@use
statement.