refactor(compiler): make static reflector work
Also adjust `RuntimeMetadataResolver` to be able to use it. Also rename `RuntimeMetadataResolver` into `CompileMetadataResolver`. Closes #8313
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
library angular2.test.compiler.runtime_metadata_fixture;
|
||||
library angular2.test.compiler.metadata_resolver_fixture;
|
||||
|
||||
import "package:angular2/core.dart" show Component;
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
} from 'angular2/testing_internal';
|
||||
|
||||
import {IS_DART, stringify} from 'angular2/src/facade/lang';
|
||||
import {RuntimeMetadataResolver} from 'angular2/src/compiler/runtime_metadata';
|
||||
import {CompileMetadataResolver} from 'angular2/src/compiler/metadata_resolver';
|
||||
import {LifecycleHooks, LIFECYCLE_HOOKS_VALUES} from 'angular2/src/core/metadata/lifecycle_hooks';
|
||||
import {
|
||||
Component,
|
||||
@ -36,15 +36,15 @@ import {
|
||||
import {TEST_PROVIDERS} from './test_bindings';
|
||||
import {MODULE_SUFFIX} from 'angular2/src/compiler/util';
|
||||
import {PLATFORM_DIRECTIVES} from 'angular2/src/core/platform_directives_and_pipes';
|
||||
import {MalformedStylesComponent} from './runtime_metadata_fixture';
|
||||
import {MalformedStylesComponent} from './metadata_resolver_fixture';
|
||||
|
||||
export function main() {
|
||||
describe('RuntimeMetadataResolver', () => {
|
||||
describe('CompileMetadataResolver', () => {
|
||||
beforeEachProviders(() => TEST_PROVIDERS);
|
||||
|
||||
describe('getMetadata', () => {
|
||||
it('should read metadata',
|
||||
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
var meta = resolver.getDirectiveMetadata(ComponentWithEverything);
|
||||
expect(meta.selector).toEqual('someSelector');
|
||||
expect(meta.exportAs).toEqual('someExportAs');
|
||||
@ -67,16 +67,16 @@ export function main() {
|
||||
}));
|
||||
|
||||
it('should use the moduleUrl from the reflector if none is given',
|
||||
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
var value: string =
|
||||
resolver.getDirectiveMetadata(ComponentWithoutModuleId).type.moduleUrl;
|
||||
var expectedEndValue =
|
||||
IS_DART ? 'test/compiler/runtime_metadata_spec.dart' : './ComponentWithoutModuleId';
|
||||
IS_DART ? 'test/compiler/metadata_resolver_spec.dart' : './ComponentWithoutModuleId';
|
||||
expect(value.endsWith(expectedEndValue)).toBe(true);
|
||||
}));
|
||||
|
||||
it('should throw when metadata is incorrectly typed',
|
||||
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
if (!IS_DART) {
|
||||
expect(() => resolver.getDirectiveMetadata(MalformedStylesComponent))
|
||||
.toThrowError(`Expected 'styles' to be an array of strings.`);
|
||||
@ -87,7 +87,7 @@ export function main() {
|
||||
describe('getViewDirectivesMetadata', () => {
|
||||
|
||||
it('should return the directive metadatas',
|
||||
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
|
||||
.toContain(resolver.getDirectiveMetadata(SomeDirective));
|
||||
}));
|
||||
@ -97,7 +97,7 @@ export function main() {
|
||||
() => [provide(PLATFORM_DIRECTIVES, {useValue: [ADirective], multi: true})]);
|
||||
|
||||
it('should include platform directives when available',
|
||||
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
||||
inject([CompileMetadataResolver], (resolver: CompileMetadataResolver) => {
|
||||
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
|
||||
.toContain(resolver.getDirectiveMetadata(ADirective));
|
||||
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
|
@ -1,18 +1,32 @@
|
||||
import {
|
||||
describe,
|
||||
it,
|
||||
expect,
|
||||
} from 'angular2/testing_internal';
|
||||
import {describe, it, iit, expect, ddescribe, beforeEach} from 'angular2/testing_internal';
|
||||
import {IS_DART} from 'angular2/src/facade/lang';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
import {StaticReflector, StaticReflectorHost} from 'angular2/src/compiler/static_reflector';
|
||||
|
||||
export function main() {
|
||||
describe('StaticReflector', () => {
|
||||
it('should get annotations for NgFor', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
// Static reflector is not supported in Dart
|
||||
// as we use reflection to create objects.
|
||||
if (IS_DART) return;
|
||||
|
||||
describe('StaticReflector', () => {
|
||||
let host: StaticReflectorHost;
|
||||
let reflector: StaticReflector;
|
||||
|
||||
beforeEach(() => {
|
||||
host = new MockReflectorHost();
|
||||
reflector = new StaticReflector(host);
|
||||
});
|
||||
|
||||
function singleModuleSimplify(moduleContext: string, value: any) {
|
||||
return reflector.simplify(moduleContext, value, false);
|
||||
}
|
||||
|
||||
function crossModuleSimplify(moduleContext: string, value: any) {
|
||||
return reflector.simplify(moduleContext, value, true);
|
||||
}
|
||||
|
||||
it('should get annotations for NgFor', () => {
|
||||
let NgFor = reflector.getStaticType(
|
||||
host.resolveModule('angular2/src/common/directives/ng_for'), 'NgFor');
|
||||
let annotations = reflector.annotations(NgFor);
|
||||
@ -20,12 +34,10 @@ export function main() {
|
||||
let annotation = annotations[0];
|
||||
expect(annotation.selector).toEqual('[ngFor][ngForOf]');
|
||||
expect(annotation.inputs).toEqual(['ngForTrackBy', 'ngForOf', 'ngForTemplate']);
|
||||
|
||||
});
|
||||
|
||||
it('should get constructor for NgFor', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
let NgFor = reflector.getStaticType(
|
||||
host.resolveModule('angular2/src/common/directives/ng_for'), 'NgFor');
|
||||
let ViewContainerRef = reflector.getStaticType(
|
||||
@ -41,34 +53,32 @@ export function main() {
|
||||
|
||||
let parameters = reflector.parameters(NgFor);
|
||||
expect(parameters)
|
||||
.toEqual([ViewContainerRef, TemplateRef, IterableDiffers, ChangeDetectorRef]);
|
||||
.toEqual([[ViewContainerRef], [TemplateRef], [IterableDiffers], [ChangeDetectorRef]]);
|
||||
});
|
||||
|
||||
it('should get annotations for HeroDetailComponent', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
let HeroDetailComponent =
|
||||
reflector.getStaticType('/src/app/hero-detail.component.ts', 'HeroDetailComponent');
|
||||
let annotations = reflector.annotations(HeroDetailComponent);
|
||||
expect(annotations.length).toEqual(1);
|
||||
let annotation = annotations[0];
|
||||
expect(annotation.selector).toEqual('my-hero-detail');
|
||||
expect(annotation.directives)
|
||||
.toEqual([
|
||||
[
|
||||
reflector.getStaticType(host.resolveModule('angular2/src/common/directives/ng_for'),
|
||||
'NgFor')
|
||||
]
|
||||
]);
|
||||
});
|
||||
|
||||
it('should get and empty annotation list for an unknown class', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
let UnknownClass = reflector.getStaticType('/src/app/app.component.ts', 'UnknownClass');
|
||||
let annotations = reflector.annotations(UnknownClass);
|
||||
expect(annotations).toEqual([]);
|
||||
});
|
||||
|
||||
it('should get propMetadata for HeroDetailComponent', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
let HeroDetailComponent =
|
||||
reflector.getStaticType('/src/app/hero-detail.component.ts', 'HeroDetailComponent');
|
||||
let props = reflector.propMetadata(HeroDetailComponent);
|
||||
@ -76,254 +86,175 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should get an empty object from propMetadata for an unknown class', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
let UnknownClass = reflector.getStaticType('/src/app/app.component.ts', 'UnknownClass');
|
||||
let properties = reflector.propMetadata(UnknownClass);
|
||||
expect(properties).toEqual({});
|
||||
});
|
||||
|
||||
it('should get empty parameters list for an unknown class ', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
let UnknownClass = reflector.getStaticType('/src/app/app.component.ts', 'UnknownClass');
|
||||
let parameters = reflector.parameters(UnknownClass);
|
||||
expect(parameters).toEqual([]);
|
||||
});
|
||||
|
||||
it('should simplify primitive into itself', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', 1)).toBe(1);
|
||||
expect(reflector.simplify('', true)).toBe(true);
|
||||
expect(reflector.simplify('', "some value")).toBe("some value");
|
||||
expect(singleModuleSimplify('', 1)).toBe(1);
|
||||
expect(singleModuleSimplify('', true)).toBe(true);
|
||||
expect(singleModuleSimplify('', "some value")).toBe("some value");
|
||||
});
|
||||
|
||||
it('should simplify an array into a copy of the array', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', [1, 2, 3])).toEqual([1, 2, 3]);
|
||||
});
|
||||
it('should simplify an array into a copy of the array',
|
||||
() => { expect(singleModuleSimplify('', [1, 2, 3])).toEqual([1, 2, 3]); });
|
||||
|
||||
it('should simplify an object to a copy of the object', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
let expr = {a: 1, b: 2, c: 3};
|
||||
expect(reflector.simplify('', expr)).toEqual(expr);
|
||||
expect(singleModuleSimplify('', expr)).toEqual(expr);
|
||||
});
|
||||
|
||||
it('should simplify &&', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '&&', left: true, right: true}))).toBe(true);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '&&', left: true, right: false}))).toBe(false);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '&&', left: false, right: true}))).toBe(false);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '&&', left: false, right: false}))).toBe(false);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '&&', left: true, right: true}))).toBe(true);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '&&', left: true, right: false}))).toBe(false);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '&&', left: false, right: true}))).toBe(false);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '&&', left: false, right: false}))).toBe(false);
|
||||
});
|
||||
|
||||
it('should simplify ||', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '||', left: true, right: true}))).toBe(true);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '||', left: true, right: false}))).toBe(true);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '||', left: false, right: true}))).toBe(true);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '||', left: false, right: false}))).toBe(false);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '||', left: true, right: true}))).toBe(true);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '||', left: true, right: false}))).toBe(true);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '||', left: false, right: true}))).toBe(true);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '||', left: false, right: false}))).toBe(false);
|
||||
});
|
||||
|
||||
it('should simplify &', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '&', left: 0x22, right: 0x0F}))).toBe(0x22 & 0x0F);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '&', left: 0x22, right: 0xF0}))).toBe(0x22 & 0xF0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '&', left: 0x22, right: 0x0F}))).toBe(0x22 & 0x0F);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '&', left: 0x22, right: 0xF0}))).toBe(0x22 & 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify |', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '|', left: 0x22, right: 0x0F}))).toBe(0x22 | 0x0F);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '|', left: 0x22, right: 0xF0}))).toBe(0x22 | 0xF0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '|', left: 0x22, right: 0x0F}))).toBe(0x22 | 0x0F);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '|', left: 0x22, right: 0xF0}))).toBe(0x22 | 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify ^', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '|', left: 0x22, right: 0x0F}))).toBe(0x22 | 0x0F);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '|', left: 0x22, right: 0xF0}))).toBe(0x22 | 0xF0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '|', left: 0x22, right: 0x0F}))).toBe(0x22 | 0x0F);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '|', left: 0x22, right: 0xF0}))).toBe(0x22 | 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify ==', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '==', left: 0x22, right: 0x22}))).toBe(0x22 == 0x22);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '==', left: 0x22, right: 0xF0}))).toBe(0x22 == 0xF0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '==', left: 0x22, right: 0x22}))).toBe(0x22 == 0x22);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '==', left: 0x22, right: 0xF0}))).toBe(0x22 == 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify !=', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '!=', left: 0x22, right: 0x22}))).toBe(0x22 != 0x22);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '!=', left: 0x22, right: 0xF0}))).toBe(0x22 != 0xF0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '!=', left: 0x22, right: 0x22}))).toBe(0x22 != 0x22);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '!=', left: 0x22, right: 0xF0}))).toBe(0x22 != 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify ===', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '===', left: 0x22, right: 0x22}))).toBe(0x22 === 0x22);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '===', left: 0x22, right: 0xF0}))).toBe(0x22 === 0xF0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '===', left: 0x22, right: 0x22}))).toBe(0x22 === 0x22);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '===', left: 0x22, right: 0xF0}))).toBe(0x22 === 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify !==', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '!==', left: 0x22, right: 0x22}))).toBe(0x22 !== 0x22);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '!==', left: 0x22, right: 0xF0}))).toBe(0x22 !== 0xF0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '!==', left: 0x22, right: 0x22}))).toBe(0x22 !== 0x22);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '!==', left: 0x22, right: 0xF0}))).toBe(0x22 !== 0xF0);
|
||||
});
|
||||
|
||||
it('should simplify >', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '>', left: 1, right: 1}))).toBe(1 > 1);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '>', left: 1, right: 0}))).toBe(1 > 0);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '>', left: 0, right: 1}))).toBe(0 > 1);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '>', left: 1, right: 1}))).toBe(1 > 1);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '>', left: 1, right: 0}))).toBe(1 > 0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '>', left: 0, right: 1}))).toBe(0 > 1);
|
||||
});
|
||||
|
||||
it('should simplify >=', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '>=', left: 1, right: 1}))).toBe(1 >= 1);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '>=', left: 1, right: 0}))).toBe(1 >= 0);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '>=', left: 0, right: 1}))).toBe(0 >= 1);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '>=', left: 1, right: 1}))).toBe(1 >= 1);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '>=', left: 1, right: 0}))).toBe(1 >= 0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '>=', left: 0, right: 1}))).toBe(0 >= 1);
|
||||
});
|
||||
|
||||
it('should simplify <=', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '<=', left: 1, right: 1}))).toBe(1 <= 1);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '<=', left: 1, right: 0}))).toBe(1 <= 0);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '<=', left: 0, right: 1}))).toBe(0 <= 1);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '<=', left: 1, right: 1}))).toBe(1 <= 1);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '<=', left: 1, right: 0}))).toBe(1 <= 0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '<=', left: 0, right: 1}))).toBe(0 <= 1);
|
||||
});
|
||||
|
||||
it('should simplify <', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '<', left: 1, right: 1}))).toBe(1 < 1);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '<', left: 1, right: 0}))).toBe(1 < 0);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '<', left: 0, right: 1}))).toBe(0 < 1);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '<', left: 1, right: 1}))).toBe(1 < 1);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '<', left: 1, right: 0}))).toBe(1 < 0);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '<', left: 0, right: 1}))).toBe(0 < 1);
|
||||
});
|
||||
|
||||
it('should simplify <<', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '<<', left: 0x55, right: 2}))).toBe(0x55 << 2);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '<<', left: 0x55, right: 2}))).toBe(0x55 << 2);
|
||||
});
|
||||
|
||||
it('should simplify >>', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '>>', left: 0x55, right: 2}))).toBe(0x55 >> 2);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '>>', left: 0x55, right: 2}))).toBe(0x55 >> 2);
|
||||
});
|
||||
|
||||
it('should simplify +', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '+', left: 0x55, right: 2}))).toBe(0x55 + 2);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '+', left: 0x55, right: 2}))).toBe(0x55 + 2);
|
||||
});
|
||||
|
||||
it('should simplify -', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '-', left: 0x55, right: 2}))).toBe(0x55 - 2);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '-', left: 0x55, right: 2}))).toBe(0x55 - 2);
|
||||
});
|
||||
|
||||
it('should simplify *', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '*', left: 0x55, right: 2}))).toBe(0x55 * 2);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '*', left: 0x55, right: 2}))).toBe(0x55 * 2);
|
||||
});
|
||||
|
||||
it('should simplify /', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '/', left: 0x55, right: 2}))).toBe(0x55 / 2);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '/', left: 0x55, right: 2}))).toBe(0x55 / 2);
|
||||
});
|
||||
|
||||
it('should simplify %', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'binop', operator: '%', left: 0x55, right: 2}))).toBe(0x55 % 2);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'binop', operator: '%', left: 0x55, right: 2}))).toBe(0x55 % 2);
|
||||
});
|
||||
|
||||
it('should simplify prefix -', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'pre', operator: '-', operand: 2}))).toBe(-2);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'pre', operator: '-', operand: 2}))).toBe(-2);
|
||||
});
|
||||
|
||||
it('should simplify prefix ~', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'pre', operator: '~', operand: 2}))).toBe(~2);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'pre', operator: '~', operand: 2}))).toBe(~2);
|
||||
});
|
||||
|
||||
it('should simplify prefix !', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({ __symbolic: 'pre', operator: '!', operand: true}))).toBe(!true);
|
||||
expect(reflector.simplify('', ({ __symbolic: 'pre', operator: '!', operand: false}))).toBe(!false);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'pre', operator: '!', operand: true}))).toBe(!true);
|
||||
expect(singleModuleSimplify('', ({ __symbolic: 'pre', operator: '!', operand: false}))).toBe(!false);
|
||||
});
|
||||
|
||||
it('should simplify an array index', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('', ({__symbolic: "index", expression: [1, 2, 3], index: 2})))
|
||||
expect(singleModuleSimplify('', ({__symbolic: "index", expression: [1, 2, 3], index: 2})))
|
||||
.toBe(3);
|
||||
});
|
||||
|
||||
it('should simplify an object index', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
let expr = {__symbolic: "select", expression: {a: 1, b: 2, c: 3}, member: "b"};
|
||||
expect(reflector.simplify('', expr)).toBe(2);
|
||||
expect(singleModuleSimplify('', expr)).toBe(2);
|
||||
});
|
||||
|
||||
it('should simplify a module reference', () => {
|
||||
let host = new MockReflectorHost();
|
||||
let reflector = new StaticReflector(host);
|
||||
|
||||
expect(reflector.simplify('/src/cases',
|
||||
({__symbolic: "reference", module: "./extern", name: "s"})))
|
||||
it('should simplify a module reference across modules', () => {
|
||||
expect(crossModuleSimplify('/src/cases',
|
||||
({__symbolic: "reference", module: "./extern", name: "s"})))
|
||||
.toEqual("s");
|
||||
});
|
||||
|
||||
it('should simplify a module reference without crossing modules', () => {
|
||||
expect(singleModuleSimplify('/src/cases',
|
||||
({__symbolic: "reference", module: "./extern", name: "s"})))
|
||||
.toEqual(reflector.getStaticType('/src/extern.d.ts', 's'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
class MockReflectorHost implements StaticReflectorHost {
|
||||
// In tests, assume that symbols are not re-exported
|
||||
findDeclaration(modulePath: string,
|
||||
symbolName: string): {declarationPath: string, declaredName: string} {
|
||||
return {declarationPath: modulePath, declaredName: symbolName};
|
||||
}
|
||||
resolveModule(moduleName: string, containingFile?: string): string {
|
||||
function splitPath(path: string): string[] { return path.split(/\/|\\/g); }
|
||||
|
||||
@ -363,68 +294,80 @@ class MockReflectorHost implements StaticReflectorHost {
|
||||
|
||||
getMetadataFor(moduleId: string): any {
|
||||
return {
|
||||
'/tmp/angular2/src/common/directives/ng_for.d.ts':
|
||||
'/tmp/angular2/src/common/forms/directives.d.ts':
|
||||
{
|
||||
"__symbolic": "module",
|
||||
"metadata":
|
||||
"metadata": {
|
||||
"FORM_DIRECTIVES": [
|
||||
{
|
||||
"NgFor":
|
||||
{
|
||||
"__symbolic": "class",
|
||||
"decorators":
|
||||
[
|
||||
{
|
||||
"__symbolic": "call",
|
||||
"expression": {
|
||||
"__symbolic": "reference",
|
||||
"name": "Directive",
|
||||
"module": "../../core/metadata"
|
||||
},
|
||||
"arguments":
|
||||
[
|
||||
"__symbolic": "reference",
|
||||
"name": "NgFor",
|
||||
"module": "angular2/src/common/directives/ng_for"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'/tmp/angular2/src/common/directives/ng_for.d.ts':
|
||||
{
|
||||
"__symbolic": "module",
|
||||
"metadata":
|
||||
{
|
||||
"NgFor":
|
||||
{
|
||||
"__symbolic": "class",
|
||||
"decorators":
|
||||
[
|
||||
{
|
||||
"__symbolic": "call",
|
||||
"expression": {
|
||||
"__symbolic": "reference",
|
||||
"name": "Directive",
|
||||
"module": "../../core/metadata"
|
||||
},
|
||||
"arguments": [
|
||||
{
|
||||
"selector": "[ngFor][ngForOf]",
|
||||
"inputs": ["ngForTrackBy", "ngForOf", "ngForTemplate"]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"members":
|
||||
{
|
||||
"__ctor__": [
|
||||
}
|
||||
],
|
||||
"members":
|
||||
{
|
||||
"__symbolic": "constructor",
|
||||
"parameters":
|
||||
[
|
||||
{
|
||||
"__symbolic": "reference",
|
||||
"module": "../../core/linker/view_container_ref",
|
||||
"name": "ViewContainerRef"
|
||||
},
|
||||
{
|
||||
"__symbolic": "reference",
|
||||
"module": "../../core/linker/template_ref",
|
||||
"name": "TemplateRef"
|
||||
},
|
||||
{
|
||||
"__symbolic": "reference",
|
||||
"module":
|
||||
"../../core/change_detection/differs/iterable_differs",
|
||||
"name": "IterableDiffers"
|
||||
},
|
||||
{
|
||||
"__symbolic": "reference",
|
||||
"module":
|
||||
"../../core/change_detection/change_detector_ref",
|
||||
"name": "ChangeDetectorRef"
|
||||
}
|
||||
]
|
||||
"__ctor__": [
|
||||
{
|
||||
"__symbolic": "constructor",
|
||||
"parameters":
|
||||
[
|
||||
{
|
||||
"__symbolic": "reference",
|
||||
"module": "../../core/linker/view_container_ref",
|
||||
"name": "ViewContainerRef"
|
||||
},
|
||||
{
|
||||
"__symbolic": "reference",
|
||||
"module": "../../core/linker/template_ref",
|
||||
"name": "TemplateRef"
|
||||
},
|
||||
{
|
||||
"__symbolic": "reference",
|
||||
"module":
|
||||
"../../core/change_detection/differs/iterable_differs",
|
||||
"name": "IterableDiffers"
|
||||
},
|
||||
{
|
||||
"__symbolic": "reference",
|
||||
"module":
|
||||
"../../core/change_detection/change_detector_ref",
|
||||
"name": "ChangeDetectorRef"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
'/tmp/angular2/src/core/linker/view_container_ref.d.ts':
|
||||
{"metadata": {"ViewContainerRef": {"__symbolic": "class"}}},
|
||||
'/tmp/angular2/src/core/linker/template_ref.d.ts':
|
||||
@ -453,7 +396,15 @@ class MockReflectorHost implements StaticReflectorHost {
|
||||
"arguments": [
|
||||
{
|
||||
"selector": "my-hero-detail",
|
||||
"template": "\n <div *ngIf=\"hero\">\n <h2>{{hero.name}} details!</h2>\n <div><label>id: </label>{{hero.id}}</div>\n <div>\n <label>name: </label>\n <input [(ngModel)]=\"hero.name\" placeholder=\"name\"/>\n </div>\n </div>\n"
|
||||
"template": "\n <div *ngIf=\"hero\">\n <h2>{{hero.name}} details!</h2>\n <div><label>id: </label>{{hero.id}}</div>\n <div>\n <label>name: </label>\n <input [(ngModel)]=\"hero.name\" placeholder=\"name\"/>\n </div>\n </div>\n",
|
||||
"directives":
|
||||
[
|
||||
{
|
||||
"__symbolic": "reference",
|
||||
"name": "FORM_DIRECTIVES",
|
||||
"module": "angular2/src/common/forms/directives"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user