File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -322,8 +322,14 @@ export class LowerMetadataCache implements RequestsMap {
322
322
return value ;
323
323
} ;
324
324
325
+ // Do not validate or lower metadata in a declaration file. Declaration files are requested
326
+ // when we need to update the version of the metadata to add informatoin that might be missing
327
+ // in the out-of-date version that can be recovered from the .d.ts file.
328
+ const declarationFile = sourceFile . isDeclarationFile ;
329
+
325
330
const metadata = this . collector . getMetadata (
326
- sourceFile , this . strict , sourceFile . isDeclarationFile ? undefined : substituteExpression ) ;
331
+ sourceFile , this . strict && ! declarationFile ,
332
+ declarationFile ? undefined : substituteExpression ) ;
327
333
328
334
return { metadata, requests} ;
329
335
}
Original file line number Diff line number Diff line change @@ -98,6 +98,38 @@ describe('Expression lowering', () => {
98
98
expect ( collected . requests . has ( collected . annotations [ 0 ] . start ) )
99
99
. toBeTruthy ( 'did not find the data field' ) ;
100
100
} ) ;
101
+
102
+ it ( 'should throw a validation execption for invalid files' , ( ) => {
103
+ const cache = new LowerMetadataCache ( { } , /* strict */ true ) ;
104
+ const sourceFile = ts . createSourceFile (
105
+ 'foo.ts' , `
106
+ import {Injectable} from '@angular/core';
107
+
108
+ class SomeLocalClass {}
109
+ @Injectable()
110
+ export class SomeClass {
111
+ constructor(a: SomeLocalClass) {}
112
+ }
113
+ ` ,
114
+ ts . ScriptTarget . Latest , true ) ;
115
+ expect ( ( ) => cache . getMetadata ( sourceFile ) ) . toThrow ( ) ;
116
+ } ) ;
117
+
118
+ it ( 'should not report validation errors on a .d.ts file' , ( ) => {
119
+ const cache = new LowerMetadataCache ( { } , /* strict */ true ) ;
120
+ const dtsFile = ts . createSourceFile (
121
+ 'foo.d.ts' , `
122
+ import {Injectable} from '@angular/core';
123
+
124
+ class SomeLocalClass {}
125
+ @Injectable()
126
+ export class SomeClass {
127
+ constructor(a: SomeLocalClass) {}
128
+ }
129
+ ` ,
130
+ ts . ScriptTarget . Latest , true ) ;
131
+ expect ( ( ) => cache . getMetadata ( dtsFile ) ) . not . toThrow ( ) ;
132
+ } ) ;
101
133
} ) ;
102
134
} ) ;
103
135
You can’t perform that action at this time.
0 commit comments