fix(ivy): ensure ngcc compiles @angular/core with correct internal imports (#26236)

PR Close #26236
This commit is contained in:
Pete Bacon Darwin
2018-10-03 16:59:32 +01:00
committed by Jason Aden
parent 807070fe83
commit 83302d193e
20 changed files with 357 additions and 210 deletions

View File

@ -294,7 +294,6 @@ describe('ngtsc metadata', () => {
const host = new TypeScriptReflectionHost(checker);
const result = getDeclaration(program, 'entry.ts', 'target$', ts.isVariableDeclaration);
const res = staticallyResolve(result.initializer !, host, checker);
console.error(res);
expect(res instanceof Reference).toBe(true);
});
});

View File

@ -53,9 +53,9 @@ export class ImportManager {
private moduleToIndex = new Map<string, string>();
private nextIndex = 0;
constructor(private isCore: boolean, private prefix = 'i') {}
constructor(protected isCore: boolean, private prefix = 'i') {}
generateNamedImport(moduleName: string, symbol: string): string {
generateNamedImport(moduleName: string, symbol: string): string|null {
if (!this.moduleToIndex.has(moduleName)) {
this.moduleToIndex.set(moduleName, `${this.prefix}${this.nextIndex++}`);
}
@ -206,13 +206,18 @@ class ExpressionTranslatorVisitor implements ExpressionVisitor, StatementVisitor
}
}
visitExternalExpr(ast: ExternalExpr, context: Context): ts.PropertyAccessExpression {
visitExternalExpr(ast: ExternalExpr, context: Context): ts.PropertyAccessExpression
|ts.Identifier {
if (ast.value.moduleName === null || ast.value.name === null) {
throw new Error(`Import unknown module or symbol ${ast.value}`);
}
return ts.createPropertyAccess(
ts.createIdentifier(this.imports.generateNamedImport(ast.value.moduleName, ast.value.name)),
ts.createIdentifier(ast.value.name));
const importIdentifier = this.imports.generateNamedImport(ast.value.moduleName, ast.value.name);
if (importIdentifier === null) {
return ts.createIdentifier(ast.value.name);
} else {
return ts.createPropertyAccess(
ts.createIdentifier(importIdentifier), ts.createIdentifier(ast.value.name));
}
}
visitConditionalExpr(ast: ConditionalExpr, context: Context): ts.ParenthesizedExpression {