2018-10-24 19:02:25 -04:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2018-10-24 19:02:25 -04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-03-21 13:31:20 -04:00
|
|
|
import {CompilerFacade, CoreEnvironment, ExportedCompilerFacade, OpaqueValue, R3ComponentMetadataFacade, R3DeclareComponentFacade, R3DeclareDependencyMetadataFacade, R3DeclareDirectiveFacade, R3DeclareFactoryFacade, R3DeclareInjectableFacade, R3DeclareInjectorFacade, R3DeclareNgModuleFacade, R3DeclarePipeFacade, R3DeclareQueryMetadataFacade, R3DeclareUsedDirectiveFacade, R3DependencyMetadataFacade, R3DirectiveMetadataFacade, R3FactoryDefMetadataFacade, R3InjectableMetadataFacade, R3InjectorMetadataFacade, R3NgModuleMetadataFacade, R3PipeMetadataFacade, R3QueryMetadataFacade, StringMap, StringMapWithRename} from './compiler_facade_interface';
|
2018-10-24 19:02:25 -04:00
|
|
|
import {ConstantPool} from './constant_pool';
|
2021-03-21 13:31:20 -04:00
|
|
|
import {ChangeDetectionStrategy, HostBinding, HostListener, Input, Output, ViewEncapsulation} from './core';
|
|
|
|
import {compileInjectable, createR3ProviderExpression, R3ProviderExpression} from './injectable_compiler_2';
|
2018-11-29 19:21:16 -05:00
|
|
|
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from './ml_parser/interpolation_config';
|
2021-03-23 11:14:53 -04:00
|
|
|
import {DeclareVarStmt, Expression, literal, LiteralExpr, Statement, StmtModifier, WrappedNodeExpr} from './output/output_ast';
|
2019-02-08 17:10:19 -05:00
|
|
|
import {JitEvaluator} from './output/output_jit';
|
2019-01-24 20:25:46 -05:00
|
|
|
import {ParseError, ParseSourceSpan, r3JitTypeSourceSpan} from './parse_util';
|
2021-03-25 17:25:03 -04:00
|
|
|
import {compileFactoryFunction, FactoryTarget, R3DependencyMetadata} from './render3/r3_factory';
|
2021-03-04 15:55:25 -05:00
|
|
|
import {compileInjector, R3InjectorMetadata} from './render3/r3_injector_compiler';
|
2019-02-08 17:10:19 -05:00
|
|
|
import {R3JitReflector} from './render3/r3_jit';
|
2021-03-04 15:55:25 -05:00
|
|
|
import {compileNgModule, compileNgModuleDeclarationExpression, R3NgModuleMetadata} from './render3/r3_module_compiler';
|
2020-04-08 13:14:18 -04:00
|
|
|
import {compilePipeFromMetadata, R3PipeMetadata} from './render3/r3_pipe_compiler';
|
2021-03-23 11:14:53 -04:00
|
|
|
import {getSafePropertyAccessString, wrapReference} from './render3/util';
|
2020-12-15 06:47:35 -05:00
|
|
|
import {DeclarationListEmitMode, R3ComponentMetadata, R3DirectiveMetadata, R3HostMetadata, R3QueryMetadata, R3UsedDirectiveMetadata} from './render3/view/api';
|
2020-04-08 13:14:18 -04:00
|
|
|
import {compileComponentFromMetadata, compileDirectiveFromMetadata, ParsedHostBindings, parseHostBindings, verifyHostBindings} from './render3/view/compiler';
|
2018-10-24 19:02:25 -04:00
|
|
|
import {makeBindingParser, parseTemplate} from './render3/view/template';
|
2019-03-03 12:19:27 -05:00
|
|
|
import {ResourceLoader} from './resource_loader';
|
2018-11-22 09:38:28 -05:00
|
|
|
import {DomElementSchemaRegistry} from './schema/dom_element_schema_registry';
|
2018-10-24 19:02:25 -04:00
|
|
|
|
|
|
|
export class CompilerFacadeImpl implements CompilerFacade {
|
2021-03-25 17:25:03 -04:00
|
|
|
FactoryTarget = FactoryTarget as any;
|
2019-03-03 12:19:27 -05:00
|
|
|
ResourceLoader = ResourceLoader;
|
2018-11-22 09:38:28 -05:00
|
|
|
private elementSchemaRegistry = new DomElementSchemaRegistry();
|
2019-02-08 17:10:20 -05:00
|
|
|
|
|
|
|
constructor(private jitEvaluator = new JitEvaluator()) {}
|
2018-10-24 19:02:25 -04:00
|
|
|
|
|
|
|
compilePipe(angularCoreEnv: CoreEnvironment, sourceMapUrl: string, facade: R3PipeMetadataFacade):
|
|
|
|
any {
|
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
2019-11-01 12:55:09 -04:00
|
|
|
const metadata: R3PipeMetadata = {
|
2018-10-24 19:02:25 -04:00
|
|
|
name: facade.name,
|
2019-12-18 09:03:05 -05:00
|
|
|
type: wrapReference(facade.type),
|
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
2019-11-01 12:55:09 -04:00
|
|
|
internalType: new WrappedNodeExpr(facade.type),
|
2021-03-23 11:14:53 -04:00
|
|
|
typeArgumentCount: 0,
|
|
|
|
deps: null,
|
2018-10-24 19:02:25 -04:00
|
|
|
pipeName: facade.pipeName,
|
|
|
|
pure: facade.pure,
|
2019-08-12 02:26:20 -04:00
|
|
|
};
|
|
|
|
const res = compilePipeFromMetadata(metadata);
|
|
|
|
return this.jitExpression(res.expression, angularCoreEnv, sourceMapUrl, []);
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
|
2021-02-11 09:42:10 -05:00
|
|
|
compilePipeDeclaration(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
declaration: R3DeclarePipeFacade): any {
|
|
|
|
const meta = convertDeclarePipeFacadeToMetadata(declaration);
|
2021-02-18 17:20:45 -05:00
|
|
|
const res = compilePipeFromMetadata(meta);
|
|
|
|
return this.jitExpression(res.expression, angularCoreEnv, sourceMapUrl, []);
|
2021-02-11 09:42:10 -05:00
|
|
|
}
|
|
|
|
|
2018-10-24 19:02:25 -04:00
|
|
|
compileInjectable(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
facade: R3InjectableMetadataFacade): any {
|
2021-03-21 13:31:20 -04:00
|
|
|
const {expression, statements} = compileInjectable(
|
|
|
|
{
|
|
|
|
name: facade.name,
|
|
|
|
type: wrapReference(facade.type),
|
|
|
|
internalType: new WrappedNodeExpr(facade.type),
|
|
|
|
typeArgumentCount: facade.typeArgumentCount,
|
|
|
|
providedIn: computeProvidedIn(facade.providedIn),
|
|
|
|
useClass: convertToProviderExpression(facade, USE_CLASS),
|
|
|
|
useFactory: wrapExpression(facade, USE_FACTORY),
|
|
|
|
useValue: convertToProviderExpression(facade, USE_VALUE),
|
|
|
|
useExisting: convertToProviderExpression(facade, USE_EXISTING),
|
|
|
|
deps: facade.deps?.map(convertR3DependencyMetadata),
|
|
|
|
},
|
|
|
|
/* resolveForwardRefs */ true);
|
|
|
|
|
|
|
|
return this.jitExpression(expression, angularCoreEnv, sourceMapUrl, statements);
|
|
|
|
}
|
|
|
|
|
|
|
|
compileInjectableDeclaration(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
facade: R3DeclareInjectableFacade): any {
|
|
|
|
const {expression, statements} = compileInjectable(
|
|
|
|
{
|
|
|
|
name: facade.type.name,
|
|
|
|
type: wrapReference(facade.type),
|
|
|
|
internalType: new WrappedNodeExpr(facade.type),
|
|
|
|
typeArgumentCount: 0,
|
|
|
|
providedIn: computeProvidedIn(facade.providedIn),
|
|
|
|
useClass: convertToProviderExpression(facade, USE_CLASS),
|
|
|
|
useFactory: wrapExpression(facade, USE_FACTORY),
|
|
|
|
useValue: convertToProviderExpression(facade, USE_VALUE),
|
|
|
|
useExisting: convertToProviderExpression(facade, USE_EXISTING),
|
|
|
|
deps: facade.deps?.map(convertR3DeclareDependencyMetadata),
|
|
|
|
},
|
|
|
|
/* resolveForwardRefs */ true);
|
2018-10-24 19:02:25 -04:00
|
|
|
|
2019-02-08 17:10:19 -05:00
|
|
|
return this.jitExpression(expression, angularCoreEnv, sourceMapUrl, statements);
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
compileInjector(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
facade: R3InjectorMetadataFacade): any {
|
|
|
|
const meta: R3InjectorMetadata = {
|
|
|
|
name: facade.name,
|
2019-12-18 09:03:05 -05:00
|
|
|
type: wrapReference(facade.type),
|
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
2019-11-01 12:55:09 -04:00
|
|
|
internalType: new WrappedNodeExpr(facade.type),
|
2018-10-24 19:02:25 -04:00
|
|
|
providers: new WrappedNodeExpr(facade.providers),
|
2019-03-30 08:09:45 -04:00
|
|
|
imports: facade.imports.map(i => new WrappedNodeExpr(i)),
|
2018-10-24 19:02:25 -04:00
|
|
|
};
|
refactor(compiler): move factory out of injector definition (#41022)
Previously, injector definitions contained a `factory` property that
was used to create a new instance of the associated NgModule class.
Now this factory has been moved to its own `ɵfac` static property on the
NgModule class itself. This is inline with how directives, components and
pipes are created.
There is a small size increase to bundle sizes for each NgModule class,
because the `ɵfac` takes up a bit more space:
Before:
```js
let a = (() => {
class n {}
return n.\u0275mod = c.Cb({type: n}),
n.\u0275inj = c.Bb({factory: function(t) { return new (t || n) }, imports: [[e.a.forChild(s)], e.a]}),
n
})(),
```
After:
```js
let a = (() => {
class n {}
return n.\u0275fac = function(t) { return new (t || n) },
n.\u0275mod = c.Cb({type: n}),
n.\u0275inj = c.Bb({imports: [[r.a.forChild(s)], r.a]}),
n
})(),
```
In other words `n.\u0275fac = ` is longer than `factory: ` (by 5 characters)
and only because the tooling insists on encoding `ɵ` as `\u0275`.
This can be mitigated in a future PR by only generating the `ɵfac` property
if it is actually needed.
PR Close #41022
2021-02-26 14:21:29 -05:00
|
|
|
const res = compileInjector(meta);
|
|
|
|
return this.jitExpression(res.expression, angularCoreEnv, sourceMapUrl, []);
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
|
2021-03-04 15:55:25 -05:00
|
|
|
compileInjectorDeclaration(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
declaration: R3DeclareInjectorFacade): any {
|
|
|
|
const meta = convertDeclareInjectorFacadeToMetadata(declaration);
|
|
|
|
const res = compileInjector(meta);
|
|
|
|
return this.jitExpression(res.expression, angularCoreEnv, sourceMapUrl, []);
|
|
|
|
}
|
|
|
|
|
2018-10-24 19:02:25 -04:00
|
|
|
compileNgModule(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
facade: R3NgModuleMetadataFacade): any {
|
|
|
|
const meta: R3NgModuleMetadata = {
|
2019-12-18 09:03:05 -05:00
|
|
|
type: wrapReference(facade.type),
|
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
2019-11-01 12:55:09 -04:00
|
|
|
internalType: new WrappedNodeExpr(facade.type),
|
|
|
|
adjacentType: new WrappedNodeExpr(facade.type),
|
2018-10-24 19:02:25 -04:00
|
|
|
bootstrap: facade.bootstrap.map(wrapReference),
|
|
|
|
declarations: facade.declarations.map(wrapReference),
|
|
|
|
imports: facade.imports.map(wrapReference),
|
|
|
|
exports: facade.exports.map(wrapReference),
|
|
|
|
emitInline: true,
|
2019-03-08 20:57:34 -05:00
|
|
|
containsForwardDecls: false,
|
2019-02-11 18:03:04 -05:00
|
|
|
schemas: facade.schemas ? facade.schemas.map(wrapReference) : null,
|
2019-05-07 22:57:55 -04:00
|
|
|
id: facade.id ? new WrappedNodeExpr(facade.id) : null,
|
2018-10-24 19:02:25 -04:00
|
|
|
};
|
|
|
|
const res = compileNgModule(meta);
|
2019-02-08 17:10:19 -05:00
|
|
|
return this.jitExpression(res.expression, angularCoreEnv, sourceMapUrl, []);
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
|
2021-03-04 15:55:25 -05:00
|
|
|
compileNgModuleDeclaration(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
declaration: R3DeclareNgModuleFacade): any {
|
|
|
|
const expression = compileNgModuleDeclarationExpression(declaration);
|
|
|
|
return this.jitExpression(expression, angularCoreEnv, sourceMapUrl, []);
|
|
|
|
}
|
|
|
|
|
2018-10-24 19:02:25 -04:00
|
|
|
compileDirective(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
facade: R3DirectiveMetadataFacade): any {
|
2020-12-13 14:25:20 -05:00
|
|
|
const meta: R3DirectiveMetadata = convertDirectiveFacadeToMetadata(facade);
|
|
|
|
return this.compileDirectiveFromMeta(angularCoreEnv, sourceMapUrl, meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
compileDirectiveDeclaration(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
declaration: R3DeclareDirectiveFacade): any {
|
|
|
|
const typeSourceSpan =
|
|
|
|
this.createParseSourceSpan('Directive', declaration.type.name, sourceMapUrl);
|
|
|
|
const meta = convertDeclareDirectiveFacadeToMetadata(declaration, typeSourceSpan);
|
|
|
|
return this.compileDirectiveFromMeta(angularCoreEnv, sourceMapUrl, meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
private compileDirectiveFromMeta(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string, meta: R3DirectiveMetadata): any {
|
2018-10-24 19:02:25 -04:00
|
|
|
const constantPool = new ConstantPool();
|
|
|
|
const bindingParser = makeBindingParser();
|
|
|
|
const res = compileDirectiveFromMetadata(meta, constantPool, bindingParser);
|
2019-08-12 02:26:20 -04:00
|
|
|
return this.jitExpression(
|
|
|
|
res.expression, angularCoreEnv, sourceMapUrl, constantPool.statements);
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
compileComponent(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
facade: R3ComponentMetadataFacade): any {
|
|
|
|
// Parse the template and check for errors.
|
2020-12-15 06:47:35 -05:00
|
|
|
const {template, interpolation} = parseJitTemplate(
|
|
|
|
facade.template, facade.name, sourceMapUrl, facade.preserveWhitespaces,
|
|
|
|
facade.interpolation);
|
2018-10-24 19:02:25 -04:00
|
|
|
|
|
|
|
// Compile the component metadata, including template, into an expression.
|
2020-12-15 06:47:35 -05:00
|
|
|
const meta: R3ComponentMetadata = {
|
2019-08-12 02:26:20 -04:00
|
|
|
...facade as R3ComponentMetadataFacadeNoPropAndWhitespace,
|
|
|
|
...convertDirectiveFacadeToMetadata(facade),
|
|
|
|
selector: facade.selector || this.elementSchemaRegistry.getDefaultComponentElementName(),
|
|
|
|
template,
|
2020-12-15 06:47:35 -05:00
|
|
|
declarationListEmitMode: DeclarationListEmitMode.Direct,
|
2019-11-23 18:36:00 -05:00
|
|
|
styles: [...facade.styles, ...template.styles],
|
2019-08-12 02:26:20 -04:00
|
|
|
encapsulation: facade.encapsulation as any,
|
2020-12-15 06:47:35 -05:00
|
|
|
interpolation,
|
2019-08-12 02:26:20 -04:00
|
|
|
changeDetection: facade.changeDetection,
|
|
|
|
animations: facade.animations != null ? new WrappedNodeExpr(facade.animations) : null,
|
|
|
|
viewProviders: facade.viewProviders != null ? new WrappedNodeExpr(facade.viewProviders) :
|
|
|
|
null,
|
|
|
|
relativeContextFilePath: '',
|
|
|
|
i18nUseExternalIds: true,
|
|
|
|
};
|
|
|
|
const jitExpressionSourceMap = `ng:///${facade.name}.js`;
|
2020-12-15 06:47:35 -05:00
|
|
|
return this.compileComponentFromMeta(angularCoreEnv, jitExpressionSourceMap, meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
compileComponentDeclaration(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string,
|
|
|
|
declaration: R3DeclareComponentFacade): any {
|
|
|
|
const typeSourceSpan =
|
|
|
|
this.createParseSourceSpan('Component', declaration.type.name, sourceMapUrl);
|
|
|
|
const meta = convertDeclareComponentFacadeToMetadata(declaration, typeSourceSpan, sourceMapUrl);
|
|
|
|
return this.compileComponentFromMeta(angularCoreEnv, sourceMapUrl, meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
private compileComponentFromMeta(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string, meta: R3ComponentMetadata): any {
|
|
|
|
const constantPool = new ConstantPool();
|
|
|
|
const bindingParser = makeBindingParser(meta.interpolation);
|
|
|
|
const res = compileComponentFromMetadata(meta, constantPool, bindingParser);
|
2019-08-12 02:26:20 -04:00
|
|
|
return this.jitExpression(
|
2020-12-15 06:47:35 -05:00
|
|
|
res.expression, angularCoreEnv, sourceMapUrl, constantPool.statements);
|
2019-08-12 02:26:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
compileFactory(
|
2019-09-01 06:26:04 -04:00
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string, meta: R3FactoryDefMetadataFacade) {
|
2019-10-03 15:54:49 -04:00
|
|
|
const factoryRes = compileFactoryFunction({
|
2019-08-12 02:26:20 -04:00
|
|
|
name: meta.name,
|
2019-12-18 09:03:05 -05:00
|
|
|
type: wrapReference(meta.type),
|
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
2019-11-01 12:55:09 -04:00
|
|
|
internalType: new WrappedNodeExpr(meta.type),
|
2019-08-12 02:26:20 -04:00
|
|
|
typeArgumentCount: meta.typeArgumentCount,
|
2019-09-01 06:26:04 -04:00
|
|
|
deps: convertR3DependencyMetadataArray(meta.deps),
|
2019-10-03 15:54:49 -04:00
|
|
|
target: meta.target,
|
2019-08-12 02:26:20 -04:00
|
|
|
});
|
2019-02-08 17:10:19 -05:00
|
|
|
return this.jitExpression(
|
2021-03-10 10:24:11 -05:00
|
|
|
factoryRes.expression, angularCoreEnv, sourceMapUrl, factoryRes.statements);
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
2019-01-24 20:25:46 -05:00
|
|
|
|
2021-03-14 17:03:59 -04:00
|
|
|
compileFactoryDeclaration(
|
|
|
|
angularCoreEnv: CoreEnvironment, sourceMapUrl: string, meta: R3DeclareFactoryFacade) {
|
|
|
|
const factoryRes = compileFactoryFunction({
|
|
|
|
name: meta.type.name,
|
|
|
|
type: wrapReference(meta.type),
|
|
|
|
internalType: new WrappedNodeExpr(meta.type),
|
|
|
|
typeArgumentCount: 0,
|
2021-03-23 11:14:53 -04:00
|
|
|
deps: meta.deps && meta.deps.map(convertR3DeclareDependencyMetadata),
|
2021-03-14 17:03:59 -04:00
|
|
|
target: meta.target,
|
|
|
|
});
|
|
|
|
return this.jitExpression(
|
|
|
|
factoryRes.expression, angularCoreEnv, sourceMapUrl, factoryRes.statements);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-24 20:25:46 -05:00
|
|
|
createParseSourceSpan(kind: string, typeName: string, sourceUrl: string): ParseSourceSpan {
|
|
|
|
return r3JitTypeSourceSpan(kind, typeName, sourceUrl);
|
|
|
|
}
|
2019-02-08 17:10:19 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* JIT compiles an expression and returns the result of executing that expression.
|
|
|
|
*
|
|
|
|
* @param def the definition which will be compiled and executed to get the value to patch
|
|
|
|
* @param context an object map of @angular/core symbol names to symbols which will be available
|
|
|
|
* in the context of the compiled expression
|
|
|
|
* @param sourceUrl a URL to use for the source map of the compiled expression
|
|
|
|
* @param preStatements a collection of statements that should be evaluated before the expression.
|
|
|
|
*/
|
|
|
|
private jitExpression(
|
|
|
|
def: Expression, context: {[key: string]: any}, sourceUrl: string,
|
|
|
|
preStatements: Statement[]): any {
|
|
|
|
// The ConstantPool may contain Statements which declare variables used in the final expression.
|
|
|
|
// Therefore, its statements need to precede the actual JIT operation. The final statement is a
|
|
|
|
// declaration of $def which is set to the expression being compiled.
|
|
|
|
const statements: Statement[] = [
|
|
|
|
...preStatements,
|
|
|
|
new DeclareVarStmt('$def', def, undefined, [StmtModifier.Exported]),
|
|
|
|
];
|
|
|
|
|
|
|
|
const res = this.jitEvaluator.evaluateStatements(
|
|
|
|
sourceUrl, statements, new R3JitReflector(context), /* enableSourceMaps */ true);
|
|
|
|
return res['$def'];
|
|
|
|
}
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This seems to be needed to placate TS v3.0 only
|
|
|
|
type R3ComponentMetadataFacadeNoPropAndWhitespace = Pick<
|
|
|
|
R3ComponentMetadataFacade,
|
|
|
|
Exclude<Exclude<keyof R3ComponentMetadataFacade, 'preserveWhitespaces'>, 'propMetadata'>>;
|
|
|
|
|
|
|
|
const USE_CLASS = Object.keys({useClass: null})[0];
|
|
|
|
const USE_FACTORY = Object.keys({useFactory: null})[0];
|
|
|
|
const USE_VALUE = Object.keys({useValue: null})[0];
|
|
|
|
const USE_EXISTING = Object.keys({useExisting: null})[0];
|
|
|
|
|
|
|
|
function convertToR3QueryMetadata(facade: R3QueryMetadataFacade): R3QueryMetadata {
|
|
|
|
return {
|
|
|
|
...facade,
|
|
|
|
predicate: Array.isArray(facade.predicate) ? facade.predicate :
|
|
|
|
new WrappedNodeExpr(facade.predicate),
|
|
|
|
read: facade.read ? new WrappedNodeExpr(facade.read) : null,
|
2020-12-10 18:10:56 -05:00
|
|
|
static: facade.static,
|
|
|
|
emitDistinctChangesOnly: facade.emitDistinctChangesOnly,
|
2018-10-24 19:02:25 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-13 14:25:20 -05:00
|
|
|
function convertQueryDeclarationToMetadata(declaration: R3DeclareQueryMetadataFacade):
|
|
|
|
R3QueryMetadata {
|
|
|
|
return {
|
|
|
|
propertyName: declaration.propertyName,
|
|
|
|
first: declaration.first ?? false,
|
|
|
|
predicate: Array.isArray(declaration.predicate) ? declaration.predicate :
|
|
|
|
new WrappedNodeExpr(declaration.predicate),
|
|
|
|
descendants: declaration.descendants ?? false,
|
|
|
|
read: declaration.read ? new WrappedNodeExpr(declaration.read) : null,
|
|
|
|
static: declaration.static ?? false,
|
2020-12-10 18:10:56 -05:00
|
|
|
emitDistinctChangesOnly: declaration.emitDistinctChangesOnly ?? true,
|
2020-12-13 14:25:20 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-10-24 19:02:25 -04:00
|
|
|
function convertDirectiveFacadeToMetadata(facade: R3DirectiveMetadataFacade): R3DirectiveMetadata {
|
|
|
|
const inputsFromMetadata = parseInputOutputs(facade.inputs || []);
|
|
|
|
const outputsFromMetadata = parseInputOutputs(facade.outputs || []);
|
|
|
|
const propMetadata = facade.propMetadata;
|
|
|
|
const inputsFromType: StringMapWithRename = {};
|
|
|
|
const outputsFromType: StringMap = {};
|
|
|
|
for (const field in propMetadata) {
|
|
|
|
if (propMetadata.hasOwnProperty(field)) {
|
|
|
|
propMetadata[field].forEach(ann => {
|
|
|
|
if (isInput(ann)) {
|
|
|
|
inputsFromType[field] =
|
|
|
|
ann.bindingPropertyName ? [ann.bindingPropertyName, field] : field;
|
|
|
|
} else if (isOutput(ann)) {
|
|
|
|
outputsFromType[field] = ann.bindingPropertyName || field;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
...facade as R3DirectiveMetadataFacadeNoPropAndWhitespace,
|
2021-03-23 11:14:53 -04:00
|
|
|
typeArgumentCount: 0,
|
2019-01-24 20:25:46 -05:00
|
|
|
typeSourceSpan: facade.typeSourceSpan,
|
2019-12-18 09:03:05 -05:00
|
|
|
type: wrapReference(facade.type),
|
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
2019-11-01 12:55:09 -04:00
|
|
|
internalType: new WrappedNodeExpr(facade.type),
|
2021-03-23 11:14:53 -04:00
|
|
|
deps: null,
|
2019-04-27 03:33:10 -04:00
|
|
|
host: extractHostBindings(facade.propMetadata, facade.typeSourceSpan, facade.host),
|
2018-10-24 19:02:25 -04:00
|
|
|
inputs: {...inputsFromMetadata, ...inputsFromType},
|
|
|
|
outputs: {...outputsFromMetadata, ...outputsFromType},
|
2018-11-12 21:02:47 -05:00
|
|
|
queries: facade.queries.map(convertToR3QueryMetadata),
|
2018-10-24 19:02:25 -04:00
|
|
|
providers: facade.providers != null ? new WrappedNodeExpr(facade.providers) : null,
|
2019-03-13 14:30:38 -04:00
|
|
|
viewQueries: facade.viewQueries.map(convertToR3QueryMetadata),
|
feat(ngcc): add a migration for undecorated child classes (#33362)
In Angular View Engine, there are two kinds of decorator inheritance:
1) both the parent and child classes have decorators
This case is supported by InheritDefinitionFeature, which merges some fields
of the definitions (such as the inputs or queries).
2) only the parent class has a decorator
If the child class is missing a decorator, the compiler effectively behaves
as if the parent class' decorator is applied to the child class as well.
This is the "undecorated child" scenario, and this commit adds a migration
to ngcc to support this pattern in Ivy.
This migration has 2 phases. First, the NgModules of the application are
scanned for classes in 'declarations' which are missing decorators, but
whose base classes do have decorators. These classes are the undecorated
children. This scan is performed recursively, so even if a declared class
has a base class that itself inherits a decorator, this case is handled.
Next, a synthetic decorator (either @Component or @Directive) is created
on the child class. This decorator copies some critical information such
as 'selector' and 'exportAs', as well as supports any decorated fields
(@Input, etc). A flag is passed to the decorator compiler which causes a
special feature `CopyDefinitionFeature` to be included on the compiled
definition. This feature copies at runtime the remaining aspects of the
parent definition which `InheritDefinitionFeature` does not handle,
completing the "full" inheritance of the child class' decorator from its
parent class.
PR Close #33362
2019-10-23 15:00:49 -04:00
|
|
|
fullInheritance: false,
|
2018-10-24 19:02:25 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-13 14:25:20 -05:00
|
|
|
function convertDeclareDirectiveFacadeToMetadata(
|
|
|
|
declaration: R3DeclareDirectiveFacade, typeSourceSpan: ParseSourceSpan): R3DirectiveMetadata {
|
|
|
|
return {
|
|
|
|
name: declaration.type.name,
|
|
|
|
type: wrapReference(declaration.type),
|
|
|
|
typeSourceSpan,
|
|
|
|
internalType: new WrappedNodeExpr(declaration.type),
|
|
|
|
selector: declaration.selector ?? null,
|
|
|
|
inputs: declaration.inputs ?? {},
|
|
|
|
outputs: declaration.outputs ?? {},
|
|
|
|
host: convertHostDeclarationToMetadata(declaration.host),
|
|
|
|
queries: (declaration.queries ?? []).map(convertQueryDeclarationToMetadata),
|
|
|
|
viewQueries: (declaration.viewQueries ?? []).map(convertQueryDeclarationToMetadata),
|
|
|
|
providers: declaration.providers !== undefined ? new WrappedNodeExpr(declaration.providers) :
|
|
|
|
null,
|
|
|
|
exportAs: declaration.exportAs ?? null,
|
|
|
|
usesInheritance: declaration.usesInheritance ?? false,
|
|
|
|
lifecycle: {usesOnChanges: declaration.usesOnChanges ?? false},
|
|
|
|
deps: null,
|
|
|
|
typeArgumentCount: 0,
|
|
|
|
fullInheritance: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertHostDeclarationToMetadata(host: R3DeclareDirectiveFacade['host'] = {}):
|
|
|
|
R3HostMetadata {
|
|
|
|
return {
|
|
|
|
attributes: convertOpaqueValuesToExpressions(host.attributes ?? {}),
|
|
|
|
listeners: host.listeners ?? {},
|
|
|
|
properties: host.properties ?? {},
|
|
|
|
specialAttributes: {
|
|
|
|
classAttr: host.classAttribute,
|
|
|
|
styleAttr: host.styleAttribute,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertOpaqueValuesToExpressions(obj: {[key: string]: OpaqueValue}):
|
|
|
|
{[key: string]: WrappedNodeExpr<unknown>} {
|
|
|
|
const result: {[key: string]: WrappedNodeExpr<unknown>} = {};
|
|
|
|
for (const key of Object.keys(obj)) {
|
|
|
|
result[key] = new WrappedNodeExpr(obj[key]);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-12-15 06:47:35 -05:00
|
|
|
function convertDeclareComponentFacadeToMetadata(
|
|
|
|
declaration: R3DeclareComponentFacade, typeSourceSpan: ParseSourceSpan,
|
|
|
|
sourceMapUrl: string): R3ComponentMetadata {
|
|
|
|
const {template, interpolation} = parseJitTemplate(
|
2021-01-10 10:46:14 -05:00
|
|
|
declaration.template, declaration.type.name, sourceMapUrl,
|
2020-12-15 06:47:35 -05:00
|
|
|
declaration.preserveWhitespaces ?? false, declaration.interpolation);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...convertDeclareDirectiveFacadeToMetadata(declaration, typeSourceSpan),
|
|
|
|
template,
|
|
|
|
styles: declaration.styles ?? [],
|
2021-03-26 19:45:42 -04:00
|
|
|
directives: (declaration.components ?? [])
|
|
|
|
.concat(declaration.directives ?? [])
|
|
|
|
.map(convertUsedDirectiveDeclarationToMetadata),
|
2020-12-15 06:47:35 -05:00
|
|
|
pipes: convertUsedPipesToMetadata(declaration.pipes),
|
|
|
|
viewProviders: declaration.viewProviders !== undefined ?
|
|
|
|
new WrappedNodeExpr(declaration.viewProviders) :
|
|
|
|
null,
|
|
|
|
animations: declaration.animations !== undefined ? new WrappedNodeExpr(declaration.animations) :
|
|
|
|
null,
|
|
|
|
changeDetection: declaration.changeDetection ?? ChangeDetectionStrategy.Default,
|
|
|
|
encapsulation: declaration.encapsulation ?? ViewEncapsulation.Emulated,
|
|
|
|
interpolation,
|
|
|
|
declarationListEmitMode: DeclarationListEmitMode.ClosureResolved,
|
|
|
|
relativeContextFilePath: '',
|
|
|
|
i18nUseExternalIds: true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-26 19:45:42 -04:00
|
|
|
function convertUsedDirectiveDeclarationToMetadata(declaration: R3DeclareUsedDirectiveFacade):
|
2020-12-15 06:47:35 -05:00
|
|
|
R3UsedDirectiveMetadata {
|
|
|
|
return {
|
|
|
|
selector: declaration.selector,
|
|
|
|
type: new WrappedNodeExpr(declaration.type),
|
|
|
|
inputs: declaration.inputs ?? [],
|
|
|
|
outputs: declaration.outputs ?? [],
|
|
|
|
exportAs: declaration.exportAs ?? null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertUsedPipesToMetadata(declaredPipes: R3DeclareComponentFacade['pipes']):
|
|
|
|
Map<string, Expression> {
|
|
|
|
const pipes = new Map<string, Expression>();
|
|
|
|
if (declaredPipes === undefined) {
|
|
|
|
return pipes;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const pipeName of Object.keys(declaredPipes)) {
|
|
|
|
const pipeType = declaredPipes[pipeName];
|
|
|
|
pipes.set(pipeName, new WrappedNodeExpr(pipeType));
|
|
|
|
}
|
|
|
|
return pipes;
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseJitTemplate(
|
|
|
|
template: string, typeName: string, sourceMapUrl: string, preserveWhitespaces: boolean,
|
|
|
|
interpolation: [string, string]|undefined) {
|
|
|
|
const interpolationConfig =
|
|
|
|
interpolation ? InterpolationConfig.fromArray(interpolation) : DEFAULT_INTERPOLATION_CONFIG;
|
|
|
|
// Parse the template and check for errors.
|
|
|
|
const parsed = parseTemplate(
|
|
|
|
template, sourceMapUrl, {preserveWhitespaces: preserveWhitespaces, interpolationConfig});
|
|
|
|
if (parsed.errors !== null) {
|
|
|
|
const errors = parsed.errors.map(err => err.toString()).join(', ');
|
|
|
|
throw new Error(`Errors during JIT compilation of template for ${typeName}: ${errors}`);
|
|
|
|
}
|
|
|
|
return {template: parsed, interpolation: interpolationConfig};
|
|
|
|
}
|
|
|
|
|
2018-10-24 19:02:25 -04:00
|
|
|
// This seems to be needed to placate TS v3.0 only
|
|
|
|
type R3DirectiveMetadataFacadeNoPropAndWhitespace =
|
|
|
|
Pick<R3DirectiveMetadataFacade, Exclude<keyof R3DirectiveMetadataFacade, 'propMetadata'>>;
|
|
|
|
|
2021-03-21 13:31:20 -04:00
|
|
|
/**
|
|
|
|
* Convert the expression, if present to an `R3ProviderExpression`.
|
|
|
|
*
|
|
|
|
* In JIT mode we do not want the compiler to wrap the expression in a `forwardRef()` call because,
|
|
|
|
* if it is referencing a type that has not yet been defined, it will have already been wrapped in
|
|
|
|
* a `forwardRef()` - either by the application developer or during partial-compilation. Thus we can
|
|
|
|
* set `isForwardRef` to `false`.
|
|
|
|
*/
|
|
|
|
function convertToProviderExpression(obj: any, property: string): R3ProviderExpression|undefined {
|
2018-10-24 19:02:25 -04:00
|
|
|
if (obj.hasOwnProperty(property)) {
|
2021-03-21 13:31:20 -04:00
|
|
|
return createR3ProviderExpression(new WrappedNodeExpr(obj[property]), /* isForwardRef */ false);
|
2018-10-24 19:02:25 -04:00
|
|
|
} else {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 13:31:20 -04:00
|
|
|
function wrapExpression(obj: any, property: string): WrappedNodeExpr<any>|undefined {
|
|
|
|
if (obj.hasOwnProperty(property)) {
|
|
|
|
return new WrappedNodeExpr(obj[property]);
|
2018-10-24 19:02:25 -04:00
|
|
|
} else {
|
2021-03-21 13:31:20 -04:00
|
|
|
return undefined;
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 13:31:20 -04:00
|
|
|
function computeProvidedIn(providedIn: Function|string|null|undefined): R3ProviderExpression {
|
|
|
|
const expression = (providedIn == null || typeof providedIn === 'string') ?
|
|
|
|
new LiteralExpr(providedIn ?? null) :
|
|
|
|
new WrappedNodeExpr(providedIn);
|
|
|
|
// See `convertToProviderExpression()` for why `isForwardRef` is false.
|
|
|
|
return createR3ProviderExpression(expression, /* isForwardRef */ false);
|
|
|
|
}
|
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
function convertR3DependencyMetadataArray(facades: R3DependencyMetadataFacade[]|null|
|
|
|
|
undefined): R3DependencyMetadata[]|null {
|
2018-10-24 19:02:25 -04:00
|
|
|
return facades == null ? null : facades.map(convertR3DependencyMetadata);
|
2021-03-14 17:03:59 -04:00
|
|
|
}
|
|
|
|
|
2021-03-23 11:14:53 -04:00
|
|
|
function convertR3DependencyMetadata(facade: R3DependencyMetadataFacade): R3DependencyMetadata {
|
|
|
|
const isAttributeDep = facade.attribute != null; // both `null` and `undefined`
|
|
|
|
const rawToken = facade.token === null ? null : new WrappedNodeExpr(facade.token);
|
|
|
|
// In JIT mode, if the dep is an `@Attribute()` then we use the attribute name given in
|
|
|
|
// `attribute` rather than the `token`.
|
|
|
|
const token = isAttributeDep ? new WrappedNodeExpr(facade.attribute) : rawToken;
|
|
|
|
return createR3DependencyMetadata(
|
|
|
|
token, isAttributeDep, facade.host, facade.optional, facade.self, facade.skipSelf);
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertR3DeclareDependencyMetadata(facade: R3DeclareDependencyMetadataFacade):
|
|
|
|
R3DependencyMetadata {
|
|
|
|
const isAttributeDep = facade.attribute ?? false;
|
|
|
|
const token = facade.token === null ? null : new WrappedNodeExpr(facade.token);
|
|
|
|
return createR3DependencyMetadata(
|
|
|
|
token, isAttributeDep, facade.host ?? false, facade.optional ?? false, facade.self ?? false,
|
|
|
|
facade.skipSelf ?? false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createR3DependencyMetadata(
|
|
|
|
token: WrappedNodeExpr<unknown>|null, isAttributeDep: boolean, host: boolean, optional: boolean,
|
|
|
|
self: boolean, skipSelf: boolean): R3DependencyMetadata {
|
|
|
|
// If the dep is an `@Attribute()` the `attributeNameType` ought to be the `unknown` type.
|
|
|
|
// But types are not available at runtime so we just use a literal `"<unknown>"` string as a dummy
|
|
|
|
// marker.
|
|
|
|
const attributeNameType = isAttributeDep ? literal('unknown') : null;
|
|
|
|
return {token, attributeNameType, host, optional, self, skipSelf};
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
|
2019-01-24 20:25:46 -05:00
|
|
|
function extractHostBindings(
|
2019-04-27 03:33:10 -04:00
|
|
|
propMetadata: {[key: string]: any[]}, sourceSpan: ParseSourceSpan,
|
|
|
|
host?: {[key: string]: string}): ParsedHostBindings {
|
2018-10-24 19:02:25 -04:00
|
|
|
// First parse the declarations from the metadata.
|
2019-01-24 20:25:46 -05:00
|
|
|
const bindings = parseHostBindings(host || {});
|
|
|
|
|
|
|
|
// After that check host bindings for errors
|
|
|
|
const errors = verifyHostBindings(bindings, sourceSpan);
|
|
|
|
if (errors.length) {
|
|
|
|
throw new Error(errors.map((error: ParseError) => error.msg).join('\n'));
|
|
|
|
}
|
2018-10-24 19:02:25 -04:00
|
|
|
|
|
|
|
// Next, loop over the properties of the object, looking for @HostBinding and @HostListener.
|
|
|
|
for (const field in propMetadata) {
|
|
|
|
if (propMetadata.hasOwnProperty(field)) {
|
|
|
|
propMetadata[field].forEach(ann => {
|
|
|
|
if (isHostBinding(ann)) {
|
2020-12-31 11:32:24 -05:00
|
|
|
// Since this is a decorator, we know that the value is a class member. Always access it
|
|
|
|
// through `this` so that further down the line it can't be confused for a literal value
|
|
|
|
// (e.g. if there's a property called `true`).
|
|
|
|
bindings.properties[ann.hostPropertyName || field] =
|
|
|
|
getSafePropertyAccessString('this', field);
|
2018-10-24 19:02:25 -04:00
|
|
|
} else if (isHostListener(ann)) {
|
2019-01-24 20:25:46 -05:00
|
|
|
bindings.listeners[ann.eventName || field] = `${field}(${(ann.args || []).join(',')})`;
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-24 20:25:46 -05:00
|
|
|
return bindings;
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function isHostBinding(value: any): value is HostBinding {
|
|
|
|
return value.ngMetadataName === 'HostBinding';
|
|
|
|
}
|
|
|
|
|
|
|
|
function isHostListener(value: any): value is HostListener {
|
|
|
|
return value.ngMetadataName === 'HostListener';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function isInput(value: any): value is Input {
|
|
|
|
return value.ngMetadataName === 'Input';
|
|
|
|
}
|
|
|
|
|
|
|
|
function isOutput(value: any): value is Output {
|
|
|
|
return value.ngMetadataName === 'Output';
|
|
|
|
}
|
|
|
|
|
|
|
|
function parseInputOutputs(values: string[]): StringMap {
|
2020-04-08 13:14:18 -04:00
|
|
|
return values.reduce((map, value) => {
|
|
|
|
const [field, property] = value.split(',').map(piece => piece.trim());
|
|
|
|
map[field] = property || field;
|
|
|
|
return map;
|
|
|
|
}, {} as StringMap);
|
2018-10-24 19:02:25 -04:00
|
|
|
}
|
|
|
|
|
2021-02-11 09:42:10 -05:00
|
|
|
function convertDeclarePipeFacadeToMetadata(declaration: R3DeclarePipeFacade): R3PipeMetadata {
|
|
|
|
return {
|
|
|
|
name: declaration.type.name,
|
|
|
|
type: wrapReference(declaration.type),
|
|
|
|
internalType: new WrappedNodeExpr(declaration.type),
|
|
|
|
typeArgumentCount: 0,
|
|
|
|
pipeName: declaration.name,
|
|
|
|
deps: null,
|
|
|
|
pure: declaration.pure ?? true,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-04 15:55:25 -05:00
|
|
|
function convertDeclareInjectorFacadeToMetadata(declaration: R3DeclareInjectorFacade):
|
|
|
|
R3InjectorMetadata {
|
|
|
|
return {
|
|
|
|
name: declaration.type.name,
|
|
|
|
type: wrapReference(declaration.type),
|
|
|
|
internalType: new WrappedNodeExpr(declaration.type),
|
|
|
|
providers: declaration.providers !== undefined ? new WrappedNodeExpr(declaration.providers) :
|
|
|
|
null,
|
|
|
|
imports: declaration.imports !== undefined ?
|
|
|
|
declaration.imports.map(i => new WrappedNodeExpr(i)) :
|
|
|
|
[],
|
|
|
|
};
|
|
|
|
}
|
2021-02-11 09:42:10 -05:00
|
|
|
|
2018-10-24 19:02:25 -04:00
|
|
|
export function publishFacade(global: any) {
|
|
|
|
const ng: ExportedCompilerFacade = global.ng || (global.ng = {});
|
|
|
|
ng.ɵcompilerFacade = new CompilerFacadeImpl();
|
2018-11-12 21:02:47 -05:00
|
|
|
}
|