From d9ce8a4ab5083212ef980b1f92c726987108cebf Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Tue, 2 Apr 2019 11:52:19 -0700 Subject: [PATCH] feat(ivy): introduce a flag to control template type-checking for Ivy (#29698) Template type-checking is enabled by default in the View Engine compiler. The feature in Ivy is not quite ready for this yet, so this flag will temporarily control whether templates are type-checked in ngtsc. The goal is to remove this flag after rolling out template type-checking in google3 in Ivy mode, and making sure the feature is as compatible with the View Engine implementation as possible. Initially, the default value of the flag will leave checking disabled. PR Close #29698 --- packages/bazel/src/ng_module.bzl | 3 +++ packages/compiler-cli/src/ngtsc/program.ts | 5 +++-- packages/compiler-cli/src/transformers/api.ts | 11 +++++++++++ packages/compiler-cli/test/ngtsc/env.ts | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/bazel/src/ng_module.bzl b/packages/bazel/src/ng_module.bzl index 8dd1061f14..f19307a750 100644 --- a/packages/bazel/src/ng_module.bzl +++ b/packages/bazel/src/ng_module.bzl @@ -299,6 +299,9 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs): "enableSummariesForJit": is_legacy_ngc, "enableIvy": _enable_ivy_value(ctx), "fullTemplateTypeCheck": ctx.attr.type_check, + # TODO(alxhub/arick): template type-checking for Ivy needs to be tested in g3 before it can + # be enabled here. + "ivyTemplateTypeCheck": False, # In Google3 we still want to use the symbol factory re-exports in order to # not break existing apps inside Google. Unlike Bazel, Google3 does not only # enforce strict dependencies of source files, but also for generated files diff --git a/packages/compiler-cli/src/ngtsc/program.ts b/packages/compiler-cli/src/ngtsc/program.ts index 0c526edf8e..a145cc98ba 100644 --- a/packages/compiler-cli/src/ngtsc/program.ts +++ b/packages/compiler-cli/src/ngtsc/program.ts @@ -376,8 +376,9 @@ export class NgtscProgram implements api.Program { } private getTemplateDiagnostics(): ReadonlyArray { - // Skip template type-checking unless explicitly requested. - if (this.options.fullTemplateTypeCheck !== true) { + // Skip template type-checking if it's disabled. + if (this.options.ivyTemplateTypeCheck === false && + this.options.fullTemplateTypeCheck !== true) { return []; } diff --git a/packages/compiler-cli/src/transformers/api.ts b/packages/compiler-cli/src/transformers/api.ts index 6400fc6872..a9550232e2 100644 --- a/packages/compiler-cli/src/transformers/api.ts +++ b/packages/compiler-cli/src/transformers/api.ts @@ -224,6 +224,17 @@ export interface CompilerOptions extends ts.CompilerOptions { * Read more about this here: https://github.com/angular/angular/issues/25644. */ createExternalSymbolFactoryReexports?: boolean; + + /** + * Turn on template type-checking in the Ivy compiler. + * + * This is an internal flag being used to roll out template type-checking in ngtsc. Turning it on + * by default before it's ready might break other users attempting to test the new compiler's + * behavior. + * + * @internal + */ + ivyTemplateTypeCheck?: boolean; } export interface CompilerHost extends ts.CompilerHost { diff --git a/packages/compiler-cli/test/ngtsc/env.ts b/packages/compiler-cli/test/ngtsc/env.ts index 3cdc5d7dc2..52281fb454 100644 --- a/packages/compiler-cli/test/ngtsc/env.ts +++ b/packages/compiler-cli/test/ngtsc/env.ts @@ -76,7 +76,8 @@ export class NgtscTestEnvironment { "typeRoots": ["node_modules/@types"] }, "angularCompilerOptions": { - "enableIvy": true + "enableIvy": true, + "ivyTemplateTypeCheck": false }, "exclude": [ "built"