feat(ivy): able to compile @angular/core with ngtsc (#24677)
@angular/core is unique in that it defines the Angular decorators (@Component, @Directive, etc). Ordinarily ngtsc looks for imports from @angular/core in order to identify these decorators. Clearly within core itself, this strategy doesn't work. Instead, a special constant ITS_JUST_ANGULAR is declared within a known file in @angular/core. If ngtsc sees this constant it knows core is being compiled and can ignore the imports when evaluating decorators. Additionally, when compiling decorators ngtsc will often write an import to @angular/core for needed symbols. However @angular/core cannot import itself. This change creates a module within core to export all the symbols needed to compile it and adds intelligence within ngtsc to write relative imports to that module, instead of absolute imports to @angular/core. PR Close #24677
This commit is contained in:

committed by
Miško Hevery

parent
c57b491778
commit
104d30507a
32
packages/core/src/r3_symbols.ts
Normal file
32
packages/core/src/r3_symbols.ts
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file exists to support compilation of @angular/core in Ivy mode.
|
||||
*
|
||||
* When the Angular compiler processes a compilation unit, it normally writes imports to
|
||||
* @angular/core. When compiling the core package itself this strategy isn't usable. Instead, the
|
||||
* compiler writes imports to this file.
|
||||
*
|
||||
* Only a subset of such imports are supported - core is not allowed to declare components or pipes.
|
||||
* A check in ngtsc's translator.ts validates this condition.
|
||||
*
|
||||
* The below symbols are used for @Injectable and @NgModule compilation.
|
||||
*/
|
||||
|
||||
export {InjectableDef, InjectorDef, defineInjectable, defineInjector} from './di/defs';
|
||||
export {inject} from './di/injector';
|
||||
export {NgModuleDef} from './metadata/ng_module';
|
||||
export {defineNgModule as ɵdefineNgModule} from './render3/definition';
|
||||
|
||||
|
||||
/**
|
||||
* The existence of this constant (in this particular file) informs the Angular compiler that the
|
||||
* current program is actually @angular/core, which needs to be compiled specially.
|
||||
*/
|
||||
export const ITS_JUST_ANGULAR = true;
|
Reference in New Issue
Block a user