refactor(compiler): wrap the jit evaluation in an injectable class (#28055)
When testing JIT code, it is useful to be able to access the generated JIT source. Previously this is done by spying on the global `Function` object, to capture the code when it is being evaluated. This is problematic because you can only capture the body of the function, and not the arguments, which messes up line and column positions for source mapping for instance. Now the code that generates and then evaluates JIT code is wrapped in a `JitEvaluator` class, making it possible to provide a mock implementation that can capture the generated source of the function passed to `executeFunction(fn: Function, args: any[])`. PR Close #28055
This commit is contained in:

committed by
Misko Hevery

parent
8c3f1717a8
commit
54ca24b47d
@ -6,9 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Compiler, CompilerFactory, ComponentFactory, CompilerOptions, ModuleWithComponentFactories, Inject, InjectionToken, Optional, PACKAGE_ROOT_URL, PlatformRef, StaticProvider, TRANSLATIONS, Type, isDevMode, platformCore, ɵConsole as Console, ViewEncapsulation, Injector, NgModuleFactory, TRANSLATIONS_FORMAT, MissingTranslationStrategy,} from '@angular/core';
|
||||
import {Compiler, CompilerFactory, ComponentFactory, CompilerOptions, ModuleWithComponentFactories, Inject, InjectionToken, Optional, PACKAGE_ROOT_URL, StaticProvider, TRANSLATIONS, Type, isDevMode, ɵConsole as Console, ViewEncapsulation, Injector, NgModuleFactory, TRANSLATIONS_FORMAT, MissingTranslationStrategy,} from '@angular/core';
|
||||
|
||||
import {StaticSymbolCache, JitCompiler, ProviderMeta, ExternalReference, I18NHtmlParser, Identifiers, ViewCompiler, CompileMetadataResolver, UrlResolver, TemplateParser, NgModuleCompiler, JitSummaryResolver, SummaryResolver, StyleCompiler, PipeResolver, ElementSchemaRegistry, DomElementSchemaRegistry, ResourceLoader, NgModuleResolver, HtmlParser, CompileReflector, CompilerConfig, DirectiveNormalizer, DirectiveResolver, Lexer, Parser} from '@angular/compiler';
|
||||
import {StaticSymbolCache, JitCompiler, ProviderMeta, I18NHtmlParser, ViewCompiler, CompileMetadataResolver, UrlResolver, TemplateParser, NgModuleCompiler, JitEvaluator, JitSummaryResolver, SummaryResolver, StyleCompiler, PipeResolver, ElementSchemaRegistry, DomElementSchemaRegistry, ResourceLoader, NgModuleResolver, HtmlParser, CompileReflector, CompilerConfig, DirectiveNormalizer, DirectiveResolver, Lexer, Parser} from '@angular/compiler';
|
||||
|
||||
import {JitReflector} from './compiler_reflector';
|
||||
|
||||
@ -37,10 +37,11 @@ export class CompilerImpl implements Compiler {
|
||||
injector: Injector, private _metadataResolver: CompileMetadataResolver,
|
||||
templateParser: TemplateParser, styleCompiler: StyleCompiler, viewCompiler: ViewCompiler,
|
||||
ngModuleCompiler: NgModuleCompiler, summaryResolver: SummaryResolver<Type<any>>,
|
||||
compileReflector: CompileReflector, compilerConfig: CompilerConfig, console: Console) {
|
||||
compileReflector: CompileReflector, jitEvaluator: JitEvaluator,
|
||||
compilerConfig: CompilerConfig, console: Console) {
|
||||
this._delegate = new JitCompiler(
|
||||
_metadataResolver, templateParser, styleCompiler, viewCompiler, ngModuleCompiler,
|
||||
summaryResolver, compileReflector, compilerConfig, console,
|
||||
summaryResolver, compileReflector, jitEvaluator, compilerConfig, console,
|
||||
this.getExtraNgModuleProviders.bind(this));
|
||||
this.injector = injector;
|
||||
}
|
||||
@ -127,6 +128,7 @@ export const COMPILER_PROVIDERS = <StaticProvider[]>[
|
||||
Parser, ElementSchemaRegistry,
|
||||
I18NHtmlParser, Console]
|
||||
},
|
||||
{ provide: JitEvaluator, useClass: JitEvaluator, deps: [] },
|
||||
{ provide: DirectiveNormalizer, deps: [ResourceLoader, UrlResolver, HtmlParser, CompilerConfig]},
|
||||
{ provide: CompileMetadataResolver, deps: [CompilerConfig, HtmlParser, NgModuleResolver,
|
||||
DirectiveResolver, PipeResolver,
|
||||
@ -144,7 +146,7 @@ export const COMPILER_PROVIDERS = <StaticProvider[]>[
|
||||
{ provide: Compiler, useClass: CompilerImpl, deps: [Injector, CompileMetadataResolver,
|
||||
TemplateParser, StyleCompiler,
|
||||
ViewCompiler, NgModuleCompiler,
|
||||
SummaryResolver, CompileReflector, CompilerConfig,
|
||||
SummaryResolver, CompileReflector, JitEvaluator, CompilerConfig,
|
||||
Console]},
|
||||
{ provide: DomElementSchemaRegistry, deps: []},
|
||||
{ provide: ElementSchemaRegistry, useExisting: DomElementSchemaRegistry},
|
||||
|
Reference in New Issue
Block a user