refactor(): use const and let instead of var

This commit is contained in:
Joao Dias
2016-11-12 14:08:58 +01:00
committed by Victor Berchet
parent 73593d4bf3
commit 77ee27c59e
435 changed files with 4637 additions and 4663 deletions

View File

@ -16,7 +16,7 @@ import {ComponentInfo, getComponentInfo} from './metadata';
import {UpgradeNg1ComponentAdapterBuilder} from './upgrade_ng1_adapter';
import {controllerKey, onError} from './util';
var upgradeCount: number = 0;
let upgradeCount: number = 0;
/**
* Use `UpgradeAdapter` to allow AngularJS v1 and Angular v2 to coexist in a single application.
@ -178,7 +178,7 @@ export class UpgradeAdapter {
*/
downgradeNg2Component(type: Type<any>): Function {
this.upgradedComponents.push(type);
var info: ComponentInfo = getComponentInfo(type);
const info: ComponentInfo = getComponentInfo(type);
return ng1ComponentDirective(info, `${this.idPrefix}${info.selector}_c`);
}
@ -316,17 +316,17 @@ export class UpgradeAdapter {
UpgradeAdapterRef {
const ngZone =
new NgZone({enableLongStackTrace: Zone.hasOwnProperty('longStackTraceZoneSpec')});
var upgrade = new UpgradeAdapterRef();
var ng1Injector: angular.IInjectorService = null;
var moduleRef: NgModuleRef<any> = null;
var delayApplyExps: Function[] = [];
var original$applyFn: Function;
var rootScopePrototype: any;
var rootScope: angular.IRootScopeService;
var componentFactoryRefMap: ComponentFactoryRefMap = {};
var ng1Module = angular.module(this.idPrefix, modules);
var ng1BootstrapPromise: Promise<any>;
var ng1compilePromise: Promise<any>;
const upgrade = new UpgradeAdapterRef();
let ng1Injector: angular.IInjectorService = null;
let moduleRef: NgModuleRef<any> = null;
const delayApplyExps: Function[] = [];
let original$applyFn: Function;
let rootScopePrototype: any;
let rootScope: angular.IRootScopeService;
const componentFactoryRefMap: ComponentFactoryRefMap = {};
const ng1Module = angular.module(this.idPrefix, modules);
let ng1BootstrapPromise: Promise<any>;
let ng1compilePromise: Promise<any>;
ng1Module.factory(NG2_INJECTOR, () => moduleRef.injector.get(Injector))
.value(NG2_ZONE, ngZone)
.factory(NG2_COMPILER, () => moduleRef.injector.get(Compiler))
@ -354,11 +354,11 @@ export class UpgradeAdapter {
'$delegate',
function(testabilityDelegate: angular.ITestabilityService) {
var originalWhenStable: Function = testabilityDelegate.whenStable;
var newWhenStable = (callback: Function): void => {
var whenStableContext: any = this;
const originalWhenStable: Function = testabilityDelegate.whenStable;
const newWhenStable = (callback: Function): void => {
const whenStableContext: any = this;
originalWhenStable.call(this, function() {
var ng2Testability: Testability = moduleRef.injector.get(Testability);
const ng2Testability: Testability = moduleRef.injector.get(Testability);
if (ng2Testability.isStable()) {
callback.apply(this, arguments);
} else {
@ -384,7 +384,7 @@ export class UpgradeAdapter {
.then(() => {
// At this point we have ng1 injector and we have lifted ng1 components into ng2, we
// now can bootstrap ng2.
var DynamicNgUpgradeModule =
const DynamicNgUpgradeModule =
NgModule({
providers: [
{provide: NG1_INJECTOR, useFactory: () => ng1Injector},
@ -402,7 +402,7 @@ export class UpgradeAdapter {
DynamicNgUpgradeModule, this.compilerOptions, ngZone,
(componentFactories: ComponentFactory<any>[]) => {
componentFactories.forEach((componentFactory: ComponentFactory<any>) => {
var type: Type<any> = componentFactory.componentType;
const type: Type<any> = componentFactory.componentType;
if (this.upgradedComponents.indexOf(type) !== -1) {
componentFactoryRefMap[getComponentInfo(type).selector] =
componentFactory;
@ -425,13 +425,13 @@ export class UpgradeAdapter {
});
// Make sure resumeBootstrap() only exists if the current bootstrap is deferred
var windowAngular = (window as any /** TODO #???? */)['angular'];
const windowAngular = (window as any /** TODO #???? */)['angular'];
windowAngular.resumeBootstrap = undefined;
ngZone.run(() => { angular.bootstrap(element, [this.idPrefix], config); });
ng1BootstrapPromise = new Promise((resolve) => {
if (windowAngular.resumeBootstrap) {
var originalResumeBootstrap: () => void = windowAngular.resumeBootstrap;
const originalResumeBootstrap: () => void = windowAngular.resumeBootstrap;
windowAngular.resumeBootstrap = function() {
windowAngular.resumeBootstrap = originalResumeBootstrap;
windowAngular.resumeBootstrap.apply(this, arguments);
@ -489,7 +489,7 @@ export class UpgradeAdapter {
* ```
*/
public upgradeNg1Provider(name: string, options?: {asToken: any}) {
var token = options && options.asToken || name;
const token = options && options.asToken || name;
this.providers.push({
provide: token,
useFactory: (ng1Injector: angular.IInjectorService) => ng1Injector.get(name),
@ -519,7 +519,7 @@ export class UpgradeAdapter {
* ```
*/
public downgradeNg2Provider(token: any): Function {
var factory = function(injector: Injector) { return injector.get(token); };
const factory = function(injector: Injector) { return injector.get(token); };
(<any>factory).$inject = [NG2_INJECTOR];
return factory;
}
@ -534,21 +534,21 @@ function ng1ComponentDirective(info: ComponentInfo, idPrefix: string): Function
function directiveFactory(
ng1Injector: angular.IInjectorService, componentFactoryRefMap: ComponentFactoryRefMap,
parse: angular.IParseService): angular.IDirective {
var idCount = 0;
let idCount = 0;
return {
restrict: 'E',
require: REQUIRE_INJECTOR,
link: {
post: (scope: angular.IScope, element: angular.IAugmentedJQuery, attrs: angular.IAttributes,
parentInjector: any, transclude: angular.ITranscludeFunction): void => {
var componentFactory: ComponentFactory<any> = componentFactoryRefMap[info.selector];
const componentFactory: ComponentFactory<any> = componentFactoryRefMap[info.selector];
if (!componentFactory)
throw new Error('Expecting ComponentFactory for: ' + info.selector);
if (parentInjector === null) {
parentInjector = ng1Injector.get(NG2_INJECTOR);
}
var facade = new DowngradeNg2ComponentAdapter(
const facade = new DowngradeNg2ComponentAdapter(
idPrefix + (idCount++), info, element, attrs, scope, <Injector>parentInjector, parse,
componentFactory);
facade.setupInputs();