refactor: replace local namespaced imports with named (#28642)

At the moment, the API extractor doesn't support local namespaced imports, this will break the generation of flat dts files. When we turn on dts bundling for this package it will break. Hence this is the ground work needed for making this package compatable with the API extractor.

See: https://github.com/Microsoft/web-build-tools/issues/1029

Relates to #28588

PR Close #28642
This commit is contained in:
Alan 2019-02-11 11:12:57 +01:00 committed by Igor Minar
parent 599e2e22bc
commit 7c1b9ff5ec
11 changed files with 114 additions and 115 deletions

View File

@ -8,7 +8,7 @@
import {ComponentFactory, ComponentFactoryResolver, Injector, NgZone, Type} from '@angular/core';
import * as angular from './angular1';
import {IAnnotatedFunction, IAttributes, IAugmentedJQuery, ICompileService, IDirective, IInjectorService, INgModelController, IParseService, IScope} from './angular1';
import {$COMPILE, $INJECTOR, $PARSE, INJECTOR_KEY, LAZY_MODULE_REF, REQUIRE_INJECTOR, REQUIRE_NG_MODEL} from './constants';
import {DowngradeComponentAdapter} from './downgrade_component_adapter';
import {LazyModuleRef, UpgradeAppType, controllerKey, getDowngradedModuleCount, getTypeName, getUpgradeAppType, isFunction, validateInjectionKey} from './util';
@ -73,11 +73,8 @@ export function downgradeComponent(info: {
/** @deprecated since v4. This parameter is no longer used */
selectors?: string[];
}): any /* angular.IInjectable */ {
const directiveFactory:
angular.IAnnotatedFunction = function(
$compile: angular.ICompileService,
$injector: angular.IInjectorService,
$parse: angular.IParseService): angular.IDirective {
const directiveFactory: IAnnotatedFunction = function(
$compile: ICompileService, $injector: IInjectorService, $parse: IParseService): IDirective {
// When using `downgradeModule()`, we need to handle certain things specially. For example:
// - We always need to attach the component view to the `ApplicationRef` for it to be
// dirty-checked.
@ -99,13 +96,12 @@ export function downgradeComponent(info: {
restrict: 'E',
terminal: true,
require: [REQUIRE_INJECTOR, REQUIRE_NG_MODEL],
link: (scope: angular.IScope, element: angular.IAugmentedJQuery, attrs: angular.IAttributes,
required: any[]) => {
link: (scope: IScope, element: IAugmentedJQuery, attrs: IAttributes, required: any[]) => {
// We might have to compile the contents asynchronously, because this might have been
// triggered by `UpgradeNg1ComponentAdapterBuilder`, before the Angular templates have
// been compiled.
const ngModel: angular.INgModelController = required[1];
const ngModel: INgModelController = required[1];
const parentInjector: Injector|Thenable<Injector>|undefined = required[0];
let moduleInjector: Injector|Thenable<Injector>|undefined = undefined;
let ranAsync = false;
@ -230,7 +226,7 @@ class ParentInjectorPromise {
private injectorKey: string = controllerKey(INJECTOR_KEY);
private callbacks: ((injector: Injector) => any)[] = [];
constructor(private element: angular.IAugmentedJQuery) {
constructor(private element: IAugmentedJQuery) {
// Store the promise on the element.
element.data !(this.injectorKey, this);
}

View File

@ -8,7 +8,7 @@
import {ApplicationRef, ChangeDetectorRef, ComponentFactory, ComponentRef, EventEmitter, Injector, OnChanges, SimpleChange, SimpleChanges, StaticProvider, Testability, TestabilityRegistry, Type} from '@angular/core';
import * as angular from './angular1';
import {IAttributes, IAugmentedJQuery, ICompileService, IInjectorService, INgModelController, IParseService, IScope} from './angular1';
import {PropertyBinding} from './component_info';
import {$SCOPE} from './constants';
import {getTypeName, hookupNgModel, strictEquals} from './util';
@ -21,7 +21,7 @@ export class DowngradeComponentAdapter {
private implementsOnChanges = false;
private inputChangeCount: number = 0;
private inputChanges: SimpleChanges = {};
private componentScope: angular.IScope;
private componentScope: IScope;
// TODO(issue/24571): remove '!'.
private componentRef !: ComponentRef<any>;
private component: any;
@ -31,11 +31,10 @@ export class DowngradeComponentAdapter {
private viewChangeDetector !: ChangeDetectorRef;
constructor(
private element: angular.IAugmentedJQuery, private attrs: angular.IAttributes,
private scope: angular.IScope, private ngModel: angular.INgModelController,
private parentInjector: Injector, private $injector: angular.IInjectorService,
private $compile: angular.ICompileService, private $parse: angular.IParseService,
private componentFactory: ComponentFactory<any>,
private element: IAugmentedJQuery, private attrs: IAttributes, private scope: IScope,
private ngModel: INgModelController, private parentInjector: Injector,
private $injector: IInjectorService, private $compile: ICompileService,
private $parse: IParseService, private componentFactory: ComponentFactory<any>,
private wrapCallback: <T>(cb: () => T) => () => T) {
this.componentScope = scope.$new();
}

View File

@ -7,7 +7,7 @@
*/
import {Injector} from '@angular/core';
import * as angular from './angular1';
import {IInjectorService} from './angular1';
import {$INJECTOR, INJECTOR_KEY} from './constants';
import {getTypeName, isFunction, validateInjectionKey} from './util';
@ -72,7 +72,7 @@ import {getTypeName, isFunction, validateInjectionKey} from './util';
* @publicApi
*/
export function downgradeInjectable(token: any, downgradedModule: string = ''): Function {
const factory = function($injector: angular.IInjectorService) {
const factory = function($injector: IInjectorService) {
const injectorKey = `${INJECTOR_KEY}${downgradedModule}`;
const injectableName = isFunction(token) ? getTypeName(token) : String(token);
const attemptedAction = `instantiating injectable '${injectableName}'`;

View File

@ -8,11 +8,12 @@
import {ElementRef, Injector, SimpleChanges} from '@angular/core';
import * as angular from './angular1';
import {DirectiveRequireProperty, IAugmentedJQuery, ICloneAttachFunction, ICompileService, IController, IControllerService, IDirective, IHttpBackendService, IInjectorService, ILinkFn, IScope, ITemplateCacheService, SingleOrListOrMap, element as angularElement} from './angular1';
import {$COMPILE, $CONTROLLER, $HTTP_BACKEND, $INJECTOR, $TEMPLATE_CACHE} from './constants';
import {controllerKey, directiveNormalize, isFunction} from './util';
// Constants
const REQUIRE_PREFIX_RE = /^(\^\^?)?(\?)?(\^\^?)?/;
@ -31,29 +32,29 @@ export interface IControllerInstance extends IBindingDestination {
// Classes
export class UpgradeHelper {
public readonly $injector: angular.IInjectorService;
public readonly $injector: IInjectorService;
public readonly element: Element;
public readonly $element: angular.IAugmentedJQuery;
public readonly directive: angular.IDirective;
public readonly $element: IAugmentedJQuery;
public readonly directive: IDirective;
private readonly $compile: angular.ICompileService;
private readonly $controller: angular.IControllerService;
private readonly $compile: ICompileService;
private readonly $controller: IControllerService;
constructor(
private injector: Injector, private name: string, elementRef: ElementRef,
directive?: angular.IDirective) {
directive?: IDirective) {
this.$injector = injector.get($INJECTOR);
this.$compile = this.$injector.get($COMPILE);
this.$controller = this.$injector.get($CONTROLLER);
this.element = elementRef.nativeElement;
this.$element = angular.element(this.element);
this.$element = angularElement(this.element);
this.directive = directive || UpgradeHelper.getDirective(this.$injector, name);
}
static getDirective($injector: angular.IInjectorService, name: string): angular.IDirective {
const directives: angular.IDirective[] = $injector.get(name + 'Directive');
static getDirective($injector: IInjectorService, name: string): IDirective {
const directives: IDirective[] = $injector.get(name + 'Directive');
if (directives.length > 1) {
throw new Error(`Only support single directive definition for: ${name}`);
}
@ -70,12 +71,12 @@ export class UpgradeHelper {
}
static getTemplate(
$injector: angular.IInjectorService, directive: angular.IDirective,
fetchRemoteTemplate = false): string|Promise<string> {
$injector: IInjectorService, directive: IDirective, fetchRemoteTemplate = false): string
|Promise<string> {
if (directive.template !== undefined) {
return getOrCall<string>(directive.template);
} else if (directive.templateUrl) {
const $templateCache = $injector.get($TEMPLATE_CACHE) as angular.ITemplateCacheService;
const $templateCache = $injector.get($TEMPLATE_CACHE) as ITemplateCacheService;
const url = getOrCall<string>(directive.templateUrl);
const template = $templateCache.get(url);
@ -86,7 +87,7 @@ export class UpgradeHelper {
}
return new Promise((resolve, reject) => {
const $httpBackend = $injector.get($HTTP_BACKEND) as angular.IHttpBackendService;
const $httpBackend = $injector.get($HTTP_BACKEND) as IHttpBackendService;
$httpBackend('GET', url, null, (status: number, response: string) => {
if (status === 200) {
resolve($templateCache.put(url, response));
@ -100,7 +101,7 @@ export class UpgradeHelper {
}
}
buildController(controllerType: angular.IController, $scope: angular.IScope) {
buildController(controllerType: IController, $scope: IScope) {
// TODO: Document that we do not pre-assign bindings on the controller instance.
// Quoted properties below so that this code can be optimized with Closure Compiler.
const locals = {'$scope': $scope, '$element': this.$element};
@ -111,7 +112,7 @@ export class UpgradeHelper {
return controller;
}
compileTemplate(template?: string): angular.ILinkFn {
compileTemplate(template?: string): ILinkFn {
if (template === undefined) {
template = UpgradeHelper.getTemplate(this.$injector, this.directive) as string;
}
@ -119,7 +120,7 @@ export class UpgradeHelper {
return this.compileHtml(template);
}
onDestroy($scope: angular.IScope, controllerInstance?: any) {
onDestroy($scope: IScope, controllerInstance?: any) {
if (controllerInstance && isFunction(controllerInstance.$onDestroy)) {
controllerInstance.$onDestroy();
}
@ -131,14 +132,14 @@ export class UpgradeHelper {
// https://github.com/angular/angular.js/blob/26ddc5f830f902a3d22f4b2aab70d86d4d688c82/src/jqLite.js#L306-L312
// `cleanData` will invoke the AngularJS `$destroy` DOM event
// https://github.com/angular/angular.js/blob/26ddc5f830f902a3d22f4b2aab70d86d4d688c82/src/Angular.js#L1911-L1924
angular.element.cleanData([this.element]);
angular.element.cleanData(this.element.querySelectorAll('*'));
angularElement.cleanData([this.element]);
angularElement.cleanData(this.element.querySelectorAll('*'));
}
prepareTransclusion(): angular.ILinkFn|undefined {
prepareTransclusion(): ILinkFn|undefined {
const transclude = this.directive.transclude;
const contentChildNodes = this.extractChildNodes();
const attachChildrenFn: angular.ILinkFn = (scope, cloneAttachFn) => {
const attachChildrenFn: ILinkFn = (scope, cloneAttachFn) => {
// Since AngularJS v1.5.8, `cloneAttachFn` will try to destroy the transclusion scope if
// `$template` is empty. Since the transcluded content comes from Angular, not AngularJS,
// there will be no transclusion scope here.
@ -189,8 +190,9 @@ export class UpgradeHelper {
Object.keys(slots).filter(slotName => slots[slotName]).forEach(slotName => {
const nodes = slots[slotName];
slots[slotName] = (scope: angular.IScope, cloneAttach: angular.ICloneAttachFunction) =>
cloneAttach !(nodes, scope);
slots[slotName] = (scope: IScope, cloneAttach: ICloneAttachFunction) => {
return cloneAttach !(nodes, scope);
};
});
}
@ -231,7 +233,7 @@ export class UpgradeHelper {
return requiredControllers;
}
private compileHtml(html: string): angular.ILinkFn {
private compileHtml(html: string): ILinkFn {
this.element.innerHTML = html;
return this.$compile(this.element.childNodes);
}
@ -248,7 +250,7 @@ export class UpgradeHelper {
return childNodes;
}
private getDirectiveRequire(): angular.DirectiveRequireProperty {
private getDirectiveRequire(): DirectiveRequireProperty {
const require = this.directive.require || (this.directive.controller && this.directive.name) !;
if (isMap(require)) {
@ -266,8 +268,8 @@ export class UpgradeHelper {
return require;
}
private resolveRequire(require: angular.DirectiveRequireProperty, controllerInstance?: any):
angular.SingleOrListOrMap<IControllerInstance>|null {
private resolveRequire(require: DirectiveRequireProperty, controllerInstance?: any):
SingleOrListOrMap<IControllerInstance>|null {
if (!require) {
return null;
} else if (Array.isArray(require)) {
@ -307,7 +309,7 @@ function getOrCall<T>(property: T | Function): T {
}
// NOTE: Only works for `typeof T !== 'object'`.
function isMap<T>(value: angular.SingleOrListOrMap<T>): value is {[key: string]: T} {
function isMap<T>(value: SingleOrListOrMap<T>): value is {[key: string]: T} {
return value && !Array.isArray(value) && typeof value === 'object';
}

View File

@ -7,7 +7,8 @@
*/
import {Injector, Type} from '@angular/core';
import * as angular from './angular1';
import {IInjectorService, INgModelController} from './angular1';
import {DOWNGRADED_MODULE_COUNT_KEY, UPGRADE_APP_TYPE_KEY} from './constants';
const DIRECTIVE_PREFIX_REGEXP = /^(?:x|data)[:\-_]/i;
@ -38,12 +39,12 @@ export function getTypeName(type: Type<any>): string {
return (type as any).overriddenName || type.name || type.toString().split('\n')[0];
}
export function getDowngradedModuleCount($injector: angular.IInjectorService): number {
export function getDowngradedModuleCount($injector: IInjectorService): number {
return $injector.has(DOWNGRADED_MODULE_COUNT_KEY) ? $injector.get(DOWNGRADED_MODULE_COUNT_KEY) :
0;
}
export function getUpgradeAppType($injector: angular.IInjectorService): UpgradeAppType {
export function getUpgradeAppType($injector: IInjectorService): UpgradeAppType {
return $injector.has(UPGRADE_APP_TYPE_KEY) ? $injector.get(UPGRADE_APP_TYPE_KEY) :
UpgradeAppType.None;
}
@ -53,7 +54,7 @@ export function isFunction(value: any): value is Function {
}
export function validateInjectionKey(
$injector: angular.IInjectorService, downgradedModule: string, injectionKey: string,
$injector: IInjectorService, downgradedModule: string, injectionKey: string,
attemptedAction: string): void {
const upgradeAppType = getUpgradeAppType($injector);
const downgradedModuleCount = getDowngradedModuleCount($injector);
@ -141,7 +142,7 @@ function supportsNgModel(component: any) {
* Glue the AngularJS `NgModelController` (if it exists) to the component
* (if it implements the needed subset of the `ControlValueAccessor` interface).
*/
export function hookupNgModel(ngModel: angular.INgModelController, component: any) {
export function hookupNgModel(ngModel: INgModelController, component: any) {
if (ngModel && supportsNgModel(component)) {
ngModel.$render = () => { component.writeValue(ngModel.$viewValue); };
component.registerOnChange(ngModel.$setViewValue.bind(ngModel));

View File

@ -9,7 +9,7 @@
import {Compiler, CompilerOptions, Injector, NgModule, NgModuleRef, NgZone, StaticProvider, Testability, Type, resolveForwardRef} from '@angular/core';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import * as angular from '../common/angular1';
import {IAngularBootstrapConfig, IAugmentedJQuery, IInjectorService, IModule, IProvideService, IRootScopeService, ITestabilityService, bootstrap, element as angularElement, module as angularModule} from '../common/angular1';
import {$$TESTABILITY, $COMPILE, $INJECTOR, $ROOT_SCOPE, COMPILER_KEY, INJECTOR_KEY, LAZY_MODULE_REF, NG_ZONE_KEY, UPGRADE_APP_TYPE_KEY} from '../common/constants';
import {downgradeComponent} from '../common/downgrade_component';
import {downgradeInjectable} from '../common/downgrade_injectable';
@ -117,10 +117,10 @@ export class UpgradeAdapter {
// TODO(issue/24571): remove '!'.
private ngZone !: NgZone;
// TODO(issue/24571): remove '!'.
private ng1Module !: angular.IModule;
private ng1Module !: IModule;
private moduleRef: NgModuleRef<any>|null = null;
// TODO(issue/24571): remove '!'.
private ng2BootstrapDeferred !: Deferred<angular.IInjectorService>;
private ng2BootstrapDeferred !: Deferred<IInjectorService>;
constructor(private ng2AppModule: Type<any>, private compilerOptions?: CompilerOptions) {
if (!ng2AppModule) {
@ -382,7 +382,7 @@ export class UpgradeAdapter {
* });
* ```
*/
bootstrap(element: Element, modules?: any[], config?: angular.IAngularBootstrapConfig):
bootstrap(element: Element, modules?: any[], config?: IAngularBootstrapConfig):
UpgradeAdapterRef {
this.declareNg1Module(modules);
@ -392,7 +392,7 @@ export class UpgradeAdapter {
const windowAngular = (window as any /** TODO #???? */)['angular'];
windowAngular.resumeBootstrap = undefined;
this.ngZone.run(() => { angular.bootstrap(element, [this.ng1Module.name], config !); });
this.ngZone.run(() => { bootstrap(element, [this.ng1Module.name], config !); });
const ng1BootstrapPromise = new Promise((resolve) => {
if (windowAngular.resumeBootstrap) {
const originalResumeBootstrap: () => void = windowAngular.resumeBootstrap;
@ -408,7 +408,7 @@ export class UpgradeAdapter {
});
Promise.all([this.ng2BootstrapDeferred.promise, ng1BootstrapPromise]).then(([ng1Injector]) => {
angular.element(element).data !(controllerKey(INJECTOR_KEY), this.moduleRef !.injector);
angularElement(element).data !(controllerKey(INJECTOR_KEY), this.moduleRef !.injector);
this.moduleRef !.injector.get<NgZone>(NgZone).run(
() => { (<any>upgrade)._bootstrapDone(this.moduleRef, ng1Injector); });
}, onError);
@ -450,7 +450,7 @@ export class UpgradeAdapter {
const token = options && options.asToken || name;
this.upgradedProviders.push({
provide: token,
useFactory: ($injector: angular.IInjectorService) => $injector.get(name),
useFactory: ($injector: IInjectorService) => $injector.get(name),
deps: [$INJECTOR]
});
}
@ -495,13 +495,13 @@ export class UpgradeAdapter {
* upgradeAdapter.declareNg1Module(['heroApp']);
* ```
*/
private declareNg1Module(modules: string[] = []): angular.IModule {
private declareNg1Module(modules: string[] = []): IModule {
const delayApplyExps: Function[] = [];
let original$applyFn: Function;
let rootScopePrototype: any;
let rootScope: angular.IRootScopeService;
let rootScope: IRootScopeService;
const upgradeAdapter = this;
const ng1Module = this.ng1Module = angular.module(this.idPrefix, modules);
const ng1Module = this.ng1Module = angularModule(this.idPrefix, modules);
const platformRef = platformBrowserDynamic();
this.ngZone = new NgZone({enableLongStackTrace: Zone.hasOwnProperty('longStackTraceZoneSpec')});
@ -515,10 +515,10 @@ export class UpgradeAdapter {
.factory(COMPILER_KEY, () => this.moduleRef !.injector.get(Compiler))
.config([
'$provide', '$injector',
(provide: angular.IProvideService, ng1Injector: angular.IInjectorService) => {
(provide: IProvideService, ng1Injector: IInjectorService) => {
provide.decorator($ROOT_SCOPE, [
'$delegate',
function(rootScopeDelegate: angular.IRootScopeService) {
function(rootScopeDelegate: IRootScopeService) {
// Capture the root apply so that we can delay first call to $apply until we
// bootstrap Angular and then we replay and restore the $apply.
rootScopePrototype = rootScopeDelegate.constructor.prototype;
@ -534,7 +534,7 @@ export class UpgradeAdapter {
if (ng1Injector.has($$TESTABILITY)) {
provide.decorator($$TESTABILITY, [
'$delegate',
function(testabilityDelegate: angular.ITestabilityService) {
function(testabilityDelegate: ITestabilityService) {
const originalWhenStable: Function = testabilityDelegate.whenStable;
// Cannot use arrow function below because we need the context
const newWhenStable = function(callback: Function) {
@ -559,7 +559,7 @@ export class UpgradeAdapter {
ng1Module.run([
'$injector', '$rootScope',
(ng1Injector: angular.IInjectorService, rootScope: angular.IRootScopeService) => {
(ng1Injector: IInjectorService, rootScope: IRootScopeService) => {
UpgradeNg1ComponentAdapterBuilder.resolve(this.ng1ComponentsToBeUpgraded, ng1Injector)
.then(() => {
// Note: There is a bug in TS 2.4 that prevents us from
@ -620,7 +620,7 @@ class ParentInjectorPromise {
private injector !: Injector;
private callbacks: ((injector: Injector) => any)[] = [];
constructor(private element: angular.IAugmentedJQuery) {
constructor(private element: IAugmentedJQuery) {
// store the promise on the element
element.data !(controllerKey(INJECTOR_KEY), this);
}
@ -660,13 +660,13 @@ export class UpgradeAdapterRef {
/* @internal */
private _readyFn: ((upgradeAdapterRef?: UpgradeAdapterRef) => void)|null = null;
public ng1RootScope: angular.IRootScopeService = null !;
public ng1Injector: angular.IInjectorService = null !;
public ng1RootScope: IRootScopeService = null !;
public ng1Injector: IInjectorService = null !;
public ng2ModuleRef: NgModuleRef<any> = null !;
public ng2Injector: Injector = null !;
/* @internal */
private _bootstrapDone(ngModuleRef: NgModuleRef<any>, ng1Injector: angular.IInjectorService) {
private _bootstrapDone(ngModuleRef: NgModuleRef<any>, ng1Injector: IInjectorService) {
this.ng2ModuleRef = ngModuleRef;
this.ng2Injector = ngModuleRef.injector;
this.ng1Injector = ng1Injector;

View File

@ -8,7 +8,7 @@
import {Directive, DoCheck, ElementRef, EventEmitter, Inject, Injector, OnChanges, OnDestroy, OnInit, SimpleChange, SimpleChanges, Type} from '@angular/core';
import * as angular from '../common/angular1';
import {IAttributes, IDirective, IDirectivePrePost, IInjectorService, ILinkFn, IScope, ITranscludeFunction} from '../common/angular1';
import {$SCOPE} from '../common/constants';
import {IBindingDestination, IControllerInstance, UpgradeHelper} from '../common/upgrade_helper';
import {isFunction, strictEquals} from '../common/util';
@ -31,7 +31,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
propertyOutputs: string[] = [];
checkProperties: string[] = [];
propertyMap: {[name: string]: string} = {};
directive: angular.IDirective|null = null;
directive: IDirective|null = null;
// TODO(issue/24571): remove '!'.
template !: string;
@ -48,8 +48,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
@Directive({jit: true, ...directive})
class MyClass extends UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck,
OnDestroy {
constructor(
@Inject($SCOPE) scope: angular.IScope, injector: Injector, elementRef: ElementRef) {
constructor(@Inject($SCOPE) scope: IScope, injector: Injector, elementRef: ElementRef) {
super(
new UpgradeHelper(injector, name, elementRef, self.directive || undefined), scope,
self.template, self.inputs, self.outputs, self.propertyOutputs, self.checkProperties,
@ -121,7 +120,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
*/
static resolve(
exportedComponents: {[name: string]: UpgradeNg1ComponentAdapterBuilder},
$injector: angular.IInjectorService): Promise<string[]> {
$injector: IInjectorService): Promise<string[]> {
const promises = Object.keys(exportedComponents).map(name => {
const exportedComponent = exportedComponents[name];
exportedComponent.directive = UpgradeHelper.getDirective($injector, name);
@ -140,13 +139,13 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
private controllerInstance: IControllerInstance|null = null;
destinationObj: IBindingDestination|null = null;
checkLastValues: any[] = [];
directive: angular.IDirective;
directive: IDirective;
element: Element;
$element: any = null;
componentScope: angular.IScope;
componentScope: IScope;
constructor(
private helper: UpgradeHelper, scope: angular.IScope, private template: string,
private helper: UpgradeHelper, scope: IScope, private template: string,
private inputs: string[], private outputs: string[], private propOuts: string[],
private checkProperties: string[], private propertyMap: {[key: string]: string}) {
this.directive = helper.directive;
@ -180,7 +179,7 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
ngOnInit() {
// Collect contents, insert and compile template
const attachChildNodes: angular.ILinkFn|undefined = this.helper.prepareTransclusion();
const attachChildNodes: ILinkFn|undefined = this.helper.prepareTransclusion();
const linkFn = this.helper.compileTemplate(this.template);
// Instantiate controller (if not already done so)
@ -201,10 +200,10 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
// Linking
const link = this.directive.link;
const preLink = (typeof link == 'object') && (link as angular.IDirectivePrePost).pre;
const postLink = (typeof link == 'object') ? (link as angular.IDirectivePrePost).post : link;
const attrs: angular.IAttributes = NOT_SUPPORTED;
const transcludeFn: angular.ITranscludeFunction = NOT_SUPPORTED;
const preLink = (typeof link == 'object') && (link as IDirectivePrePost).pre;
const postLink = (typeof link == 'object') ? (link as IDirectivePrePost).post : link;
const attrs: IAttributes = NOT_SUPPORTED;
const transcludeFn: ITranscludeFunction = NOT_SUPPORTED;
if (preLink) {
preLink(this.componentScope, this.$element, attrs, requiredControllers, transcludeFn);
}

View File

@ -1,3 +1,4 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
@ -6,14 +7,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as angular from '../common/angular1';
import {IInjectorService} from '../common/angular1';
// We have to do a little dance to get the ng1 injector into the module injector.
// We store the ng1 injector so that the provider in the module injector can access it
// Then we "get" the ng1 injector from the module injector, which triggers the provider to read
// the stored injector and release the reference to it.
let tempInjectorRef: angular.IInjectorService|null = null;
export function setTempInjectorRef(injector: angular.IInjectorService) {
let tempInjectorRef: IInjectorService|null = null;
export function setTempInjectorRef(injector: IInjectorService) {
tempInjectorRef = injector;
}
export function injectorFactory() {
@ -21,20 +22,20 @@ export function injectorFactory() {
throw new Error('Trying to get the AngularJS injector before it being set.');
}
const injector: angular.IInjectorService = tempInjectorRef;
const injector: IInjectorService = tempInjectorRef;
tempInjectorRef = null; // clear the value to prevent memory leaks
return injector;
}
export function rootScopeFactory(i: angular.IInjectorService) {
export function rootScopeFactory(i: IInjectorService) {
return i.get('$rootScope');
}
export function compileFactory(i: angular.IInjectorService) {
export function compileFactory(i: IInjectorService) {
return i.get('$compile');
}
export function parseFactory(i: angular.IInjectorService) {
export function parseFactory(i: IInjectorService) {
return i.get('$parse');
}

View File

@ -9,7 +9,7 @@
import {Injector, NgModuleFactory, NgModuleRef, StaticProvider} from '@angular/core';
import {platformBrowser} from '@angular/platform-browser';
import * as angular from '../common/angular1';
import {IInjectorService, IProvideService, module as angularModule} from '../common/angular1';
import {$INJECTOR, $PROVIDE, DOWNGRADED_MODULE_COUNT_KEY, INJECTOR_KEY, LAZY_MODULE_REF, UPGRADE_APP_TYPE_KEY, UPGRADE_MODULE_NAME} from '../common/constants';
import {LazyModuleRef, UpgradeAppType, getDowngradedModuleCount, isFunction} from '../common/util';
@ -143,7 +143,7 @@ export function downgradeModule<T>(
let injector: Injector;
// Create an ng1 module to bootstrap.
angular.module(lazyModuleName, [])
angularModule(lazyModuleName, [])
.constant(UPGRADE_APP_TYPE_KEY, UpgradeAppType.Lite)
.factory(INJECTOR_KEY, [lazyInjectorKey, identity])
.factory(
@ -161,7 +161,7 @@ export function downgradeModule<T>(
lazyModuleRefKey,
[
$INJECTOR,
($injector: angular.IInjectorService) => {
($injector: IInjectorService) => {
setTempInjectorRef($injector);
const result: LazyModuleRef = {
promise: bootstrapFn(angular1Providers).then(ref => {
@ -176,7 +176,7 @@ export function downgradeModule<T>(
])
.config([
$INJECTOR, $PROVIDE,
($injector: angular.IInjectorService, $provide: angular.IProvideService) => {
($injector: IInjectorService, $provide: IProvideService) => {
$provide.constant(DOWNGRADED_MODULE_COUNT_KEY, getDowngradedModuleCount($injector) + 1);
}
]);

View File

@ -7,7 +7,8 @@
*/
import {DoCheck, ElementRef, EventEmitter, Injector, OnChanges, OnDestroy, OnInit, SimpleChanges, ɵlooseIdentical as looseIdentical} from '@angular/core';
import * as angular from '../common/angular1';
import {IAttributes, IAugmentedJQuery, IDirective, IDirectivePrePost, IInjectorService, ILinkFn, IScope, ITranscludeFunction} from '../common/angular1';
import {$SCOPE} from '../common/constants';
import {IBindingDestination, IControllerInstance, UpgradeHelper} from '../common/upgrade_helper';
import {isFunction} from '../common/util';
@ -68,13 +69,13 @@ class Bindings {
export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
private helper: UpgradeHelper;
private $injector: angular.IInjectorService;
private $injector: IInjectorService;
private element: Element;
private $element: angular.IAugmentedJQuery;
private $componentScope: angular.IScope;
private $element: IAugmentedJQuery;
private $componentScope: IScope;
private directive: angular.IDirective;
private directive: IDirective;
private bindings: Bindings;
// TODO(issue/24571): remove '!'.
@ -125,7 +126,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
ngOnInit() {
// Collect contents, insert and compile template
const attachChildNodes: angular.ILinkFn|undefined = this.helper.prepareTransclusion();
const attachChildNodes: ILinkFn|undefined = this.helper.prepareTransclusion();
const linkFn = this.helper.compileTemplate();
// Instantiate controller
@ -167,10 +168,10 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
// Linking
const link = this.directive.link;
const preLink = (typeof link == 'object') && (link as angular.IDirectivePrePost).pre;
const postLink = (typeof link == 'object') ? (link as angular.IDirectivePrePost).post : link;
const attrs: angular.IAttributes = NOT_SUPPORTED;
const transcludeFn: angular.ITranscludeFunction = NOT_SUPPORTED;
const preLink = (typeof link == 'object') && (link as IDirectivePrePost).pre;
const postLink = (typeof link == 'object') ? (link as IDirectivePrePost).post : link;
const attrs: IAttributes = NOT_SUPPORTED;
const transcludeFn: ITranscludeFunction = NOT_SUPPORTED;
if (preLink) {
preLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
}
@ -221,7 +222,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
this.helper.onDestroy(this.$componentScope, this.controllerInstance);
}
private initializeBindings(directive: angular.IDirective) {
private initializeBindings(directive: IDirective) {
const btcIsObject = typeof directive.bindToController === 'object';
if (btcIsObject && Object.keys(directive.scope !).length) {
throw new Error(

View File

@ -8,7 +8,7 @@
import {Injector, NgModule, NgZone, Testability} from '@angular/core';
import * as angular from '../common/angular1';
import {IInjectorService, IIntervalService, IProvideService, ITestabilityService, bootstrap, element as angularElement, module as angularModule} from '../common/angular1';
import {$$TESTABILITY, $DELEGATE, $INJECTOR, $INTERVAL, $PROVIDE, INJECTOR_KEY, LAZY_MODULE_REF, UPGRADE_APP_TYPE_KEY, UPGRADE_MODULE_NAME} from '../common/constants';
import {LazyModuleRef, UpgradeAppType, controllerKey} from '../common/util';
@ -16,6 +16,7 @@ import {angular1Providers, setTempInjectorRef} from './angular1_providers';
import {NgAdapterInjector} from './util';
/**
* @description
*
@ -170,8 +171,7 @@ export class UpgradeModule {
// Create an ng1 module to bootstrap
const initModule =
angular
.module(INIT_MODULE_NAME, [])
angularModule(INIT_MODULE_NAME, [])
.constant(UPGRADE_APP_TYPE_KEY, UpgradeAppType.Static)
@ -183,11 +183,11 @@ export class UpgradeModule {
.config([
$PROVIDE, $INJECTOR,
($provide: angular.IProvideService, $injector: angular.IInjectorService) => {
($provide: IProvideService, $injector: IInjectorService) => {
if ($injector.has($$TESTABILITY)) {
$provide.decorator($$TESTABILITY, [
$DELEGATE,
(testabilityDelegate: angular.ITestabilityService) => {
(testabilityDelegate: ITestabilityService) => {
const originalWhenStable: Function = testabilityDelegate.whenStable;
const injector = this.injector;
// Cannot use arrow function below because we need the context
@ -212,7 +212,7 @@ export class UpgradeModule {
if ($injector.has($INTERVAL)) {
$provide.decorator($INTERVAL, [
$DELEGATE,
(intervalDelegate: angular.IIntervalService) => {
(intervalDelegate: IIntervalService) => {
// Wrap the $interval service so that setInterval is called outside NgZone,
// but the callback is still invoked within it. This is so that $interval
// won't block stability, which preserves the behavior from AngularJS.
@ -240,7 +240,7 @@ export class UpgradeModule {
.run([
$INJECTOR,
($injector: angular.IInjectorService) => {
($injector: IInjectorService) => {
this.$injector = $injector;
// Initialize the ng1 $injector provider
@ -248,7 +248,7 @@ export class UpgradeModule {
this.injector.get($INJECTOR);
// Put the injector on the DOM, so that it can be "required"
angular.element(element).data !(controllerKey(INJECTOR_KEY), this.injector);
angularElement(element).data !(controllerKey(INJECTOR_KEY), this.injector);
// Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
// We need to do this in the next tick so that we don't prevent the bootup
@ -262,14 +262,14 @@ export class UpgradeModule {
}
]);
const upgradeModule = angular.module(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
const upgradeModule = angularModule(UPGRADE_MODULE_NAME, [INIT_MODULE_NAME].concat(modules));
// Make sure resumeBootstrap() only exists if the current bootstrap is deferred
const windowAngular = (window as any)['angular'];
windowAngular.resumeBootstrap = undefined;
// Bootstrap the AngularJS application inside our zone
this.ngZone.run(() => { angular.bootstrap(element, [upgradeModule.name], config); });
this.ngZone.run(() => { bootstrap(element, [upgradeModule.name], config); });
// Patch resumeBootstrap() to run inside the ngZone
if (windowAngular.resumeBootstrap) {