refactor(compiler): don’t rely on global reflector (#16832)
Using the global reflector made it impossible to compile multiple programs at the same time.
This commit is contained in:

committed by
Chuck Jazdzewski

parent
de8d7c65f2
commit
50abca4583
@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import {AotCompilerHost, AotCompilerOptions, GeneratedFile, createAotCompiler, toTypeScript} from '@angular/compiler';
|
||||
import {ɵReflectionCapabilities as ReflectionCapabilities, ɵreflector as reflector} from '@angular/core';
|
||||
import {MetadataBundlerHost, MetadataCollector, ModuleMetadata} from '@angular/tsc-wrapped';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
@ -537,8 +536,6 @@ export function setup(options: {compileAngular: boolean} = {
|
||||
emittingHost.writtenAngularFiles(angularFiles);
|
||||
}
|
||||
});
|
||||
// Restore reflector since AoT compiler will update it with a new static reflector
|
||||
afterEach(() => { reflector.updateCapabilities(new ReflectionCapabilities()); });
|
||||
|
||||
return angularFiles;
|
||||
}
|
||||
|
@ -6,9 +6,13 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {hasLifecycleHook} from '@angular/compiler/src/lifecycle_reflector';
|
||||
import {JitReflector} from '@angular/compiler';
|
||||
import {LifecycleHooks as Hooks, hasLifecycleHook as hasLifecycleHookImpl} from '@angular/compiler/src/lifecycle_reflector';
|
||||
import {SimpleChanges} from '@angular/core';
|
||||
import {LifecycleHooks as Hooks} from '@angular/core/src/metadata/lifecycle_hooks';
|
||||
|
||||
function hasLifecycleHook(hook: Hooks, directive: any): boolean {
|
||||
return hasLifecycleHookImpl(new JitReflector(), hook, directive);
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('Create Directive', () => {
|
||||
|
@ -6,8 +6,10 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {JitReflector} from '@angular/compiler';
|
||||
import {Component, Directive, Injector, ɵViewMetadata as ViewMetadata} from '@angular/core';
|
||||
import {TestBed, inject} from '@angular/core/testing';
|
||||
|
||||
import {MockDirectiveResolver} from '../testing';
|
||||
|
||||
export function main() {
|
||||
@ -20,7 +22,7 @@ export function main() {
|
||||
});
|
||||
|
||||
beforeEach(inject([Injector], (injector: Injector) => {
|
||||
dirResolver = new MockDirectiveResolver(injector);
|
||||
dirResolver = new MockDirectiveResolver(injector, new JitReflector());
|
||||
}));
|
||||
|
||||
describe('Directive overriding', () => {
|
||||
|
@ -6,9 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {JitReflector} from '@angular/compiler';
|
||||
import {DirectiveResolver} from '@angular/compiler/src/directive_resolver';
|
||||
import {Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Input, Output, ViewChild, ViewChildren} from '@angular/core/src/metadata';
|
||||
import {reflector} from '@angular/core/src/reflection/reflection';
|
||||
|
||||
@Directive({selector: 'someDirective'})
|
||||
class SomeDirective {
|
||||
@ -110,7 +110,7 @@ export function main() {
|
||||
describe('DirectiveResolver', () => {
|
||||
let resolver: DirectiveResolver;
|
||||
|
||||
beforeEach(() => { resolver = new DirectiveResolver(); });
|
||||
beforeEach(() => { resolver = new DirectiveResolver(new JitReflector()); });
|
||||
|
||||
it('should read out the Directive metadata', () => {
|
||||
const directiveMetadata = resolver.resolve(SomeDirective);
|
||||
|
@ -6,14 +6,16 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {LIFECYCLE_HOOKS_VALUES, LifecycleHooks} from '@angular/compiler/src/lifecycle_reflector';
|
||||
import {TEST_COMPILER_PROVIDERS} from '@angular/compiler/testing/src/test_bindings';
|
||||
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, Component, Directive, DoCheck, Injectable, NgModule, OnChanges, OnDestroy, OnInit, Pipe, SimpleChanges, ViewEncapsulation, ɵstringify as stringify} from '@angular/core';
|
||||
import {LIFECYCLE_HOOKS_VALUES} from '@angular/core/src/metadata/lifecycle_hooks';
|
||||
import {TestBed, async, inject} from '@angular/core/testing';
|
||||
|
||||
import {identifierName} from '../src/compile_metadata';
|
||||
import {CompileMetadataResolver} from '../src/metadata_resolver';
|
||||
import {ResourceLoader} from '../src/resource_loader';
|
||||
import {MockResourceLoader} from '../testing/src/resource_loader_mock';
|
||||
|
||||
import {MalformedStylesComponent} from './metadata_resolver_fixture';
|
||||
|
||||
export function main() {
|
||||
|
@ -6,8 +6,10 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {JitReflector} from '@angular/compiler';
|
||||
import {Injector, NgModule} from '@angular/core';
|
||||
import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {MockNgModuleResolver} from '../testing';
|
||||
|
||||
export function main() {
|
||||
@ -15,7 +17,7 @@ export function main() {
|
||||
let ngModuleResolver: MockNgModuleResolver;
|
||||
|
||||
beforeEach(inject([Injector], (injector: Injector) => {
|
||||
ngModuleResolver = new MockNgModuleResolver(injector);
|
||||
ngModuleResolver = new MockNgModuleResolver(injector, new JitReflector());
|
||||
}));
|
||||
|
||||
describe('NgModule overriding', () => {
|
||||
|
@ -6,6 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {JitReflector} from '@angular/compiler';
|
||||
import {NgModuleResolver} from '@angular/compiler/src/ng_module_resolver';
|
||||
import {ɵstringify as stringify} from '@angular/core';
|
||||
import {NgModule} from '@angular/core/src/metadata';
|
||||
@ -32,7 +33,7 @@ export function main() {
|
||||
describe('NgModuleResolver', () => {
|
||||
let resolver: NgModuleResolver;
|
||||
|
||||
beforeEach(() => { resolver = new NgModuleResolver(); });
|
||||
beforeEach(() => { resolver = new NgModuleResolver(new JitReflector()); });
|
||||
|
||||
it('should read out the metadata from the class', () => {
|
||||
const moduleMetadata = resolver.resolve(SomeModule);
|
||||
|
@ -6,16 +6,19 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {JitReflector} from '@angular/compiler';
|
||||
import {Injector, Pipe} from '@angular/core';
|
||||
import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {inject} from '@angular/core/testing';
|
||||
|
||||
import {MockPipeResolver} from '../testing';
|
||||
|
||||
export function main() {
|
||||
describe('MockPipeResolver', () => {
|
||||
let pipeResolver: MockPipeResolver;
|
||||
|
||||
beforeEach(inject(
|
||||
[Injector], (injector: Injector) => { pipeResolver = new MockPipeResolver(injector); }));
|
||||
beforeEach(inject([Injector], (injector: Injector) => {
|
||||
pipeResolver = new MockPipeResolver(injector, new JitReflector());
|
||||
}));
|
||||
|
||||
describe('Pipe overriding', () => {
|
||||
it('should fallback to the default PipeResolver when templates are not overridden', () => {
|
||||
|
@ -6,6 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {JitReflector} from '@angular/compiler';
|
||||
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
|
||||
import {ɵstringify as stringify} from '@angular/core';
|
||||
import {Pipe} from '@angular/core/src/metadata';
|
||||
@ -20,7 +21,7 @@ export function main() {
|
||||
describe('PipeResolver', () => {
|
||||
let resolver: PipeResolver;
|
||||
|
||||
beforeEach(() => { resolver = new PipeResolver(); });
|
||||
beforeEach(() => { resolver = new PipeResolver(new JitReflector()); });
|
||||
|
||||
it('should read out the metadata from the class', () => {
|
||||
const moduleMetadata = resolver.resolve(SomePipe);
|
||||
|
@ -5,7 +5,7 @@
|
||||
* 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 {CompileQueryMetadata, CompilerConfig, ProxyClass, StaticSymbol} from '@angular/compiler';
|
||||
import {CompileQueryMetadata, CompilerConfig, JitReflector, ProxyClass, StaticSymbol} from '@angular/compiler';
|
||||
import {CompileAnimationEntryMetadata, CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileDirectiveSummary, CompilePipeMetadata, CompilePipeSummary, CompileProviderMetadata, CompileTemplateMetadata, CompileTokenMetadata, CompileTypeMetadata, tokenReference} from '@angular/compiler/src/compile_metadata';
|
||||
import {DomElementSchemaRegistry} from '@angular/compiler/src/schema/dom_element_schema_registry';
|
||||
import {ElementSchemaRegistry} from '@angular/compiler/src/schema/element_schema_registry';
|
||||
@ -17,7 +17,7 @@ import {Console} from '@angular/core/src/console';
|
||||
import {TestBed, inject} from '@angular/core/testing';
|
||||
|
||||
import {CompileEntryComponentMetadata, CompileStylesheetMetadata} from '../../src/compile_metadata';
|
||||
import {Identifiers, createIdentifierToken, identifierToken} from '../../src/identifiers';
|
||||
import {Identifiers, createTokenForExternalReference, createTokenForReference} from '../../src/identifiers';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../../src/ml_parser/interpolation_config';
|
||||
import {noUndefined} from '../../src/util';
|
||||
import {MockSchemaRegistry} from '../../testing';
|
||||
@ -1198,7 +1198,7 @@ Binding to attribute 'onEvent' is disallowed for security reasons ("<my-componen
|
||||
expect(humanizeTplAst(parse('<div a #a="dirA"></div>', [dirA]))).toEqual([
|
||||
[ElementAst, 'div'],
|
||||
[AttrAst, 'a', ''],
|
||||
[ReferenceAst, 'a', identifierToken(dirA.type)],
|
||||
[ReferenceAst, 'a', createTokenForReference(dirA.type.reference)],
|
||||
[DirectiveAst, dirA],
|
||||
]);
|
||||
});
|
||||
@ -1244,7 +1244,7 @@ Reference "#a" is defined several times ("<div #a></div><div [ERROR ->]#a></div>
|
||||
expect(humanizeTplAst(parse('<div a #a></div>', [dirA]))).toEqual([
|
||||
[ElementAst, 'div'],
|
||||
[AttrAst, 'a', ''],
|
||||
[ReferenceAst, 'a', identifierToken(dirA.type)],
|
||||
[ReferenceAst, 'a', createTokenForReference(dirA.type.reference)],
|
||||
[DirectiveAst, dirA],
|
||||
]);
|
||||
});
|
||||
@ -1262,6 +1262,10 @@ Reference "#a" is defined several times ("<div #a></div><div [ERROR ->]#a></div>
|
||||
});
|
||||
|
||||
describe('explicit templates', () => {
|
||||
let reflector: JitReflector;
|
||||
|
||||
beforeEach(() => { reflector = new JitReflector(); });
|
||||
|
||||
it('should create embedded templates for <ng-template> elements', () => {
|
||||
expect(humanizeTplAst(parse('<template></template>', [
|
||||
]))).toEqual([[EmbeddedTemplateAst]]);
|
||||
@ -1286,22 +1290,30 @@ Reference "#a" is defined several times ("<div #a></div><div [ERROR ->]#a></div>
|
||||
it('should support references via #...', () => {
|
||||
expect(humanizeTplAst(parse('<template #a>', []))).toEqual([
|
||||
[EmbeddedTemplateAst],
|
||||
[ReferenceAst, 'a', createIdentifierToken(Identifiers.TemplateRef)],
|
||||
[
|
||||
ReferenceAst, 'a', createTokenForExternalReference(reflector, Identifiers.TemplateRef)
|
||||
],
|
||||
]);
|
||||
expect(humanizeTplAst(parse('<ng-template #a>', []))).toEqual([
|
||||
[EmbeddedTemplateAst],
|
||||
[ReferenceAst, 'a', createIdentifierToken(Identifiers.TemplateRef)],
|
||||
[
|
||||
ReferenceAst, 'a', createTokenForExternalReference(reflector, Identifiers.TemplateRef)
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should support references via ref-...', () => {
|
||||
expect(humanizeTplAst(parse('<template ref-a>', []))).toEqual([
|
||||
[EmbeddedTemplateAst],
|
||||
[ReferenceAst, 'a', createIdentifierToken(Identifiers.TemplateRef)]
|
||||
[
|
||||
ReferenceAst, 'a', createTokenForExternalReference(reflector, Identifiers.TemplateRef)
|
||||
]
|
||||
]);
|
||||
expect(humanizeTplAst(parse('<ng-template ref-a>', []))).toEqual([
|
||||
[EmbeddedTemplateAst],
|
||||
[ReferenceAst, 'a', createIdentifierToken(Identifiers.TemplateRef)]
|
||||
[
|
||||
ReferenceAst, 'a', createTokenForExternalReference(reflector, Identifiers.TemplateRef)
|
||||
]
|
||||
]);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user