fix(@angular/build): show clear error when styleUrl points to a TypeScript file#32881
Open
maruthang wants to merge 1 commit intoangular:mainfrom
Open
fix(@angular/build): show clear error when styleUrl points to a TypeScript file#32881maruthang wants to merge 1 commit intoangular:mainfrom
maruthang wants to merge 1 commit intoangular:mainfrom
Conversation
…cript file Reject TypeScript files (.ts, .tsx, .mts, .cts) used as component resources in the Angular compiler host. Previously this caused confusing downstream errors (e.g., rxjs-related). Now the file is treated as not found, producing a clear 'Could not find stylesheet file' message. Fixes angular#32193
There was a problem hiding this comment.
Code Review
This pull request prevents TypeScript files from being used as component resources by adding a check in the Angular compiler host and a corresponding test case. The reviewer suggested refactoring the extension check logic to use Array.prototype.includes() for better readability and conciseness.
Comment on lines
+280
to
+288
| switch (extension) { | ||
| case '.ts': | ||
| case '.tsx': | ||
| case '.mts': | ||
| case '.cts': | ||
| return true; | ||
| } | ||
|
|
||
| return false; |
There was a problem hiding this comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
What is the current behavior?
When a component's
styleUrlaccidentally points to a.tsfile, the TypeScript content is fed to the CSS parser, producing confusing downstream errors (e.g., rxjs-related "Could not resolve" errors) that don't indicate the actual problem.Issue Number: #32193
What is the new behavior?
TypeScript files (
.ts,.tsx,.mts,.cts) used as component resources are now rejected early inresourceNameToFileName()in the Angular compiler host. The function returnsnull, causing the Angular compiler to emit a clear "Could not find stylesheet file './app.component.ts'" error that directly points to the problem.This follows the existing
hasTemplateExtension()pattern in the same file.Does this PR introduce a breaking change?