build(compiler-cli): enable full TypeScript strictness (#29436)

This commit enables strict: true in TypeScript builds of
//packages/compiler-cli.

PR Close #29436
This commit is contained in:
Alex Rickabaugh 2019-03-20 17:47:55 -07:00 committed by Matias Niemelä
parent 6cd3743b44
commit dc10355d61
6 changed files with 18 additions and 9 deletions

View File

@ -267,7 +267,7 @@ export class NgtscProgram implements api.Program {
const writeFile: ts.WriteFileCallback = const writeFile: ts.WriteFileCallback =
(fileName: string, data: string, writeByteOrderMark: boolean, (fileName: string, data: string, writeByteOrderMark: boolean,
onError: ((message: string) => void) | undefined, onError: ((message: string) => void) | undefined,
sourceFiles: ReadonlyArray<ts.SourceFile>) => { sourceFiles: ReadonlyArray<ts.SourceFile>| undefined) => {
if (this.closureCompilerEnabled && fileName.endsWith('.js')) { if (this.closureCompilerEnabled && fileName.endsWith('.js')) {
data = nocollapseHack(data); data = nocollapseHack(data);
} }

View File

@ -81,7 +81,7 @@ export class GeneratedShimsHostWrapper implements ts.CompilerHost {
writeFile( writeFile(
fileName: string, data: string, writeByteOrderMark: boolean, fileName: string, data: string, writeByteOrderMark: boolean,
onError: ((message: string) => void)|undefined, onError: ((message: string) => void)|undefined,
sourceFiles: ReadonlyArray<ts.SourceFile>): void { sourceFiles: ReadonlyArray<ts.SourceFile>|undefined): void {
return this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); return this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
} }

View File

@ -75,7 +75,7 @@ export class TypeCheckProgramHost implements ts.CompilerHost {
writeFile( writeFile(
fileName: string, data: string, writeByteOrderMark: boolean, fileName: string, data: string, writeByteOrderMark: boolean,
onError: ((message: string) => void)|undefined, onError: ((message: string) => void)|undefined,
sourceFiles: ReadonlyArray<ts.SourceFile>): void { sourceFiles: ReadonlyArray<ts.SourceFile>|undefined): void {
return this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); return this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
} }

View File

@ -54,7 +54,10 @@ export class InlineResourcesMetadataTransformer implements MetadataTransformer {
isMetadataImportedSymbolReferenceExpression(d.expression) && isMetadataImportedSymbolReferenceExpression(d.expression) &&
d.expression.module === '@angular/core' && d.expression.name === 'Component' && d.expression.module === '@angular/core' && d.expression.name === 'Component' &&
d.arguments) { d.arguments) {
d.arguments = d.arguments.map(this.updateDecoratorMetadata.bind(this, loader)); // Arguments to an @Component that was compiled successfully are always
// MetadataObject(s).
d.arguments = (d.arguments as MetadataObject[])
.map(this.updateDecoratorMetadata.bind(this, loader));
} }
}); });
} }
@ -95,8 +98,8 @@ export function getInlineResourcesTransformFactory(
// Decorator case - before or without decorator downleveling // Decorator case - before or without decorator downleveling
// @Component() // @Component()
const newDecorators = ts.visitNodes(node.decorators, (node: ts.Decorator) => { const newDecorators = ts.visitNodes(node.decorators, (node: ts.Node) => {
if (isComponentDecorator(node, program.getTypeChecker())) { if (ts.isDecorator(node) && isComponentDecorator(node, program.getTypeChecker())) {
return updateDecorator(node, loader); return updateDecorator(node, loader);
} }
return node; return node;
@ -104,9 +107,13 @@ export function getInlineResourcesTransformFactory(
// Annotation case - after decorator downleveling // Annotation case - after decorator downleveling
// static decorators: {type: Function, args?: any[]}[] // static decorators: {type: Function, args?: any[]}[]
const newMembers = ts.visitNodes( const newMembers = ts.visitNodes(node.members, (node: ts.Node) => {
node.members, if (ts.isClassElement(node)) {
(node: ts.ClassElement) => updateAnnotations(node, loader, program.getTypeChecker())); return updateAnnotations(node, loader, program.getTypeChecker());
} else {
return node;
}
});
// Create a new AST subtree with our modifications // Create a new AST subtree with our modifications
return ts.updateClassDeclaration( return ts.updateClassDeclaration(

View File

@ -13,6 +13,7 @@
"paths": { "paths": {
"@angular/compiler": ["../../dist/packages/compiler"] "@angular/compiler": ["../../dist/packages/compiler"]
}, },
"strict": true,
"types": [ "types": [
"node" "node"
], ],

View File

@ -5,6 +5,7 @@
"lib": [ "lib": [
"es2015" "es2015"
], ],
"strict": true,
"types": [ "types": [
"jasmine" "jasmine"
] ]