feat(compiler): implement "enableIvy" compiler option (#21427)

The "enableIvy" compiler option is the initial implementation
of the Render3 (or Ivy) code generation. This commit enables
generation generating "Hello, World" (example in the test)
but not much else. It is currenly only useful for internal Ivy
testing as Ivy is in development.

PR Close #21427
This commit is contained in:
Chuck Jazdzewski
2017-11-20 10:21:17 -08:00
committed by Miško Hevery
parent ce8b5877e2
commit 64d16dee02
27 changed files with 1484 additions and 47 deletions

View File

@ -13,7 +13,9 @@ export type Entry = string | Directory;
export interface Directory { [name: string]: Entry; }
export class MockAotContext {
constructor(public currentDirectory: string, private files: Entry) {}
private files: Entry[];
constructor(public currentDirectory: string, ...files: Entry[]) { this.files = files; }
fileExists(fileName: string): boolean { return typeof this.getEntry(fileName) === 'string'; }
@ -53,19 +55,7 @@ export class MockAotContext {
}
parts.shift();
parts = normalize(parts);
let current = this.files;
while (parts.length) {
const part = parts.shift() !;
if (typeof current === 'string') {
return undefined;
}
const next = (<Directory>current)[part];
if (next === undefined) {
return undefined;
}
current = next;
}
return current;
return first(this.files, files => getEntryFromFiles(parts, files));
}
getDirectories(path: string): string[] {
@ -76,6 +66,31 @@ export class MockAotContext {
return Object.keys(dir).filter(key => typeof dir[key] === 'object');
}
}
override(files: Entry) { return new MockAotContext(this.currentDirectory, files, ...this.files); }
}
function first<T>(a: T[], cb: (value: T) => T | undefined): T|undefined {
for (const value of a) {
const result = cb(value);
if (result != null) return result;
}
}
function getEntryFromFiles(parts: string[], files: Entry) {
let current = files;
while (parts.length) {
const part = parts.shift() !;
if (typeof current === 'string') {
return undefined;
}
const next = (<Directory>current)[part];
if (next === undefined) {
return undefined;
}
current = next;
}
return current;
}
function normalize(parts: string[]): string[] {