Skip to content

Commit

Permalink
feat(compiler): generate shallow imports compiler generated references (
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckjaz authored and IgorMinar committed Feb 14, 2017
1 parent e4e9dbe commit 8b81bb1
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 346 deletions.
4 changes: 4 additions & 0 deletions modules/@angular/compiler-cli/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const NODE_MODULES = '/node_modules/';
const IS_GENERATED = /\.(ngfactory|ngstyle)$/;
const GENERATED_FILES = /\.ngfactory\.ts$|\.ngstyle\.ts$/;
const GENERATED_OR_DTS_FILES = /\.d\.ts$|\.ngfactory\.ts$|\.ngstyle\.ts$/;
const SHALLOW_IMPORT = /^(\w+|(\@\w+\/\w+))$/;

export interface CompilerHostContext extends ts.ModuleResolutionHost {
readResource(fileName: string): Promise<string>;
Expand Down Expand Up @@ -133,6 +134,9 @@ export class CompilerHost implements AotCompilerHost {
// assume that they are on top of each other.
importedFile = importedFile.replace(this.basePath, this.genDir);
}
if (SHALLOW_IMPORT.test(importedFile)) {
return importedFile;
}
return this.dotRelative(containingDir, importedFile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class StaticAndDynamicReflectionCapabilities {
setter(name: string): SetterFn { return this.dynamicDelegate.setter(name); }
method(name: string): MethodFn { return this.dynamicDelegate.method(name); }
importUri(type: any): string { return this.staticDelegate.importUri(type); }
resolveIdentifier(name: string, moduleUrl: string, runtime: any) {
return this.staticDelegate.resolveIdentifier(name, moduleUrl);
resolveIdentifier(name: string, moduleUrl: string, members: string[], runtime: any) {
return this.staticDelegate.resolveIdentifier(name, moduleUrl, members);
}
resolveEnum(enumIdentifier: any, name: string): any {
if (isStaticType(enumIdentifier)) {
Expand Down
15 changes: 12 additions & 3 deletions modules/@angular/compiler/src/aot/static_reflector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,16 @@ export class StaticReflector implements ReflectorReader {
return staticSymbol ? staticSymbol.filePath : null;
}

resolveIdentifier(name: string, moduleUrl: string): StaticSymbol {
return this.findDeclaration(moduleUrl, name);
resolveIdentifier(name: string, moduleUrl: string, members: string[]): StaticSymbol {
const importSymbol = this.getStaticSymbol(moduleUrl, name);
const rootSymbol = this.findDeclaration(moduleUrl, name);
if (importSymbol != rootSymbol) {
this.symbolResolver.recordImportAs(rootSymbol, importSymbol);
}
if (members && members.length) {
return this.getStaticSymbol(rootSymbol.filePath, rootSymbol.name, members);
}
return rootSymbol;
}

findDeclaration(moduleUrl: string, name: string, containingFile?: string): StaticSymbol {
Expand All @@ -77,7 +85,8 @@ export class StaticReflector implements ReflectorReader {

resolveEnum(enumIdentifier: any, name: string): any {
const staticSymbol: StaticSymbol = enumIdentifier;
return this.getStaticSymbol(staticSymbol.filePath, staticSymbol.name, [name]);
const members = (staticSymbol.members || []).concat(name);
return this.getStaticSymbol(staticSymbol.filePath, staticSymbol.name, members);
}

public annotations(type: StaticSymbol): any[] {
Expand Down
6 changes: 6 additions & 0 deletions modules/@angular/compiler/src/aot/static_symbol_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ export class StaticSymbolResolver {
return (resolvedSymbol && resolvedSymbol.metadata && resolvedSymbol.metadata.arity) || null;
}

recordImportAs(sourceSymbol: StaticSymbol, targetSymbol: StaticSymbol) {
sourceSymbol.assertNoMembers();
targetSymbol.assertNoMembers();
this.importAs.set(sourceSymbol, targetSymbol);
}

private _resolveSymbolMembers(staticSymbol: StaticSymbol): ResolvedStaticSymbol {
const members = staticSymbol.members;
const baseResolvedSymbol =
Expand Down
Loading

0 comments on commit 8b81bb1

Please sign in to comment.