From dc10355d61a98092b5f8cabc0993d737ed2e721f Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Wed, 20 Mar 2019 17:47:55 -0700 Subject: [PATCH] build(compiler-cli): enable full TypeScript strictness (#29436) This commit enables strict: true in TypeScript builds of //packages/compiler-cli. PR Close #29436 --- packages/compiler-cli/src/ngtsc/program.ts | 2 +- .../compiler-cli/src/ngtsc/shims/src/host.ts | 2 +- .../src/ngtsc/typecheck/src/host.ts | 2 +- .../src/transformers/inline_resources.ts | 19 +++++++++++++------ packages/compiler-cli/tsconfig-build.json | 1 + packages/compiler-cli/tsconfig.json | 1 + 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/program.ts b/packages/compiler-cli/src/ngtsc/program.ts index 23835421e8..7016bf9b85 100644 --- a/packages/compiler-cli/src/ngtsc/program.ts +++ b/packages/compiler-cli/src/ngtsc/program.ts @@ -267,7 +267,7 @@ export class NgtscProgram implements api.Program { const writeFile: ts.WriteFileCallback = (fileName: string, data: string, writeByteOrderMark: boolean, onError: ((message: string) => void) | undefined, - sourceFiles: ReadonlyArray) => { + sourceFiles: ReadonlyArray| undefined) => { if (this.closureCompilerEnabled && fileName.endsWith('.js')) { data = nocollapseHack(data); } diff --git a/packages/compiler-cli/src/ngtsc/shims/src/host.ts b/packages/compiler-cli/src/ngtsc/shims/src/host.ts index 2dec954274..029e763f0a 100644 --- a/packages/compiler-cli/src/ngtsc/shims/src/host.ts +++ b/packages/compiler-cli/src/ngtsc/shims/src/host.ts @@ -81,7 +81,7 @@ export class GeneratedShimsHostWrapper implements ts.CompilerHost { writeFile( fileName: string, data: string, writeByteOrderMark: boolean, onError: ((message: string) => void)|undefined, - sourceFiles: ReadonlyArray): void { + sourceFiles: ReadonlyArray|undefined): void { return this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); } diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/host.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/host.ts index f35223e4dd..dad3c0156e 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/host.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/host.ts @@ -75,7 +75,7 @@ export class TypeCheckProgramHost implements ts.CompilerHost { writeFile( fileName: string, data: string, writeByteOrderMark: boolean, onError: ((message: string) => void)|undefined, - sourceFiles: ReadonlyArray): void { + sourceFiles: ReadonlyArray|undefined): void { return this.delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles); } diff --git a/packages/compiler-cli/src/transformers/inline_resources.ts b/packages/compiler-cli/src/transformers/inline_resources.ts index 9ac282814c..25e4d6108f 100644 --- a/packages/compiler-cli/src/transformers/inline_resources.ts +++ b/packages/compiler-cli/src/transformers/inline_resources.ts @@ -54,7 +54,10 @@ export class InlineResourcesMetadataTransformer implements MetadataTransformer { isMetadataImportedSymbolReferenceExpression(d.expression) && d.expression.module === '@angular/core' && d.expression.name === 'Component' && 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 // @Component() - const newDecorators = ts.visitNodes(node.decorators, (node: ts.Decorator) => { - if (isComponentDecorator(node, program.getTypeChecker())) { + const newDecorators = ts.visitNodes(node.decorators, (node: ts.Node) => { + if (ts.isDecorator(node) && isComponentDecorator(node, program.getTypeChecker())) { return updateDecorator(node, loader); } return node; @@ -104,9 +107,13 @@ export function getInlineResourcesTransformFactory( // Annotation case - after decorator downleveling // static decorators: {type: Function, args?: any[]}[] - const newMembers = ts.visitNodes( - node.members, - (node: ts.ClassElement) => updateAnnotations(node, loader, program.getTypeChecker())); + const newMembers = ts.visitNodes(node.members, (node: ts.Node) => { + if (ts.isClassElement(node)) { + return updateAnnotations(node, loader, program.getTypeChecker()); + } else { + return node; + } + }); // Create a new AST subtree with our modifications return ts.updateClassDeclaration( diff --git a/packages/compiler-cli/tsconfig-build.json b/packages/compiler-cli/tsconfig-build.json index ae659b8dfc..22956fc745 100644 --- a/packages/compiler-cli/tsconfig-build.json +++ b/packages/compiler-cli/tsconfig-build.json @@ -13,6 +13,7 @@ "paths": { "@angular/compiler": ["../../dist/packages/compiler"] }, + "strict": true, "types": [ "node" ], diff --git a/packages/compiler-cli/tsconfig.json b/packages/compiler-cli/tsconfig.json index 1c2a642024..953e52219f 100644 --- a/packages/compiler-cli/tsconfig.json +++ b/packages/compiler-cli/tsconfig.json @@ -5,6 +5,7 @@ "lib": [ "es2015" ], + "strict": true, "types": [ "jasmine" ]