MCPcopy Create free account
hub / github.com/angular/angular / parseNgCompilerOptions

Function parseNgCompilerOptions

packages/language-service/src/language_service.ts:965–1022  ·  view source on GitHub ↗
(
  project: ts.server.Project,
  host: ConfigurationHost,
  config: LanguageServiceConfig,
)

Source from the content-addressed store, hash-verified

963}
964
965function parseNgCompilerOptions(
966 project: ts.server.Project,
967 host: ConfigurationHost,
968 config: LanguageServiceConfig,
969): CompilerOptions {
970 if (!(project instanceof ts.server.ConfiguredProject)) {
971 return {};
972 }
973 const {options, errors} = readConfiguration(
974 project.getConfigFilePath(),
975 /* existingOptions */ undefined,
976 host,
977 );
978 if (errors.length > 0) {
979 project.setProjectErrors(errors);
980 }
981
982 // Projects loaded into the Language Service often include test files which are not part of the
983 // app's main compilation unit, and these test files often include inline NgModules that declare
984 // components from the app. These declarations conflict with the main declarations of such
985 // components in the app's NgModules. This conflict is not normally present during regular
986 // compilation because the app and the tests are part of separate compilation units.
987 //
988 // As a temporary mitigation of this problem, we instruct the compiler to ignore classes which
989 // are not exported. In many cases, this ensures the test NgModules are ignored by the compiler
990 // and only the real component declaration is used.
991 options.compileNonExportedClasses = false;
992
993 // If `forceStrictTemplates` is true, always enable `strictTemplates`
994 // regardless of its value in tsconfig.json.
995 if (config['forceStrictTemplates'] === true) {
996 options.strictTemplates = true;
997 }
998
999 options['_angularCoreVersion'] = config['angularCoreVersion'];
1000
1001 if (project.getCurrentDirectory()) {
1002 // Attempt to resolve the version of @angular/core that is installed in the project.
1003 // This is useful for monorepos where different projects may use different versions of Angular.
1004 const detectedVersion = detectAngularCoreVersion(project, host);
1005 if (detectedVersion !== null) {
1006 options['_angularCoreVersion'] = detectedVersion;
1007 }
1008 }
1009
1010 // Prior to v22, strictTemplates was set to false by default
1011 if (options.strictTemplates === undefined && typeof options['_angularCoreVersion'] === 'string') {
1012 const version = options['_angularCoreVersion'];
1013 if (version !== `0.0.0-${'PLACEHOLDER'}`) {
1014 const major = parseInt(version.split('.')[0], 10);
1015 if (!Number.isNaN(major) && major < 22) {
1016 options.strictTemplates = false;
1017 }
1018 }
1019 }
1020
1021 return options;
1022}

Callers 2

constructorMethod · 0.85
watchConfigFileMethod · 0.85

Calls 3

readConfigurationFunction · 0.90
detectAngularCoreVersionFunction · 0.85
getCurrentDirectoryMethod · 0.45

Tested by

no test coverage detected