feat(compiler): generate shallow imports compiler generated references (#14388)

This commit is contained in:
Chuck Jazdzewski 2017-02-14 13:33:06 -08:00 committed by Igor Minar
parent e4e9dbe33d
commit 8b81bb1eb6
14 changed files with 378 additions and 343 deletions

View File

@ -18,6 +18,7 @@ const NODE_MODULES = '/node_modules/';
const IS_GENERATED = /\.(ngfactory|ngstyle)$/; const IS_GENERATED = /\.(ngfactory|ngstyle)$/;
const GENERATED_FILES = /\.ngfactory\.ts$|\.ngstyle\.ts$/; const GENERATED_FILES = /\.ngfactory\.ts$|\.ngstyle\.ts$/;
const GENERATED_OR_DTS_FILES = /\.d\.ts$|\.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 { export interface CompilerHostContext extends ts.ModuleResolutionHost {
readResource(fileName: string): Promise<string>; readResource(fileName: string): Promise<string>;
@ -133,6 +134,9 @@ export class CompilerHost implements AotCompilerHost {
// assume that they are on top of each other. // assume that they are on top of each other.
importedFile = importedFile.replace(this.basePath, this.genDir); importedFile = importedFile.replace(this.basePath, this.genDir);
} }
if (SHALLOW_IMPORT.test(importedFile)) {
return importedFile;
}
return this.dotRelative(containingDir, importedFile); return this.dotRelative(containingDir, importedFile);
} }
} }

View File

@ -42,8 +42,8 @@ export class StaticAndDynamicReflectionCapabilities {
setter(name: string): SetterFn { return this.dynamicDelegate.setter(name); } setter(name: string): SetterFn { return this.dynamicDelegate.setter(name); }
method(name: string): MethodFn { return this.dynamicDelegate.method(name); } method(name: string): MethodFn { return this.dynamicDelegate.method(name); }
importUri(type: any): string { return this.staticDelegate.importUri(type); } importUri(type: any): string { return this.staticDelegate.importUri(type); }
resolveIdentifier(name: string, moduleUrl: string, runtime: any) { resolveIdentifier(name: string, moduleUrl: string, members: string[], runtime: any) {
return this.staticDelegate.resolveIdentifier(name, moduleUrl); return this.staticDelegate.resolveIdentifier(name, moduleUrl, members);
} }
resolveEnum(enumIdentifier: any, name: string): any { resolveEnum(enumIdentifier: any, name: string): any {
if (isStaticType(enumIdentifier)) { if (isStaticType(enumIdentifier)) {

View File

@ -57,8 +57,16 @@ export class StaticReflector implements ReflectorReader {
return staticSymbol ? staticSymbol.filePath : null; return staticSymbol ? staticSymbol.filePath : null;
} }
resolveIdentifier(name: string, moduleUrl: string): StaticSymbol { resolveIdentifier(name: string, moduleUrl: string, members: string[]): StaticSymbol {
return this.findDeclaration(moduleUrl, name); 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 { findDeclaration(moduleUrl: string, name: string, containingFile?: string): StaticSymbol {
@ -77,7 +85,8 @@ export class StaticReflector implements ReflectorReader {
resolveEnum(enumIdentifier: any, name: string): any { resolveEnum(enumIdentifier: any, name: string): any {
const staticSymbol: StaticSymbol = enumIdentifier; 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[] { public annotations(type: StaticSymbol): any[] {

View File

@ -127,6 +127,12 @@ export class StaticSymbolResolver {
return (resolvedSymbol && resolvedSymbol.metadata && resolvedSymbol.metadata.arity) || null; 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 { private _resolveSymbolMembers(staticSymbol: StaticSymbol): ResolvedStaticSymbol {
const members = staticSymbol.members; const members = staticSymbol.members;
const baseResolvedSymbol = const baseResolvedSymbol =

View File

@ -6,448 +6,392 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Injector, LOCALE_ID, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core'; import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Injector, LOCALE_ID, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation, ɵAnimationGroupPlayer, ɵAnimationKeyframe, ɵAnimationSequencePlayer, ɵAnimationStyles, ɵAnimationTransition, ɵAppView, ɵChangeDetectorStatus, ɵCodegenComponentFactoryResolver, ɵComponentRef_, ɵDebugAppView, ɵDebugContext, ɵNgModuleInjector, ɵNoOpAnimationPlayer, ɵStaticNodeDebugInfo, ɵTemplateRef_, ɵValueUnwrapper, ɵViewContainer, ɵViewType, ɵbalanceAnimationKeyframes, ɵclearStyles, ɵcollectAndResolveStyles, ɵdevModeEqual, ɵprepareFinalAnimationStyles, ɵreflector, ɵregisterModuleFactory, ɵrenderStyles, ɵviewEngine, ɵview_utils} from '@angular/core';
import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata'; import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata';
import {AnimationGroupPlayer, AnimationKeyframe, AnimationSequencePlayer, AnimationStyles, AnimationTransition, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, ComponentRef_, DebugAppView, DebugContext, NgModuleInjector, NoOpAnimationPlayer, StaticNodeDebugInfo, TemplateRef_, ValueUnwrapper, ViewContainer, ViewType, balanceAnimationKeyframes, clearStyles, collectAndResolveStyles, devModeEqual, prepareFinalAnimationStyles, reflector, registerModuleFactory, renderStyles, viewEngine, view_utils} from './private_import_core';
const APP_VIEW_MODULE_URL = assetUrl('core', 'linker/view'); const CORE = assetUrl('core');
const VIEW_UTILS_MODULE_URL = assetUrl('core', 'linker/view_utils'); const VIEW_UTILS_MODULE_URL = assetUrl('core', 'linker/view_utils');
const VIEW_ENGINE_MODULE_URL = assetUrl('core', 'view/index');
const CD_MODULE_URL = assetUrl('core', 'change_detection/change_detection');
const ANIMATION_STYLE_UTIL_ASSET_URL = assetUrl('core', 'animation/animation_style_util');
export interface IdentifierSpec { export interface IdentifierSpec {
name: string; name: string;
moduleUrl: string; moduleUrl: string;
member?: string;
runtime: any; runtime: any;
} }
export class Identifiers { export class Identifiers {
static ANALYZE_FOR_ENTRY_COMPONENTS: IdentifierSpec = { static ANALYZE_FOR_ENTRY_COMPONENTS: IdentifierSpec = {
name: 'ANALYZE_FOR_ENTRY_COMPONENTS', name: 'ANALYZE_FOR_ENTRY_COMPONENTS',
moduleUrl: assetUrl('core', 'metadata/di'), moduleUrl: CORE,
runtime: ANALYZE_FOR_ENTRY_COMPONENTS runtime: ANALYZE_FOR_ENTRY_COMPONENTS
}; };
static ViewUtils: IdentifierSpec = { static ViewUtils: IdentifierSpec =
name: 'ViewUtils', {name: 'ɵview_utils', moduleUrl: CORE, member: 'ViewUtils', runtime: ɵview_utils.ViewUtils};
moduleUrl: assetUrl('core', 'linker/view_utils'), static AppView: IdentifierSpec = {name: 'ɵAppView', moduleUrl: CORE, runtime: ɵAppView};
runtime: view_utils.ViewUtils static DebugAppView:
}; IdentifierSpec = {name: 'ɵDebugAppView', moduleUrl: CORE, runtime: ɵDebugAppView};
static AppView: static ViewContainer:
IdentifierSpec = {name: 'AppView', moduleUrl: APP_VIEW_MODULE_URL, runtime: AppView}; IdentifierSpec = {name: 'ɵViewContainer', moduleUrl: CORE, runtime: ɵViewContainer};
static DebugAppView: IdentifierSpec = { static ElementRef: IdentifierSpec = {name: 'ElementRef', moduleUrl: CORE, runtime: ElementRef};
name: 'DebugAppView', static ViewContainerRef:
moduleUrl: APP_VIEW_MODULE_URL, IdentifierSpec = {name: 'ViewContainerRef', moduleUrl: CORE, runtime: ViewContainerRef};
runtime: DebugAppView static ChangeDetectorRef:
}; IdentifierSpec = {name: 'ChangeDetectorRef', moduleUrl: CORE, runtime: ChangeDetectorRef};
static ViewContainer: IdentifierSpec = { static RenderComponentType:
name: 'ViewContainer', IdentifierSpec = {name: 'RenderComponentType', moduleUrl: CORE, runtime: RenderComponentType};
moduleUrl: assetUrl('core', 'linker/view_container'), static QueryList: IdentifierSpec = {name: 'QueryList', moduleUrl: CORE, runtime: QueryList};
runtime: ViewContainer static TemplateRef: IdentifierSpec = {name: 'TemplateRef', moduleUrl: CORE, runtime: TemplateRef};
}; static TemplateRef_:
static ElementRef: IdentifierSpec = { IdentifierSpec = {name: 'ɵTemplateRef_', moduleUrl: CORE, runtime: ɵTemplateRef_};
name: 'ElementRef',
moduleUrl: assetUrl('core', 'linker/element_ref'),
runtime: ElementRef
};
static ViewContainerRef: IdentifierSpec = {
name: 'ViewContainerRef',
moduleUrl: assetUrl('core', 'linker/view_container_ref'),
runtime: ViewContainerRef
};
static ChangeDetectorRef: IdentifierSpec = {
name: 'ChangeDetectorRef',
moduleUrl: assetUrl('core', 'change_detection/change_detector_ref'),
runtime: ChangeDetectorRef
};
static RenderComponentType: IdentifierSpec = {
name: 'RenderComponentType',
moduleUrl: assetUrl('core', 'render/api'),
runtime: RenderComponentType
};
static QueryList: IdentifierSpec = {
name: 'QueryList',
moduleUrl: assetUrl('core', 'linker/query_list'),
runtime: QueryList
};
static TemplateRef: IdentifierSpec = {
name: 'TemplateRef',
moduleUrl: assetUrl('core', 'linker/template_ref'),
runtime: TemplateRef
};
static TemplateRef_: IdentifierSpec = {
name: 'TemplateRef_',
moduleUrl: assetUrl('core', 'linker/template_ref'),
runtime: TemplateRef_
};
static CodegenComponentFactoryResolver: IdentifierSpec = { static CodegenComponentFactoryResolver: IdentifierSpec = {
name: 'CodegenComponentFactoryResolver', name: 'ɵCodegenComponentFactoryResolver',
moduleUrl: assetUrl('core', 'linker/component_factory_resolver'), moduleUrl: CORE,
runtime: CodegenComponentFactoryResolver runtime: ɵCodegenComponentFactoryResolver
}; };
static ComponentFactoryResolver: IdentifierSpec = { static ComponentFactoryResolver: IdentifierSpec = {
name: 'ComponentFactoryResolver', name: 'ComponentFactoryResolver',
moduleUrl: assetUrl('core', 'linker/component_factory_resolver'), moduleUrl: CORE,
runtime: ComponentFactoryResolver runtime: ComponentFactoryResolver
}; };
static ComponentFactory: IdentifierSpec = { static ComponentFactory:
name: 'ComponentFactory', IdentifierSpec = {name: 'ComponentFactory', moduleUrl: CORE, runtime: ComponentFactory};
runtime: ComponentFactory,
moduleUrl: assetUrl('core', 'linker/component_factory')
};
static ComponentRef_: IdentifierSpec = { static ComponentRef_: IdentifierSpec = {
name: 'ComponentRef_', name: 'ɵComponentRef_',
runtime: ComponentRef_, moduleUrl: CORE,
moduleUrl: assetUrl('core', 'linker/component_factory') runtime: ɵComponentRef_,
};
static ComponentRef: IdentifierSpec = {
name: 'ComponentRef',
runtime: ComponentRef,
moduleUrl: assetUrl('core', 'linker/component_factory')
};
static NgModuleFactory: IdentifierSpec = {
name: 'NgModuleFactory',
runtime: NgModuleFactory,
moduleUrl: assetUrl('core', 'linker/ng_module_factory')
}; };
static ComponentRef:
IdentifierSpec = {name: 'ComponentRef', moduleUrl: CORE, runtime: ComponentRef};
static NgModuleFactory:
IdentifierSpec = {name: 'NgModuleFactory', moduleUrl: CORE, runtime: NgModuleFactory};
static NgModuleInjector: IdentifierSpec = { static NgModuleInjector: IdentifierSpec = {
name: 'NgModuleInjector', name: 'ɵNgModuleInjector',
runtime: NgModuleInjector, moduleUrl: CORE,
moduleUrl: assetUrl('core', 'linker/ng_module_factory') runtime: ɵNgModuleInjector,
}; };
static RegisterModuleFactoryFn: IdentifierSpec = { static RegisterModuleFactoryFn: IdentifierSpec = {
name: 'registerModuleFactory', name: 'ɵregisterModuleFactory',
runtime: registerModuleFactory, moduleUrl: CORE,
moduleUrl: assetUrl('core', 'linker/ng_module_factory_loader') runtime: ɵregisterModuleFactory,
}; };
static ValueUnwrapper: static ValueUnwrapper:
IdentifierSpec = {name: 'ValueUnwrapper', moduleUrl: CD_MODULE_URL, runtime: ValueUnwrapper}; IdentifierSpec = {name: 'ɵValueUnwrapper', moduleUrl: CORE, runtime: ɵValueUnwrapper};
static Injector: IdentifierSpec = { static Injector: IdentifierSpec = {name: 'Injector', moduleUrl: CORE, runtime: Injector};
name: 'Injector', static ViewEncapsulation:
moduleUrl: assetUrl('core', 'di/injector'), IdentifierSpec = {name: 'ViewEncapsulation', moduleUrl: CORE, runtime: ViewEncapsulation};
runtime: Injector static ViewType: IdentifierSpec = {name: 'ɵViewType', moduleUrl: CORE, runtime: ɵViewType};
};
static ViewEncapsulation: IdentifierSpec = {
name: 'ViewEncapsulation',
moduleUrl: assetUrl('core', 'metadata/view'),
runtime: ViewEncapsulation
};
static ViewType: IdentifierSpec = {
name: 'ViewType',
moduleUrl: assetUrl('core', 'linker/view_type'),
runtime: ViewType
};
static ChangeDetectionStrategy: IdentifierSpec = { static ChangeDetectionStrategy: IdentifierSpec = {
name: 'ChangeDetectionStrategy', name: 'ChangeDetectionStrategy',
moduleUrl: CD_MODULE_URL, moduleUrl: CORE,
runtime: ChangeDetectionStrategy runtime: ChangeDetectionStrategy
}; };
static StaticNodeDebugInfo: IdentifierSpec = { static StaticNodeDebugInfo: IdentifierSpec = {
name: 'StaticNodeDebugInfo', name: 'ɵStaticNodeDebugInfo',
moduleUrl: assetUrl('core', 'linker/debug_context'), moduleUrl: CORE,
runtime: StaticNodeDebugInfo runtime: ɵStaticNodeDebugInfo
};
static DebugContext: IdentifierSpec = {
name: 'DebugContext',
moduleUrl: assetUrl('core', 'linker/debug_context'),
runtime: DebugContext
};
static Renderer: IdentifierSpec = {
name: 'Renderer',
moduleUrl: assetUrl('core', 'render/api'),
runtime: Renderer
}; };
static DebugContext:
IdentifierSpec = {name: 'ɵDebugContext', moduleUrl: CORE, runtime: ɵDebugContext};
static Renderer: IdentifierSpec = {name: 'Renderer', moduleUrl: CORE, runtime: Renderer};
static SimpleChange: static SimpleChange:
IdentifierSpec = {name: 'SimpleChange', moduleUrl: CD_MODULE_URL, runtime: SimpleChange}; IdentifierSpec = {name: 'SimpleChange', moduleUrl: CORE, runtime: SimpleChange};
static ChangeDetectorStatus: IdentifierSpec = { static ChangeDetectorStatus: IdentifierSpec = {
name: 'ChangeDetectorStatus', name: 'ɵChangeDetectorStatus',
moduleUrl: CD_MODULE_URL, moduleUrl: CORE,
runtime: ChangeDetectorStatus runtime: ɵChangeDetectorStatus
}; };
static checkBinding: IdentifierSpec = { static checkBinding: IdentifierSpec = {
name: 'checkBinding', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.checkBinding member: 'checkBinding',
runtime: ɵview_utils.checkBinding
}; };
static checkBindingChange: IdentifierSpec = { static checkBindingChange: IdentifierSpec = {
name: 'checkBindingChange', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.checkBindingChange member: 'checkBindingChange',
runtime: ɵview_utils.checkBindingChange
}; };
static checkRenderText: IdentifierSpec = { static checkRenderText: IdentifierSpec = {
name: 'checkRenderText', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.checkRenderText member: 'checkRenderText',
runtime: ɵview_utils.checkRenderText
}; };
static checkRenderProperty: IdentifierSpec = { static checkRenderProperty: IdentifierSpec = {
name: 'checkRenderProperty', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.checkRenderProperty member: 'checkRenderProperty',
runtime: ɵview_utils.checkRenderProperty
}; };
static checkRenderAttribute: IdentifierSpec = { static checkRenderAttribute: IdentifierSpec = {
name: 'checkRenderAttribute', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.checkRenderAttribute member: 'checkRenderAttribute',
runtime: ɵview_utils.checkRenderAttribute
}; };
static checkRenderClass: IdentifierSpec = { static checkRenderClass: IdentifierSpec = {
name: 'checkRenderClass', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.checkRenderClass member: 'checkRenderClass',
runtime: ɵview_utils.checkRenderClass
}; };
static checkRenderStyle: IdentifierSpec = { static checkRenderStyle: IdentifierSpec = {
name: 'checkRenderStyle', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.checkRenderStyle member: 'checkRenderStyle',
runtime: ɵview_utils.checkRenderStyle
}; };
static devModeEqual: static devModeEqual:
IdentifierSpec = {name: 'devModeEqual', moduleUrl: CD_MODULE_URL, runtime: devModeEqual}; IdentifierSpec = {name: 'ɵdevModeEqual', moduleUrl: CORE, runtime: ɵdevModeEqual};
static inlineInterpolate: IdentifierSpec = { static inlineInterpolate: IdentifierSpec = {
name: 'inlineInterpolate', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.inlineInterpolate member: 'inlineInterpolate',
runtime: ɵview_utils.inlineInterpolate
}; };
static interpolate: IdentifierSpec = { static interpolate: IdentifierSpec = {
name: 'interpolate', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.interpolate member: 'interpolate',
runtime: ɵview_utils.interpolate
}; };
static castByValue: IdentifierSpec = { static castByValue: IdentifierSpec = {
name: 'castByValue', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.castByValue member: 'castByValue',
runtime: ɵview_utils.castByValue
}; };
static EMPTY_ARRAY: IdentifierSpec = { static EMPTY_ARRAY: IdentifierSpec = {
name: 'EMPTY_ARRAY', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.EMPTY_ARRAY member: 'EMPTY_ARRAY',
}; runtime: ɵview_utils.EMPTY_ARRAY
static EMPTY_MAP: IdentifierSpec = {
name: 'EMPTY_MAP',
moduleUrl: VIEW_UTILS_MODULE_URL,
runtime: view_utils.EMPTY_MAP
}; };
static EMPTY_MAP: IdentifierSpec =
{name: 'ɵview_utils', moduleUrl: CORE, member: 'EMPTY_MAP', runtime: ɵview_utils.EMPTY_MAP};
static createRenderElement: IdentifierSpec = { static createRenderElement: IdentifierSpec = {
name: 'createRenderElement', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.createRenderElement member: 'createRenderElement',
runtime: ɵview_utils.createRenderElement
}; };
static selectOrCreateRenderHostElement: IdentifierSpec = { static selectOrCreateRenderHostElement: IdentifierSpec = {
name: 'selectOrCreateRenderHostElement', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.selectOrCreateRenderHostElement member: 'selectOrCreateRenderHostElement',
runtime: ɵview_utils.selectOrCreateRenderHostElement
}; };
static pureProxies: IdentifierSpec[] = [ static pureProxies: IdentifierSpec[] = [
null, null,
{name: 'pureProxy1', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy1}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy1', runtime: ɵview_utils.pureProxy1},
{name: 'pureProxy2', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy2}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy2', runtime: ɵview_utils.pureProxy2},
{name: 'pureProxy3', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy3}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy3', runtime: ɵview_utils.pureProxy3},
{name: 'pureProxy4', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy4}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy4', runtime: ɵview_utils.pureProxy4},
{name: 'pureProxy5', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy5}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy5', runtime: ɵview_utils.pureProxy5},
{name: 'pureProxy6', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy6}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy6', runtime: ɵview_utils.pureProxy6},
{name: 'pureProxy7', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy7}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy7', runtime: ɵview_utils.pureProxy7},
{name: 'pureProxy8', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy8}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy8', runtime: ɵview_utils.pureProxy8},
{name: 'pureProxy9', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy9}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy9', runtime: ɵview_utils.pureProxy9},
{name: 'pureProxy10', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.pureProxy10}, {name: 'ɵview_utils', moduleUrl: CORE, member: 'pureProxy10', runtime: ɵview_utils.pureProxy10},
]; ];
static SecurityContext: IdentifierSpec = { static SecurityContext: IdentifierSpec = {
name: 'SecurityContext', name: 'SecurityContext',
moduleUrl: assetUrl('core', 'security'), moduleUrl: CORE,
runtime: SecurityContext, runtime: SecurityContext,
}; };
static AnimationKeyframe: IdentifierSpec = { static AnimationKeyframe:
name: 'AnimationKeyframe', IdentifierSpec = {name: 'ɵAnimationKeyframe', moduleUrl: CORE, runtime: ɵAnimationKeyframe};
moduleUrl: assetUrl('core', 'animation/animation_keyframe'), static AnimationStyles:
runtime: AnimationKeyframe IdentifierSpec = {name: 'ɵAnimationStyles', moduleUrl: CORE, runtime: ɵAnimationStyles};
};
static AnimationStyles: IdentifierSpec = {
name: 'AnimationStyles',
moduleUrl: assetUrl('core', 'animation/animation_styles'),
runtime: AnimationStyles
};
static NoOpAnimationPlayer: IdentifierSpec = { static NoOpAnimationPlayer: IdentifierSpec = {
name: 'NoOpAnimationPlayer', name: 'ɵNoOpAnimationPlayer',
moduleUrl: assetUrl('core', 'animation/animation_player'), moduleUrl: CORE,
runtime: NoOpAnimationPlayer runtime: ɵNoOpAnimationPlayer
}; };
static AnimationGroupPlayer: IdentifierSpec = { static AnimationGroupPlayer: IdentifierSpec = {
name: 'AnimationGroupPlayer', name: 'ɵAnimationGroupPlayer',
moduleUrl: assetUrl('core', 'animation/animation_group_player'), moduleUrl: CORE,
runtime: AnimationGroupPlayer runtime: ɵAnimationGroupPlayer
}; };
static AnimationSequencePlayer: IdentifierSpec = { static AnimationSequencePlayer: IdentifierSpec = {
name: 'AnimationSequencePlayer', name: 'ɵAnimationSequencePlayer',
moduleUrl: assetUrl('core', 'animation/animation_sequence_player'), moduleUrl: CORE,
runtime: AnimationSequencePlayer runtime: ɵAnimationSequencePlayer
}; };
static prepareFinalAnimationStyles: IdentifierSpec = { static prepareFinalAnimationStyles: IdentifierSpec = {
name: 'prepareFinalAnimationStyles', name: 'ɵprepareFinalAnimationStyles',
moduleUrl: ANIMATION_STYLE_UTIL_ASSET_URL, moduleUrl: CORE,
runtime: prepareFinalAnimationStyles runtime: ɵprepareFinalAnimationStyles
}; };
static balanceAnimationKeyframes: IdentifierSpec = { static balanceAnimationKeyframes: IdentifierSpec = {
name: 'balanceAnimationKeyframes', name: 'ɵbalanceAnimationKeyframes',
moduleUrl: ANIMATION_STYLE_UTIL_ASSET_URL, moduleUrl: CORE,
runtime: balanceAnimationKeyframes runtime: ɵbalanceAnimationKeyframes
};
static clearStyles: IdentifierSpec = {
name: 'clearStyles',
moduleUrl: ANIMATION_STYLE_UTIL_ASSET_URL,
runtime: clearStyles
};
static renderStyles: IdentifierSpec = {
name: 'renderStyles',
moduleUrl: ANIMATION_STYLE_UTIL_ASSET_URL,
runtime: renderStyles
}; };
static clearStyles:
IdentifierSpec = {name: 'ɵclearStyles', moduleUrl: CORE, runtime: ɵclearStyles};
static renderStyles:
IdentifierSpec = {name: 'ɵrenderStyles', moduleUrl: CORE, runtime: ɵrenderStyles};
static collectAndResolveStyles: IdentifierSpec = { static collectAndResolveStyles: IdentifierSpec = {
name: 'collectAndResolveStyles', name: 'ɵcollectAndResolveStyles',
moduleUrl: ANIMATION_STYLE_UTIL_ASSET_URL, moduleUrl: CORE,
runtime: collectAndResolveStyles runtime: ɵcollectAndResolveStyles
};
static LOCALE_ID: IdentifierSpec = {
name: 'LOCALE_ID',
moduleUrl: assetUrl('core', 'i18n/tokens'),
runtime: LOCALE_ID
};
static TRANSLATIONS_FORMAT: IdentifierSpec = {
name: 'TRANSLATIONS_FORMAT',
moduleUrl: assetUrl('core', 'i18n/tokens'),
runtime: TRANSLATIONS_FORMAT
}; };
static LOCALE_ID: IdentifierSpec = {name: 'LOCALE_ID', moduleUrl: CORE, runtime: LOCALE_ID};
static TRANSLATIONS_FORMAT:
IdentifierSpec = {name: 'TRANSLATIONS_FORMAT', moduleUrl: CORE, runtime: TRANSLATIONS_FORMAT};
static setBindingDebugInfo: IdentifierSpec = { static setBindingDebugInfo: IdentifierSpec = {
name: 'setBindingDebugInfo', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.setBindingDebugInfo member: 'setBindingDebugInfo',
runtime: ɵview_utils.setBindingDebugInfo
}; };
static setBindingDebugInfoForChanges: IdentifierSpec = { static setBindingDebugInfoForChanges: IdentifierSpec = {
name: 'setBindingDebugInfoForChanges', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.setBindingDebugInfoForChanges member: 'setBindingDebugInfoForChanges',
runtime: ɵview_utils.setBindingDebugInfoForChanges
}; };
static AnimationTransition: IdentifierSpec = { static AnimationTransition: IdentifierSpec = {
name: 'AnimationTransition', name: 'ɵAnimationTransition',
moduleUrl: assetUrl('core', 'animation/animation_transition'), moduleUrl: CORE,
runtime: AnimationTransition runtime: ɵAnimationTransition
}; };
// This is just the interface! // This is just the interface!
static InlineArray: static InlineArray:
IdentifierSpec = {name: 'InlineArray', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: null}; IdentifierSpec = {name: 'InlineArray', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: null};
static inlineArrays: IdentifierSpec[] = [ static inlineArrays: IdentifierSpec[] = [
{name: 'InlineArray2', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.InlineArray2}, {
{name: 'InlineArray2', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.InlineArray2}, name: 'ɵview_utils',
{name: 'InlineArray4', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.InlineArray4}, moduleUrl: CORE,
{name: 'InlineArray8', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.InlineArray8}, member: 'InlineArray2',
{name: 'InlineArray16', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.InlineArray16}, runtime: ɵview_utils.InlineArray2
},
{
name: 'ɵview_utils',
moduleUrl: CORE,
member: 'InlineArray2',
runtime: ɵview_utils.InlineArray2
},
{
name: 'ɵview_utils',
moduleUrl: CORE,
member: 'InlineArray4',
runtime: ɵview_utils.InlineArray4
},
{
name: 'ɵview_utils',
moduleUrl: CORE,
member: 'InlineArray8',
runtime: ɵview_utils.InlineArray8
},
{
name: 'ɵview_utils',
moduleUrl: CORE,
member: 'InlineArray16',
runtime: ɵview_utils.InlineArray16
},
]; ];
static EMPTY_INLINE_ARRAY: IdentifierSpec = { static EMPTY_INLINE_ARRAY: IdentifierSpec = {
name: 'EMPTY_INLINE_ARRAY', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.EMPTY_INLINE_ARRAY member: 'EMPTY_INLINE_ARRAY',
runtime: ɵview_utils.EMPTY_INLINE_ARRAY
}; };
static InlineArrayDynamic: IdentifierSpec = { static InlineArrayDynamic: IdentifierSpec = {
name: 'InlineArrayDynamic', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.InlineArrayDynamic member: 'InlineArrayDynamic',
runtime: ɵview_utils.InlineArrayDynamic
}; };
static subscribeToRenderElement: IdentifierSpec = { static subscribeToRenderElement: IdentifierSpec = {
name: 'subscribeToRenderElement', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.subscribeToRenderElement member: 'subscribeToRenderElement',
runtime: ɵview_utils.subscribeToRenderElement
}; };
static createRenderComponentType: IdentifierSpec = { static createRenderComponentType: IdentifierSpec = {
name: 'createRenderComponentType', name: 'ɵview_utils',
moduleUrl: VIEW_UTILS_MODULE_URL, moduleUrl: CORE,
runtime: view_utils.createRenderComponentType member: 'createRenderComponentType',
runtime: ɵview_utils.createRenderComponentType
}; };
static noop:
IdentifierSpec = {name: 'noop', moduleUrl: VIEW_UTILS_MODULE_URL, runtime: view_utils.noop};
static viewDef: IdentifierSpec = {
name: 'viewDef', static noop: IdentifierSpec =
moduleUrl: VIEW_ENGINE_MODULE_URL, {name: 'ɵview_utils', moduleUrl: CORE, member: 'noop', runtime: ɵview_utils.noop};
runtime: viewEngine.viewDef
}; static viewDef: IdentifierSpec =
static elementDef: IdentifierSpec = { {name: 'ɵviewEngine', moduleUrl: CORE, member: 'viewDef', runtime: ɵviewEngine.viewDef};
name: 'elementDef', static elementDef: IdentifierSpec =
moduleUrl: VIEW_ENGINE_MODULE_URL, {name: 'ɵviewEngine', moduleUrl: CORE, member: 'elementDef', runtime: ɵviewEngine.elementDef};
runtime: viewEngine.elementDef static anchorDef: IdentifierSpec =
}; {name: 'ɵviewEngine', moduleUrl: CORE, member: 'anchorDef', runtime: ɵviewEngine.anchorDef};
static anchorDef: IdentifierSpec = { static textDef: IdentifierSpec =
name: 'anchorDef', {name: 'ɵviewEngine', moduleUrl: CORE, member: 'textDef', runtime: ɵviewEngine.textDef};
moduleUrl: VIEW_ENGINE_MODULE_URL,
runtime: viewEngine.anchorDef
};
static textDef: IdentifierSpec = {
name: 'textDef',
moduleUrl: VIEW_ENGINE_MODULE_URL,
runtime: viewEngine.textDef
};
static directiveDef: IdentifierSpec = { static directiveDef: IdentifierSpec = {
name: 'directiveDef', name: 'ɵviewEngine',
moduleUrl: VIEW_ENGINE_MODULE_URL, moduleUrl: CORE,
runtime: viewEngine.directiveDef member: 'directiveDef',
runtime: ɵviewEngine.directiveDef
}; };
static providerDef: IdentifierSpec = { static providerDef: IdentifierSpec = {
name: 'providerDef', name: 'ɵviewEngine',
moduleUrl: VIEW_ENGINE_MODULE_URL, moduleUrl: CORE,
runtime: viewEngine.providerDef member: 'providerDef',
}; runtime: ɵviewEngine.providerDef
static queryDef: IdentifierSpec = {
name: 'queryDef',
moduleUrl: VIEW_ENGINE_MODULE_URL,
runtime: viewEngine.queryDef
}; };
static queryDef: IdentifierSpec =
{name: 'ɵviewEngine', moduleUrl: CORE, member: 'queryDef', runtime: ɵviewEngine.queryDef};
static pureArrayDef: IdentifierSpec = { static pureArrayDef: IdentifierSpec = {
name: 'pureArrayDef', name: 'ɵviewEngine',
moduleUrl: VIEW_ENGINE_MODULE_URL, moduleUrl: CORE,
runtime: viewEngine.pureArrayDef member: 'pureArrayDef',
runtime: ɵviewEngine.pureArrayDef
}; };
static pureObjectDef: IdentifierSpec = { static pureObjectDef: IdentifierSpec = {
name: 'pureObjectDef', name: 'ɵviewEngine',
moduleUrl: VIEW_ENGINE_MODULE_URL, moduleUrl: CORE,
runtime: viewEngine.pureObjectDef member: 'pureObjectDef',
runtime: ɵviewEngine.pureObjectDef
}; };
static purePipeDef: IdentifierSpec = { static purePipeDef: IdentifierSpec = {
name: 'purePipeDef', name: 'ɵviewEngine',
moduleUrl: VIEW_ENGINE_MODULE_URL, moduleUrl: CORE,
runtime: viewEngine.purePipeDef member: 'purePipeDef',
}; runtime: ɵviewEngine.purePipeDef
static pipeDef: IdentifierSpec = {
name: 'pipeDef',
moduleUrl: VIEW_ENGINE_MODULE_URL,
runtime: viewEngine.pipeDef
};
static nodeValue: IdentifierSpec = {
name: 'nodeValue',
moduleUrl: VIEW_ENGINE_MODULE_URL,
runtime: viewEngine.nodeValue
}; };
static pipeDef: IdentifierSpec =
{name: 'ɵviewEngine', moduleUrl: CORE, member: 'pipeDef', runtime: ɵviewEngine.pipeDef};
static nodeValue: IdentifierSpec =
{name: 'ɵviewEngine', moduleUrl: CORE, member: 'nodeValue', runtime: ɵviewEngine.nodeValue};
static unwrapValue: IdentifierSpec = { static unwrapValue: IdentifierSpec = {
name: 'unwrapValue', name: 'ɵviewEngine',
moduleUrl: VIEW_ENGINE_MODULE_URL, moduleUrl: CORE,
runtime: viewEngine.unwrapValue member: 'unwrapValue',
runtime: ɵviewEngine.unwrapValue
}; };
} }
export function assetUrl(pkg: string, path: string = null, type: string = 'src'): string { export function assetUrl(pkg: string, path: string = null, type: string = 'src'): string {
if (path == null) { if (path == null) {
return `@angular/${pkg}/index`; return `@angular/${pkg}`;
} else { } else {
return `@angular/${pkg}/${type}/${path}`; return `@angular/${pkg}/${type}/${path}`;
} }
} }
export function resolveIdentifier(identifier: IdentifierSpec) { export function resolveIdentifier(identifier: IdentifierSpec) {
return reflector.resolveIdentifier(identifier.name, identifier.moduleUrl, identifier.runtime); let name = identifier.name;
let members = identifier.member && [identifier.member];
return ɵreflector.resolveIdentifier(name, identifier.moduleUrl, members, identifier.runtime);
} }
export function createIdentifier(identifier: IdentifierSpec): CompileIdentifierMetadata { export function createIdentifier(identifier: IdentifierSpec): CompileIdentifierMetadata {
const reference = return {reference: resolveIdentifier(identifier)};
reflector.resolveIdentifier(identifier.name, identifier.moduleUrl, identifier.runtime);
return {reference: reference};
} }
export function identifierToken(identifier: CompileIdentifierMetadata): CompileTokenMetadata { export function identifierToken(identifier: CompileIdentifierMetadata): CompileTokenMetadata {
@ -460,6 +404,6 @@ export function createIdentifierToken(identifier: IdentifierSpec): CompileTokenM
export function createEnumIdentifier( export function createEnumIdentifier(
enumType: IdentifierSpec, name: string): CompileIdentifierMetadata { enumType: IdentifierSpec, name: string): CompileIdentifierMetadata {
const resolvedEnum = reflector.resolveEnum(resolveIdentifier(enumType), name); const resolvedEnum = ɵreflector.resolveEnum(resolveIdentifier(enumType), name);
return {reference: resolvedEnum}; return {reference: resolvedEnum};
} }

View File

@ -7,6 +7,7 @@
*/ */
import {AotCompiler, AotCompilerHost, createAotCompiler} from '@angular/compiler'; import {AotCompiler, AotCompilerHost, createAotCompiler} from '@angular/compiler';
import {RenderComponentType} from '@angular/core';
import {async} from '@angular/core/testing'; import {async} from '@angular/core/testing';
import * as path from 'path'; import * as path from 'path';
import * as ts from 'typescript'; import * as ts from 'typescript';
@ -16,20 +17,26 @@ import {EmittingCompilerHost, MockAotCompilerHost, MockCompilerHost, MockData, s
const DTS = /\.d\.ts$/; const DTS = /\.d\.ts$/;
// These are the files that contain the well known annotations. const minCoreIndex = `
const CORE_FILES = [ export * from './src/metadata';
'@angular/core/src/metadata.ts', '@angular/core/src/di/metadata.ts', export * from './src/di/metadata';
'@angular/core/src/di/injection_token.ts', '@angular/core/src/animation/metadata.ts', export * from './src/di/injector';
'@angular/core/src/di/provider.ts', '@angular/core/src/linker/view.ts' export * from './src/di/injection_token';
]; export * from './src/animation/metadata';
export * from './src/linker';
export * from './src/render';
export * from './src/codegen_private_exports';
`;
describe('compiler', () => { describe('compiler', () => {
let angularFiles: Map<string, string>; let angularFiles: Map<string, string>;
beforeAll(() => { beforeAll(() => {
const emittingHost = new EmittingCompilerHost(CORE_FILES); const emittingHost = new EmittingCompilerHost([], {emitMetadata: true});
emittingHost.addScript('@angular/core/index.ts', minCoreIndex);
const emittingProgram = ts.createProgram(emittingHost.scripts, settings, emittingHost); const emittingProgram = ts.createProgram(emittingHost.scripts, settings, emittingHost);
emittingProgram.emit(); emittingProgram.emit();
angularFiles = emittingHost.written; angularFiles = emittingHost.written;
}); });
@ -147,7 +154,8 @@ function summaryCompile(
function compile( function compile(
host: MockCompilerHost, aotHost: AotCompilerHost, preCompile?: (program: ts.Program) => void, host: MockCompilerHost, aotHost: AotCompilerHost, preCompile?: (program: ts.Program) => void,
postCompile: (program: ts.Program) => void = expectNoDiagnostics) { postCompile: (program: ts.Program) => void = expectNoDiagnostics) {
const program = ts.createProgram(host.scriptNames, settings, host); const scripts = host.scriptNames.slice(0);
const program = ts.createProgram(scripts, settings, host);
if (preCompile) preCompile(program); if (preCompile) preCompile(program);
const {compiler, reflector} = createAotCompiler(aotHost, {}); const {compiler, reflector} = createAotCompiler(aotHost, {});
return compiler.compileAll(program.getSourceFiles().map(sf => sf.fileName)) return compiler.compileAll(program.getSourceFiles().map(sf => sf.fileName))
@ -155,7 +163,8 @@ function compile(
generatedFiles.forEach( generatedFiles.forEach(
file => isSource(file.genFileUrl) ? host.addScript(file.genFileUrl, file.source) : file => isSource(file.genFileUrl) ? host.addScript(file.genFileUrl, file.source) :
host.override(file.genFileUrl, file.source)); host.override(file.genFileUrl, file.source));
const newProgram = ts.createProgram(host.scriptNames, settings, host, program); const scripts = host.scriptNames.slice(0);
const newProgram = ts.createProgram(scripts, settings, host);
if (postCompile) postCompile(newProgram); if (postCompile) postCompile(newProgram);
return generatedFiles; return generatedFiles;
}); });
@ -166,7 +175,7 @@ const FILES: MockData = {
quickstart: { quickstart: {
app: { app: {
'app.component.ts': ` 'app.component.ts': `
import {Component} from '@angular/core/src/metadata'; import {Component} from '@angular/core';
@Component({ @Component({
template: '<h1>Hello {{name}}</h1>' template: '<h1>Hello {{name}}</h1>'
@ -176,7 +185,7 @@ const FILES: MockData = {
} }
`, `,
'app.module.ts': ` 'app.module.ts': `
import { NgModule } from '@angular/core/src/metadata'; import { NgModule } from '@angular/core';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';

View File

@ -41,15 +41,18 @@ export const settings: ts.CompilerOptions = {
types: [] types: []
}; };
export interface EmitterOptions { emitMetadata: boolean; }
export class EmittingCompilerHost implements ts.CompilerHost { export class EmittingCompilerHost implements ts.CompilerHost {
private angularSourcePath: string|undefined; private angularSourcePath: string|undefined;
private nodeModulesPath: string|undefined; private nodeModulesPath: string|undefined;
private addedFiles = new Map<string, string>();
private writtenFiles = new Map<string, string>(); private writtenFiles = new Map<string, string>();
private scriptNames: string[]; private scriptNames: string[];
private root = '/'; private root = '/';
private collector = new MetadataCollector(); private collector = new MetadataCollector();
constructor(scriptNames: string[]) { constructor(scriptNames: string[], private options: EmitterOptions) {
const moduleFilename = module.filename.replace(/\\/g, '/'); const moduleFilename = module.filename.replace(/\\/g, '/');
const distIndex = moduleFilename.indexOf('/dist/all'); const distIndex = moduleFilename.indexOf('/dist/all');
if (distIndex >= 0) { if (distIndex >= 0) {
@ -59,13 +62,27 @@ export class EmittingCompilerHost implements ts.CompilerHost {
// Rewrite references to scripts with '@angular' to its corresponding location in // Rewrite references to scripts with '@angular' to its corresponding location in
// the source tree. // the source tree.
this.scriptNames = scriptNames.map( this.scriptNames = scriptNames.map(f => this.effectiveName(f));
f => f.startsWith('@angular/') ? path.join(this.angularSourcePath, f) : f);
this.root = root; this.root = root;
} }
} }
public addScript(fileName: string, content: string) {
const scriptName = this.effectiveName(fileName);
this.addedFiles.set(scriptName, content);
this.scriptNames.push(scriptName);
}
public override(fileName: string, content: string) {
const scriptName = this.effectiveName(fileName);
this.addedFiles.set(scriptName, content);
}
public addWrittenFile(fileName: string, content: string) {
this.writtenFiles.set(this.effectiveName(fileName), content);
}
public getWrittenFiles(): {name: string, content: string}[] { public getWrittenFiles(): {name: string, content: string}[] {
return Array.from(this.writtenFiles).map(f => ({name: f[0], content: f[1]})); return Array.from(this.writtenFiles).map(f => ({name: f[0], content: f[1]}));
} }
@ -74,10 +91,19 @@ export class EmittingCompilerHost implements ts.CompilerHost {
public get written(): Map<string, string> { return this.writtenFiles; } public get written(): Map<string, string> { return this.writtenFiles; }
public effectiveName(fileName: string): string {
return fileName.startsWith('@angular/') ? path.join(this.angularSourcePath, fileName) :
fileName;
}
// ts.ModuleResolutionHost // ts.ModuleResolutionHost
fileExists(fileName: string): boolean { return fs.existsSync(fileName); } fileExists(fileName: string): boolean {
return this.addedFiles.has(fileName) || fs.existsSync(fileName);
}
readFile(fileName: string): string { readFile(fileName: string): string {
const result = this.addedFiles.get(fileName);
if (result) return result;
let basename = path.basename(fileName); let basename = path.basename(fileName);
if (/^lib.*\.d\.ts$/.test(basename)) { if (/^lib.*\.d\.ts$/.test(basename)) {
let libPath = ts.getDefaultLibFilePath(settings); let libPath = ts.getDefaultLibFilePath(settings);
@ -106,7 +132,7 @@ export class EmittingCompilerHost implements ts.CompilerHost {
onError?: (message: string) => void): ts.SourceFile { onError?: (message: string) => void): ts.SourceFile {
const content = this.readFile(fileName); const content = this.readFile(fileName);
if (content) { if (content) {
return ts.createSourceFile(fileName, content, languageVersion); return ts.createSourceFile(fileName, content, languageVersion, /* setParentNodes */ true);
} }
} }
@ -115,11 +141,13 @@ export class EmittingCompilerHost implements ts.CompilerHost {
writeFile: ts.WriteFileCallback = writeFile: ts.WriteFileCallback =
(fileName: string, data: string, writeByteOrderMark: boolean, (fileName: string, data: string, writeByteOrderMark: boolean,
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => { onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
this.writtenFiles.set(fileName, data); this.addWrittenFile(fileName, data);
if (sourceFiles && sourceFiles.length && DTS.test(fileName)) { if (this.options.emitMetadata && sourceFiles && sourceFiles.length && DTS.test(fileName)) {
const metadataFilePath = fileName.replace(DTS, '.metadata.json'); const metadataFilePath = fileName.replace(DTS, '.metadata.json');
const metadata = this.collector.getMetadata(sourceFiles[0]); const metadata = this.collector.getMetadata(sourceFiles[0]);
if (metadata) this.writtenFiles.set(metadataFilePath, JSON.stringify(metadata)); if (metadata) {
this.addWrittenFile(metadataFilePath, JSON.stringify(metadata));
}
} }
} }

View File

@ -0,0 +1,32 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as view_utils from './linker/view_utils';
import * as viewEngine from './view/index';
export {AnimationGroupPlayer as ɵAnimationGroupPlayer} from './animation/animation_group_player';
export {AnimationKeyframe as ɵAnimationKeyframe} from './animation/animation_keyframe';
export {NoOpAnimationPlayer as ɵNoOpAnimationPlayer} from './animation/animation_player';
export {AnimationSequencePlayer as ɵAnimationSequencePlayer} from './animation/animation_sequence_player';
export {balanceAnimationKeyframes as ɵbalanceAnimationKeyframes, clearStyles as ɵclearStyles, collectAndResolveStyles as ɵcollectAndResolveStyles, prepareFinalAnimationStyles as ɵprepareFinalAnimationStyles, renderStyles as ɵrenderStyles} from './animation/animation_style_util';
export {AnimationStyles as ɵAnimationStyles} from './animation/animation_styles';
export {AnimationTransition as ɵAnimationTransition} from './animation/animation_transition';
export {ValueUnwrapper as ɵValueUnwrapper, devModeEqual as ɵdevModeEqual} from './change_detection/change_detection_util';
export {ChangeDetectorStatus as ɵChangeDetectorStatus} from './change_detection/constants';
export {ComponentRef_ as ɵComponentRef_} from './linker/component_factory';
export {CodegenComponentFactoryResolver as ɵCodegenComponentFactoryResolver} from './linker/component_factory_resolver';
export {DebugContext as ɵDebugContext, StaticNodeDebugInfo as ɵStaticNodeDebugInfo} from './linker/debug_context';
export {NgModuleInjector as ɵNgModuleInjector} from './linker/ng_module_factory';
export {registerModuleFactory as ɵregisterModuleFactory} from './linker/ng_module_factory_loader';
export {TemplateRef_ as ɵTemplateRef_} from './linker/template_ref';
export {AppView as ɵAppView, DebugAppView as ɵDebugAppView} from './linker/view';
export {ViewContainer as ɵViewContainer} from './linker/view_container';
export {ViewType as ɵViewType} from './linker/view_type';
export {reflector as ɵreflector} from './reflection/reflection';
export {view_utils as ɵview_utils};
export {viewEngine as ɵviewEngine};

View File

@ -39,3 +39,4 @@ export {AnimationStyles} from './animation/animation_styles';
export {AnimationKeyframe} from './animation/animation_keyframe'; export {AnimationKeyframe} from './animation/animation_keyframe';
export {Sanitizer, SecurityContext} from './security'; export {Sanitizer, SecurityContext} from './security';
export {TransitionFactory, TransitionInstruction, Trigger} from './triggers'; export {TransitionFactory, TransitionInstruction, Trigger} from './triggers';
export * from './codegen_private_exports';

View File

@ -20,6 +20,6 @@ export interface PlatformReflectionCapabilities {
setter(name: string): SetterFn; setter(name: string): SetterFn;
method(name: string): MethodFn; method(name: string): MethodFn;
importUri(type: Type<any>): string; importUri(type: Type<any>): string;
resolveIdentifier(name: string, moduleUrl: string, runtime: any): any; resolveIdentifier(name: string, moduleUrl: string, members: string[], runtime: any): any;
resolveEnum(enumIdentifier: any, name: string): any; resolveEnum(enumIdentifier: any, name: string): any;
} }

View File

@ -227,7 +227,9 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
return `./${stringify(type)}`; return `./${stringify(type)}`;
} }
resolveIdentifier(name: string, moduleUrl: string, runtime: any): any { return runtime; } resolveIdentifier(name: string, moduleUrl: string, members: string[], runtime: any): any {
return runtime;
}
resolveEnum(enumIdentifier: any, name: string): any { return enumIdentifier[name]; } resolveEnum(enumIdentifier: any, name: string): any { return enumIdentifier[name]; }
} }

View File

@ -49,8 +49,8 @@ export class Reflector extends ReflectorReader {
importUri(type: any): string { return this.reflectionCapabilities.importUri(type); } importUri(type: any): string { return this.reflectionCapabilities.importUri(type); }
resolveIdentifier(name: string, moduleUrl: string, runtime: any): any { resolveIdentifier(name: string, moduleUrl: string, members: string[], runtime: any): any {
return this.reflectionCapabilities.resolveIdentifier(name, moduleUrl, runtime); return this.reflectionCapabilities.resolveIdentifier(name, moduleUrl, members, runtime);
} }
resolveEnum(identifier: any, name: string): any { resolveEnum(identifier: any, name: string): any {

View File

@ -15,6 +15,6 @@ export abstract class ReflectorReader {
abstract annotations(typeOrFunc: /*Type*/ any): any[]; abstract annotations(typeOrFunc: /*Type*/ any): any[];
abstract propMetadata(typeOrFunc: /*Type*/ any): {[key: string]: any[]}; abstract propMetadata(typeOrFunc: /*Type*/ any): {[key: string]: any[]};
abstract importUri(typeOrFunc: /*Type*/ any): string; abstract importUri(typeOrFunc: /*Type*/ any): string;
abstract resolveIdentifier(name: string, moduleUrl: string, runtime: any): any; abstract resolveIdentifier(name: string, moduleUrl: string, members: string[], runtime: any): any;
abstract resolveEnum(identifier: any, name: string): any; abstract resolveEnum(identifier: any, name: string): any;
} }

View File

@ -23,7 +23,7 @@ const publicApiArgs = [
'--rootDir', '--rootDir',
'dist/packages-dist', 'dist/packages-dist',
'--stripExportPattern', '--stripExportPattern',
'^__', '^(__|ɵ)',
'--allowModuleIdentifiers', '--allowModuleIdentifiers',
'jasmine', 'jasmine',
'--allowModuleIdentifiers', '--allowModuleIdentifiers',