chore: move StaticReflector into compiler_cli, part 2

Adjust tests and build to run the unit tests again
after the move.
Closes #8363
This commit is contained in:
Tobias Bosch 2016-04-30 12:27:37 -07:00
parent ab56be46e1
commit 9e05814212
5 changed files with 359 additions and 382 deletions

View File

@ -1060,11 +1060,15 @@ gulp.task('!test.compiler_cli.codegen', function(done) {
} }
}); });
gulp.task('!test.compiler_cli.unit',
function(done) { runJasmineTests(['dist/js/cjs/compiler_cli/**/*_spec.js'], done) });
// End-to-end test for compiler CLI. // End-to-end test for compiler CLI.
// Calls the compiler using its command-line interface, then compiles the app with the codegen. // Calls the compiler using its command-line interface, then compiles the app with the codegen.
// TODO(alexeagle): wire up the playground tests with offline compilation, similar to dart. // TODO(alexeagle): wire up the playground tests with offline compilation, similar to dart.
gulp.task('test.compiler_cli', ['!build.compiler_cli'], gulp.task('test.compiler_cli', ['!build.compiler_cli'], function(done) {
function(done) { runSequence('!test.compiler_cli.codegen', sequenceComplete(done)); }); runSequence('!test.compiler_cli.unit', '!test.compiler_cli.codegen', sequenceComplete(done));
});
// ----------------- // -----------------
// orchestrated targets // orchestrated targets

View File

@ -6,7 +6,7 @@ import * as ts from 'typescript';
import * as path from 'path'; import * as path from 'path';
import * as compiler from 'angular2/compiler'; import * as compiler from 'angular2/compiler';
import {StaticReflector} from 'angular2/src/compiler/static_reflector'; import {StaticReflector} from './static_reflector';
import {CompileMetadataResolver} from 'angular2/src/compiler/metadata_resolver'; import {CompileMetadataResolver} from 'angular2/src/compiler/metadata_resolver';
import {HtmlParser} from 'angular2/src/compiler/html_parser'; import {HtmlParser} from 'angular2/src/compiler/html_parser';
import {DirectiveNormalizer} from 'angular2/src/compiler/directive_normalizer'; import {DirectiveNormalizer} from 'angular2/src/compiler/directive_normalizer';

View File

@ -1,4 +1,4 @@
import {StaticReflectorHost, StaticSymbol} from 'angular2/src/compiler/static_reflector'; import {StaticReflectorHost, StaticSymbol} from './static_reflector';
import * as ts from 'typescript'; import * as ts from 'typescript';
import {MetadataCollector, ModuleMetadata} from 'ts-metadata-collector'; import {MetadataCollector, ModuleMetadata} from 'ts-metadata-collector';
import * as fs from 'fs'; import * as fs from 'fs';

View File

@ -130,7 +130,7 @@ export class StaticReflector implements ReflectorReader {
parameters = []; parameters = [];
ListWrapper.forEachWithIndex(parameterTypes, (paramType, index) => { ListWrapper.forEachWithIndex(parameterTypes, (paramType, index) => {
let nestedResult = []; let nestedResult: any[] = [];
if (isPresent(paramType)) { if (isPresent(paramType)) {
nestedResult.push(paramType); nestedResult.push(paramType);
} }
@ -155,9 +155,9 @@ export class StaticReflector implements ReflectorReader {
private registerDecoratorOrConstructor(type: StaticSymbol, ctor: any): void { private registerDecoratorOrConstructor(type: StaticSymbol, ctor: any): void {
this.conversionMap.set(type, (context: StaticSymbol, args: any[]) => { this.conversionMap.set(type, (context: StaticSymbol, args: any[]) => {
let argValues = []; let argValues: any[] = [];
ListWrapper.forEachWithIndex(args, (arg, index) => { ListWrapper.forEachWithIndex(args, (arg, index) => {
let argValue; let argValue: any;
if (isStringMap(arg) && isBlank(arg['__symbolic'])) { if (isStringMap(arg) && isBlank(arg['__symbolic'])) {
argValue = mapStringMap(arg, (value, key) => this.simplify(context, value)); argValue = mapStringMap(arg, (value, key) => this.simplify(context, value));
} else { } else {
@ -237,7 +237,7 @@ export class StaticReflector implements ReflectorReader {
return expression; return expression;
} }
if (isArray(expression)) { if (isArray(expression)) {
let result = []; let result: any[] = [];
for (let item of(<any>expression)) { for (let item of(<any>expression)) {
result.push(simplify(item)); result.push(simplify(item));
} }
@ -245,7 +245,7 @@ export class StaticReflector implements ReflectorReader {
} }
if (isPresent(expression)) { if (isPresent(expression)) {
if (isPresent(expression['__symbolic'])) { if (isPresent(expression['__symbolic'])) {
let staticSymbol; let staticSymbol: StaticSymbol;
switch (expression['__symbolic']) { switch (expression['__symbolic']) {
case "binop": case "binop":
let left = simplify(expression['left']); let left = simplify(expression['left']);
@ -396,7 +396,7 @@ function isClassMetadata(expression: any): boolean {
function mapStringMap(input: {[key: string]: any}, function mapStringMap(input: {[key: string]: any},
transform: (value: any, key: string) => any): {[key: string]: any} { transform: (value: any, key: string) => any): {[key: string]: any} {
if (isBlank(input)) return {}; if (isBlank(input)) return {};
var result = {}; var result: {[key: string]: any} = {};
StringMapWrapper.keys(input).forEach((key) => { result[key] = transform(input[key], key); }); StringMapWrapper.keys(input).forEach((key) => { result[key] = transform(input[key], key); });
return result; return result;
} }

View File

@ -1,20 +1,13 @@
/// <reference path="../../typings/jasmine/jasmine.d.ts" />
import {describe, it, iit, expect, ddescribe, beforeEach} from 'angular2/testing_internal'; import {describe, it, iit, expect, ddescribe, beforeEach} from 'angular2/testing_internal';
import {IS_DART, isBlank} from 'angular2/src/facade/lang'; import {isBlank} from 'angular2/src/facade/lang';
import {ListWrapper} from 'angular2/src/facade/collection'; import {ListWrapper} from 'angular2/src/facade/collection';
import { import {StaticReflector, StaticReflectorHost, StaticSymbol} from './static_reflector';
StaticReflector,
StaticReflectorHost,
StaticSymbol
} from 'angular2/src/compiler/static_reflector';
export function main() { describe('StaticReflector', () => {
// Static reflector is not supported in Dart
// as we use reflection to create objects.
if (IS_DART) return;
let noContext = new StaticSymbol('', '', ''); let noContext = new StaticSymbol('', '', '');
describe('StaticReflector', () => {
let host: StaticReflectorHost; let host: StaticReflectorHost;
let reflector: StaticReflector; let reflector: StaticReflector;
@ -41,8 +34,7 @@ export function main() {
let NgFor = host.findDeclaration('angular2/src/common/directives/ng_for', 'NgFor'); let NgFor = host.findDeclaration('angular2/src/common/directives/ng_for', 'NgFor');
let ViewContainerRef = let ViewContainerRef =
host.findDeclaration('angular2/src/core/linker/view_container_ref', 'ViewContainerRef'); host.findDeclaration('angular2/src/core/linker/view_container_ref', 'ViewContainerRef');
let TemplateRef = let TemplateRef = host.findDeclaration('angular2/src/core/linker/template_ref', 'TemplateRef');
host.findDeclaration('angular2/src/core/linker/template_ref', 'TemplateRef');
let IterableDiffers = host.findDeclaration( let IterableDiffers = host.findDeclaration(
'angular2/src/core/change_detection/differs/iterable_differs', 'IterableDiffers'); 'angular2/src/core/change_detection/differs/iterable_differs', 'IterableDiffers');
let ChangeDetectorRef = host.findDeclaration( let ChangeDetectorRef = host.findDeclaration(
@ -237,8 +229,7 @@ export function main() {
({__symbolic: "reference", module: "./extern", name: "nonExisting"}))) ({__symbolic: "reference", module: "./extern", name: "nonExisting"})))
.toEqual(host.getStaticSymbol('', '/src/extern.d.ts', 'nonExisting')); .toEqual(host.getStaticSymbol('', '/src/extern.d.ts', 'nonExisting'));
}); });
}); });
}
class MockReflectorHost implements StaticReflectorHost { class MockReflectorHost implements StaticReflectorHost {
private staticTypeCache = new Map<string, StaticSymbol>(); private staticTypeCache = new Map<string, StaticSymbol>();
@ -258,7 +249,7 @@ class MockReflectorHost implements StaticReflectorHost {
function splitPath(path: string): string[] { return path.split(/\/|\\/g); } function splitPath(path: string): string[] { return path.split(/\/|\\/g); }
function resolvePath(pathParts: string[]): string { function resolvePath(pathParts: string[]): string {
let result = []; let result: string[] = [];
ListWrapper.forEachWithIndex(pathParts, (part, index) => { ListWrapper.forEachWithIndex(pathParts, (part, index) => {
switch (part) { switch (part) {
case '': case '':
@ -293,9 +284,8 @@ class MockReflectorHost implements StaticReflectorHost {
} }
getMetadataFor(moduleId: string): any { getMetadataFor(moduleId: string): any {
return { let data: {[key: string]: any} = {
'/tmp/angular2/src/common/forms/directives.d.ts': '/tmp/angular2/src/common/forms/directives.d.ts': {
{
"__symbolic": "module", "__symbolic": "module",
"metadata": { "metadata": {
"FORM_DIRECTIVES": [ "FORM_DIRECTIVES": [
@ -307,16 +297,12 @@ class MockReflectorHost implements StaticReflectorHost {
] ]
} }
}, },
'/tmp/angular2/src/common/directives/ng_for.d.ts': '/tmp/angular2/src/common/directives/ng_for.d.ts': {
{
"__symbolic": "module", "__symbolic": "module",
"metadata": "metadata": {
{ "NgFor": {
"NgFor":
{
"__symbolic": "class", "__symbolic": "class",
"decorators": "decorators": [
[
{ {
"__symbolic": "call", "__symbolic": "call",
"expression": { "expression": {
@ -332,13 +318,11 @@ class MockReflectorHost implements StaticReflectorHost {
] ]
} }
], ],
"members": "members": {
{
"__ctor__": [ "__ctor__": [
{ {
"__symbolic": "constructor", "__symbolic": "constructor",
"parameters": "parameters": [
[
{ {
"__symbolic": "reference", "__symbolic": "reference",
"module": "../../core/linker/view_container_ref", "module": "../../core/linker/view_container_ref",
@ -351,14 +335,12 @@ class MockReflectorHost implements StaticReflectorHost {
}, },
{ {
"__symbolic": "reference", "__symbolic": "reference",
"module": "module": "../../core/change_detection/differs/iterable_differs",
"../../core/change_detection/differs/iterable_differs",
"name": "IterableDiffers" "name": "IterableDiffers"
}, },
{ {
"__symbolic": "reference", "__symbolic": "reference",
"module": "module": "../../core/change_detection/change_detector_ref",
"../../core/change_detection/change_detector_ref",
"name": "ChangeDetectorRef" "name": "ChangeDetectorRef"
} }
] ]
@ -376,16 +358,12 @@ class MockReflectorHost implements StaticReflectorHost {
{"metadata": {"IterableDiffers": {"__symbolic": "class"}}}, {"metadata": {"IterableDiffers": {"__symbolic": "class"}}},
'/tmp/angular2/src/core/change_detection/change_detector_ref.d.ts': '/tmp/angular2/src/core/change_detection/change_detector_ref.d.ts':
{"metadata": {"ChangeDetectorRef": {"__symbolic": "class"}}}, {"metadata": {"ChangeDetectorRef": {"__symbolic": "class"}}},
'/tmp/src/app/hero-detail.component.d.ts': '/tmp/src/app/hero-detail.component.d.ts': {
{
"__symbolic": "module", "__symbolic": "module",
"metadata": "metadata": {
{ "HeroDetailComponent": {
"HeroDetailComponent":
{
"__symbolic": "class", "__symbolic": "class",
"decorators": "decorators": [
[
{ {
"__symbolic": "call", "__symbolic": "call",
"expression": { "expression": {
@ -396,9 +374,9 @@ class MockReflectorHost implements StaticReflectorHost {
"arguments": [ "arguments": [
{ {
"selector": "my-hero-detail", "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":
"directives": "\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", "__symbolic": "reference",
"name": "FORM_DIRECTIVES", "name": "FORM_DIRECTIVES",
@ -409,17 +387,14 @@ class MockReflectorHost implements StaticReflectorHost {
] ]
} }
], ],
"members": "members": {
{
"hero": [ "hero": [
{ {
"__symbolic": "property", "__symbolic": "property",
"decorators": "decorators": [
[
{ {
"__symbolic": "call", "__symbolic": "call",
"expression": "expression": {
{
"__symbolic": "reference", "__symbolic": "reference",
"name": "Input", "name": "Input",
"module": "angular2/src/core/metadata" "module": "angular2/src/core/metadata"
@ -432,10 +407,8 @@ class MockReflectorHost implements StaticReflectorHost {
} }
} }
}, },
'/src/extern.d.ts': { '/src/extern.d.ts': {"__symbolic": "module", metadata: {s: "s"}}
"__symbolic": "module", metadata: { s: "s" } };
} return data[moduleId];
}
[moduleId];
} }
} }