If a decorator or partial declaration has not been AOT compiled, then the compiler is needed at runtime to be able to JIT compile the code. However, it may occur that the compiler is not available, if it has not been loaded into the application. The error that was reported in this case did not provide insight into which class requested compilation, nor did it differentiate between decorators vs. partial declarations. This commit expands the error logging to provide better insight into the class that initiated JIT compilation and offers a specialized error message for partial declarations. This should help a developer better understand why the error occurs and what can be done to resolve it. Closes #40609 PR Close #42693
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC 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
|
|
*/
|
|
|
|
import {getCompilerFacade, JitCompilerUsage, R3PipeMetadataFacade} from '../../compiler/compiler_facade';
|
|
import {reflectDependencies} from '../../di/jit/util';
|
|
import {Type} from '../../interface/type';
|
|
import {Pipe} from '../../metadata/directives';
|
|
import {NG_FACTORY_DEF, NG_PIPE_DEF} from '../fields';
|
|
|
|
import {angularCoreEnv} from './environment';
|
|
|
|
export function compilePipe(type: Type<any>, meta: Pipe): void {
|
|
let ngPipeDef: any = null;
|
|
let ngFactoryDef: any = null;
|
|
|
|
Object.defineProperty(type, NG_FACTORY_DEF, {
|
|
get: () => {
|
|
if (ngFactoryDef === null) {
|
|
const metadata = getPipeMetadata(type, meta);
|
|
const compiler = getCompilerFacade(
|
|
{usage: JitCompilerUsage.Decorator, kind: 'pipe', type: metadata.type});
|
|
ngFactoryDef = compiler.compileFactory(angularCoreEnv, `ng:///${metadata.name}/ɵfac.js`, {
|
|
name: metadata.name,
|
|
type: metadata.type,
|
|
typeArgumentCount: 0,
|
|
deps: reflectDependencies(type),
|
|
target: compiler.FactoryTarget.Pipe
|
|
});
|
|
}
|
|
return ngFactoryDef;
|
|
},
|
|
// Make the property configurable in dev mode to allow overriding in tests
|
|
configurable: !!ngDevMode,
|
|
});
|
|
|
|
Object.defineProperty(type, NG_PIPE_DEF, {
|
|
get: () => {
|
|
if (ngPipeDef === null) {
|
|
const metadata = getPipeMetadata(type, meta);
|
|
const compiler = getCompilerFacade(
|
|
{usage: JitCompilerUsage.Decorator, kind: 'pipe', type: metadata.type});
|
|
ngPipeDef =
|
|
compiler.compilePipe(angularCoreEnv, `ng:///${metadata.name}/ɵpipe.js`, metadata);
|
|
}
|
|
return ngPipeDef;
|
|
},
|
|
// Make the property configurable in dev mode to allow overriding in tests
|
|
configurable: !!ngDevMode,
|
|
});
|
|
}
|
|
|
|
function getPipeMetadata(type: Type<any>, meta: Pipe): R3PipeMetadataFacade {
|
|
return {
|
|
type: type,
|
|
name: type.name,
|
|
pipeName: meta.name,
|
|
pure: meta.pure !== undefined ? meta.pure : true
|
|
};
|
|
}
|