fix(compiler-cli): do not validate metadata from declaration files (#19324)
Upgrading metadata files causes spurious reports of metadata errors. Fixes #18867
This commit is contained in:
parent
68078fd620
commit
476790290e
|
@ -322,8 +322,14 @@ export class LowerMetadataCache implements RequestsMap {
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Do not validate or lower metadata in a declaration file. Declaration files are requested
|
||||||
|
// when we need to update the version of the metadata to add informatoin that might be missing
|
||||||
|
// in the out-of-date version that can be recovered from the .d.ts file.
|
||||||
|
const declarationFile = sourceFile.isDeclarationFile;
|
||||||
|
|
||||||
const metadata = this.collector.getMetadata(
|
const metadata = this.collector.getMetadata(
|
||||||
sourceFile, this.strict, sourceFile.isDeclarationFile ? undefined : substituteExpression);
|
sourceFile, this.strict && !declarationFile,
|
||||||
|
declarationFile ? undefined : substituteExpression);
|
||||||
|
|
||||||
return {metadata, requests};
|
return {metadata, requests};
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,38 @@ describe('Expression lowering', () => {
|
||||||
expect(collected.requests.has(collected.annotations[0].start))
|
expect(collected.requests.has(collected.annotations[0].start))
|
||||||
.toBeTruthy('did not find the data field');
|
.toBeTruthy('did not find the data field');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw a validation execption for invalid files', () => {
|
||||||
|
const cache = new LowerMetadataCache({}, /* strict */ true);
|
||||||
|
const sourceFile = ts.createSourceFile(
|
||||||
|
'foo.ts', `
|
||||||
|
import {Injectable} from '@angular/core';
|
||||||
|
|
||||||
|
class SomeLocalClass {}
|
||||||
|
@Injectable()
|
||||||
|
export class SomeClass {
|
||||||
|
constructor(a: SomeLocalClass) {}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ts.ScriptTarget.Latest, true);
|
||||||
|
expect(() => cache.getMetadata(sourceFile)).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not report validation errors on a .d.ts file', () => {
|
||||||
|
const cache = new LowerMetadataCache({}, /* strict */ true);
|
||||||
|
const dtsFile = ts.createSourceFile(
|
||||||
|
'foo.d.ts', `
|
||||||
|
import {Injectable} from '@angular/core';
|
||||||
|
|
||||||
|
class SomeLocalClass {}
|
||||||
|
@Injectable()
|
||||||
|
export class SomeClass {
|
||||||
|
constructor(a: SomeLocalClass) {}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ts.ScriptTarget.Latest, true);
|
||||||
|
expect(() => cache.getMetadata(dtsFile)).not.toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue