From 811cacc80c01ab8af875f14a9e98ea3b7a5a2072 Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Fri, 8 Jan 2021 10:36:46 -0800 Subject: [PATCH] fix(language-service): reinstate overridden compiler option after change (#40364) Currently the language service has to force `compileNonExportedClasses` to `true` to handle inline NgModules in tests, regardless of the value in user's tsconfig.json. However, the override is not reinstated after the compiler option changes (triggered by a change in tsconfig.json). This commit fixes the bug. PR Close #40364 --- .../language-service/ivy/language_service.ts | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/language-service/ivy/language_service.ts b/packages/language-service/ivy/language_service.ts index d6945cc75b..82e3b75d9f 100644 --- a/packages/language-service/ivy/language_service.ts +++ b/packages/language-service/ivy/language_service.ts @@ -32,18 +32,6 @@ export class LanguageService { constructor(project: ts.server.Project, private readonly tsLS: ts.LanguageService) { this.parseConfigHost = new LSParseConfigHost(project.projectService.host); this.options = parseNgCompilerOptions(project, this.parseConfigHost); - - // Projects loaded into the Language Service often include test files which are not part of the - // app's main compilation unit, and these test files often include inline NgModules that declare - // components from the app. These declarations conflict with the main declarations of such - // components in the app's NgModules. This conflict is not normally present during regular - // compilation because the app and the tests are part of separate compilation units. - // - // As a temporary mitigation of this problem, we instruct the compiler to ignore classes which - // are not exported. In many cases, this ensures the test NgModules are ignored by the compiler - // and only the real component declaration is used. - this.options.compileNonExportedClasses = false; - this.strategy = createTypeCheckingProgramStrategy(project); this.adapter = new LanguageServiceAdapter(project); this.compilerFactory = new CompilerFactory(this.adapter, this.strategy, this.options); @@ -213,6 +201,17 @@ function parseNgCompilerOptions( project.setProjectErrors(errors); } + // Projects loaded into the Language Service often include test files which are not part of the + // app's main compilation unit, and these test files often include inline NgModules that declare + // components from the app. These declarations conflict with the main declarations of such + // components in the app's NgModules. This conflict is not normally present during regular + // compilation because the app and the tests are part of separate compilation units. + // + // As a temporary mitigation of this problem, we instruct the compiler to ignore classes which + // are not exported. In many cases, this ensures the test NgModules are ignored by the compiler + // and only the real component declaration is used. + options.compileNonExportedClasses = false; + return options; }