refactor(ivy): split type
into type
, internalType
and adjacentType
(#33533)
When compiling an Angular decorator (e.g. Directive), @angular/compiler generates an 'expression' to be added as a static definition field on the class, a 'type' which will be added for that field to the .d.ts file, and a statement adjacent to the class that calls `setClassMetadata()`. Previously, the same WrappedNodeExpr of the class' ts.Identifier was used within each of this situations. In the ngtsc case, this is proper. In the ngcc case, if the class being compiled is within an ES5 IIFE, the outer name of the class may have changed. Thus, the class has both an inner and outer name. The outer name should continue to be used elsewhere in the compiler and in 'type'. The 'expression' will live within the IIFE, the `internalType` should be used. The adjacent statement will also live within the IIFE, the `adjacentType` should be used. This commit introduces `ReflectionHost.getInternalNameOfClass()` and `ReflectionHost.getAdjacentNameOfClass()`, which the compiler can use to query for the correct name to use. PR Close #33533
This commit is contained in:
@ -28,6 +28,15 @@ export interface R3DirectiveMetadata {
|
||||
*/
|
||||
type: o.Expression;
|
||||
|
||||
/**
|
||||
* An expression representing a reference to the directive being compiled, intended for use within
|
||||
* a class definition itself.
|
||||
*
|
||||
* This can differ from the outer `type` if the class is being compiled by ngcc and is inside
|
||||
* an IIFE structure that uses a different name internally.
|
||||
*/
|
||||
internalType: o.Expression;
|
||||
|
||||
/**
|
||||
* Number of generic type parameters of the type itself.
|
||||
*/
|
||||
|
@ -45,7 +45,7 @@ function baseDirectiveFields(
|
||||
const selectors = core.parseSelectorToR3Selector(meta.selector);
|
||||
|
||||
// e.g. `type: MyDirective`
|
||||
definitionMap.set('type', meta.type);
|
||||
definitionMap.set('type', meta.internalType);
|
||||
|
||||
// e.g. `selectors: [['', 'someDir', '']]`
|
||||
if (selectors.length > 0) {
|
||||
|
Reference in New Issue
Block a user