@@ -38,7 +38,7 @@ import {
38
38
*/
39
39
export interface StyleUrlMeta {
40
40
url : string ;
41
- nodeForError : ts . Node ;
41
+ expression : ts . Expression ;
42
42
source :
43
43
| ResourceTypeForDiagnostics . StylesheetFromTemplate
44
44
| ResourceTypeForDiagnostics . StylesheetFromDecorator ;
@@ -123,7 +123,9 @@ export interface ExternalTemplateDeclaration extends CommonTemplateDeclaration {
123
123
export type TemplateDeclaration = InlineTemplateDeclaration | ExternalTemplateDeclaration ;
124
124
125
125
/** Determines the node to use for debugging purposes for the given TemplateDeclaration. */
126
- export function getTemplateDeclarationNodeForError ( declaration : TemplateDeclaration ) : ts . Node {
126
+ export function getTemplateDeclarationNodeForError (
127
+ declaration : TemplateDeclaration ,
128
+ ) : ts . Expression {
127
129
return declaration . isInline ? declaration . expression : declaration . templateUrlExpression ;
128
130
}
129
131
@@ -629,7 +631,7 @@ export function extractComponentStyleUrls(
629
631
{
630
632
url : styleUrl ,
631
633
source : ResourceTypeForDiagnostics . StylesheetFromDecorator ,
632
- nodeForError : styleUrlExpr ,
634
+ expression : styleUrlExpr ,
633
635
} ,
634
636
] ;
635
637
}
@@ -657,7 +659,7 @@ function extractStyleUrlsFromExpression(
657
659
styleUrls . push ( {
658
660
url : styleUrl ,
659
661
source : ResourceTypeForDiagnostics . StylesheetFromDecorator ,
660
- nodeForError : styleUrlExpr ,
662
+ expression : styleUrlExpr ,
661
663
} ) ;
662
664
}
663
665
}
@@ -675,44 +677,20 @@ function extractStyleUrlsFromExpression(
675
677
styleUrls . push ( {
676
678
url : styleUrl ,
677
679
source : ResourceTypeForDiagnostics . StylesheetFromDecorator ,
678
- nodeForError : styleUrlsExpr ,
680
+ expression : styleUrlsExpr ,
679
681
} ) ;
680
682
}
681
683
}
682
684
683
685
return styleUrls ;
684
686
}
685
687
686
- export function extractStyleResources (
687
- resourceLoader : ResourceLoader ,
688
- component : Map < string , ts . Expression > ,
689
- containingFile : string ,
690
- ) : ReadonlySet < Resource > {
688
+ export function extractInlineStyleResources ( component : Map < string , ts . Expression > ) : Set < Resource > {
691
689
const styles = new Set < Resource > ( ) ;
692
690
function stringLiteralElements ( array : ts . ArrayLiteralExpression ) : ts . StringLiteralLike [ ] {
693
691
return array . elements . filter ( ( e ) : e is ts . StringLiteralLike => ts . isStringLiteralLike ( e ) ) ;
694
692
}
695
693
696
- // If styleUrls is a literal array, process each resource url individually and register ones that
697
- // are string literals. If `styleUrl` is specified, register a single stylesheet. Note that
698
- // `styleUrl` and `styleUrls` are mutually-exclusive. This is validated in
699
- // `extractComponentStyleUrls`.
700
- const styleUrlExpr = component . get ( 'styleUrl' ) ;
701
- const styleUrlsExpr = component . get ( 'styleUrls' ) ;
702
- if ( styleUrlsExpr !== undefined && ts . isArrayLiteralExpression ( styleUrlsExpr ) ) {
703
- for ( const expression of stringLiteralElements ( styleUrlsExpr ) ) {
704
- const resource = stringLiteralUrlToResource ( resourceLoader , expression , containingFile ) ;
705
- if ( resource !== null ) {
706
- styles . add ( resource ) ;
707
- }
708
- }
709
- } else if ( styleUrlExpr !== undefined && ts . isStringLiteralLike ( styleUrlExpr ) ) {
710
- const resource = stringLiteralUrlToResource ( resourceLoader , styleUrlExpr , containingFile ) ;
711
- if ( resource !== null ) {
712
- styles . add ( resource ) ;
713
- }
714
- }
715
-
716
694
const stylesExpr = component . get ( 'styles' ) ;
717
695
if ( stylesExpr !== undefined ) {
718
696
if ( ts . isArrayLiteralExpression ( stylesExpr ) ) {
@@ -727,31 +705,15 @@ export function extractStyleResources(
727
705
return styles ;
728
706
}
729
707
730
- function stringLiteralUrlToResource (
731
- resourceLoader : ResourceLoader ,
732
- expression : ts . StringLiteralLike ,
733
- containingFile : string ,
734
- ) : Resource | null {
735
- try {
736
- const resourceUrl = resourceLoader . resolve ( expression . text , containingFile ) ;
737
- return { path : absoluteFrom ( resourceUrl ) , expression} ;
738
- } catch {
739
- // Errors in style resource extraction do not need to be handled here. We will produce
740
- // diagnostics for each one that fails in the analysis, after we evaluate the `styleUrls`
741
- // expression to determine _all_ style resources, not just the string literals.
742
- return null ;
743
- }
744
- }
745
-
746
708
export function _extractTemplateStyleUrls ( template : ParsedTemplateWithSource ) : StyleUrlMeta [ ] {
747
709
if ( template . styleUrls === null ) {
748
710
return [ ] ;
749
711
}
750
712
751
- const nodeForError = getTemplateDeclarationNodeForError ( template . declaration ) ;
713
+ const expression = getTemplateDeclarationNodeForError ( template . declaration ) ;
752
714
return template . styleUrls . map ( ( url ) => ( {
753
715
url,
754
716
source : ResourceTypeForDiagnostics . StylesheetFromTemplate ,
755
- nodeForError ,
717
+ expression ,
756
718
} ) ) ;
757
719
}
0 commit comments