Skip to content

Commit 811cacc

Browse files
kyliauatscott
authored andcommitted
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
1 parent b36bece commit 811cacc

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

packages/language-service/ivy/language_service.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ export class LanguageService {
3232
constructor(project: ts.server.Project, private readonly tsLS: ts.LanguageService) {
3333
this.parseConfigHost = new LSParseConfigHost(project.projectService.host);
3434
this.options = parseNgCompilerOptions(project, this.parseConfigHost);
35-
36-
// Projects loaded into the Language Service often include test files which are not part of the
37-
// app's main compilation unit, and these test files often include inline NgModules that declare
38-
// components from the app. These declarations conflict with the main declarations of such
39-
// components in the app's NgModules. This conflict is not normally present during regular
40-
// compilation because the app and the tests are part of separate compilation units.
41-
//
42-
// As a temporary mitigation of this problem, we instruct the compiler to ignore classes which
43-
// are not exported. In many cases, this ensures the test NgModules are ignored by the compiler
44-
// and only the real component declaration is used.
45-
this.options.compileNonExportedClasses = false;
46-
4735
this.strategy = createTypeCheckingProgramStrategy(project);
4836
this.adapter = new LanguageServiceAdapter(project);
4937
this.compilerFactory = new CompilerFactory(this.adapter, this.strategy, this.options);
@@ -213,6 +201,17 @@ function parseNgCompilerOptions(
213201
project.setProjectErrors(errors);
214202
}
215203

204+
// Projects loaded into the Language Service often include test files which are not part of the
205+
// app's main compilation unit, and these test files often include inline NgModules that declare
206+
// components from the app. These declarations conflict with the main declarations of such
207+
// components in the app's NgModules. This conflict is not normally present during regular
208+
// compilation because the app and the tests are part of separate compilation units.
209+
//
210+
// As a temporary mitigation of this problem, we instruct the compiler to ignore classes which
211+
// are not exported. In many cases, this ensures the test NgModules are ignored by the compiler
212+
// and only the real component declaration is used.
213+
options.compileNonExportedClasses = false;
214+
216215
return options;
217216
}
218217

0 commit comments

Comments
 (0)