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

@ -162,7 +162,7 @@ function noNg() {
throw new Error('AngularJS v1.x is not loaded!');
}
var angular: {
let angular: {
bootstrap: (e: Element, modules: (string | IInjectable)[], config: IAngularBootstrapConfig) =>
void,
module: (prefix: string, dependencies?: string[]) => IModule,

View File

@ -39,7 +39,7 @@ export class DowngradeComponentAdapter {
}
createComponent() {
var childInjector = ReflectiveInjector.resolveAndCreate(
const childInjector = ReflectiveInjector.resolveAndCreate(
[{provide: $SCOPE, useValue: this.componentScope}], this.parentInjector);
this.contentInsertionPoint = document.createComment('ng1 insertion point');
@ -50,15 +50,15 @@ export class DowngradeComponentAdapter {
}
setupInputs(): void {
var attrs = this.attrs;
var inputs = this.info.inputs || [];
for (var i = 0; i < inputs.length; i++) {
var input = new PropertyBinding(inputs[i]);
var expr: any /** TODO #9100 */ = null;
const attrs = this.attrs;
const inputs = this.info.inputs || [];
for (let i = 0; i < inputs.length; i++) {
const input = new PropertyBinding(inputs[i]);
let expr: any /** TODO #9100 */ = null;
if (attrs.hasOwnProperty(input.attr)) {
var observeFn = ((prop: any /** TODO #9100 */) => {
var prevValue = INITIAL_VALUE;
const observeFn = ((prop: any /** TODO #9100 */) => {
let prevValue = INITIAL_VALUE;
return (value: any /** TODO #9100 */) => {
if (this.inputChanges !== null) {
this.inputChangeCount++;
@ -81,7 +81,7 @@ export class DowngradeComponentAdapter {
expr = (attrs as any /** TODO #9100 */)[input.bracketParenAttr];
}
if (expr != null) {
var watchFn =
const watchFn =
((prop: any /** TODO #9100 */) =>
(value: any /** TODO #9100 */, prevValue: any /** TODO #9100 */) => {
if (this.inputChanges != null) {
@ -94,12 +94,12 @@ export class DowngradeComponentAdapter {
}
}
var prototype = this.info.component.prototype;
const prototype = this.info.component.prototype;
if (prototype && (<OnChanges>prototype).ngOnChanges) {
// Detect: OnChanges interface
this.inputChanges = {};
this.componentScope.$watch(() => this.inputChangeCount, () => {
var inputChanges = this.inputChanges;
const inputChanges = this.inputChanges;
this.inputChanges = {};
(<OnChanges>this.component).ngOnChanges(inputChanges);
});
@ -108,26 +108,26 @@ export class DowngradeComponentAdapter {
}
projectContent() {
var childNodes = this.childNodes;
var parent = this.contentInsertionPoint.parentNode;
const childNodes = this.childNodes;
const parent = this.contentInsertionPoint.parentNode;
if (parent) {
for (var i = 0, ii = childNodes.length; i < ii; i++) {
for (let i = 0, ii = childNodes.length; i < ii; i++) {
parent.insertBefore(childNodes[i], this.contentInsertionPoint);
}
}
}
setupOutputs() {
var attrs = this.attrs;
var outputs = this.info.outputs || [];
for (var j = 0; j < outputs.length; j++) {
var output = new PropertyBinding(outputs[j]);
var expr: any /** TODO #9100 */ = null;
var assignExpr = false;
const attrs = this.attrs;
const outputs = this.info.outputs || [];
for (let j = 0; j < outputs.length; j++) {
const output = new PropertyBinding(outputs[j]);
let expr: any /** TODO #9100 */ = null;
let assignExpr = false;
var bindonAttr =
const bindonAttr =
output.bindonAttr ? output.bindonAttr.substring(0, output.bindonAttr.length - 6) : null;
var bracketParenAttr = output.bracketParenAttr ?
const bracketParenAttr = output.bracketParenAttr ?
`[(${output.bracketParenAttr.substring(2, output.bracketParenAttr.length - 8)})]` :
null;
@ -144,12 +144,12 @@ export class DowngradeComponentAdapter {
}
if (expr != null && assignExpr != null) {
var getter = this.parse(expr);
var setter = getter.assign;
const getter = this.parse(expr);
const setter = getter.assign;
if (assignExpr && !setter) {
throw new Error(`Expression '${expr}' is not assignable!`);
}
var emitter = this.component[output.prop] as EventEmitter<any>;
const emitter = this.component[output.prop] as EventEmitter<any>;
if (emitter) {
emitter.subscribe({
next: assignExpr ?

View File

@ -103,7 +103,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
const attrs: angular.IAttributes = NOT_SUPPORTED;
const transcludeFn: angular.ITranscludeFunction = NOT_SUPPORTED;
const directiveRequire = this.getDirectiveRequire(this.directive);
let requiredControllers =
const requiredControllers =
this.resolveRequire(this.directive.name, this.$element, directiveRequire);
if (this.directive.bindToController && isMap(directiveRequire)) {
@ -122,8 +122,8 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
preLink(this.$componentScope, this.$element, attrs, requiredControllers, transcludeFn);
}
var childNodes: Node[] = [];
var childNode: Node;
const childNodes: Node[] = [];
let childNode: Node;
while (childNode = this.element.firstChild) {
this.element.removeChild(childNode);
childNodes.push(childNode);
@ -249,7 +249,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
bindings.propertyToOutputMap[propName] = propName;
break;
default:
var json = JSON.stringify(context);
let json = JSON.stringify(context);
throw new Error(
`Unexpected mapping '${bindingType}' in '${json}' in '${this.name}' directive.`);
}
@ -263,8 +263,8 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
if (this.directive.template !== undefined) {
return this.compileHtml(getOrCall(this.directive.template));
} else if (this.directive.templateUrl) {
var url = getOrCall(this.directive.templateUrl);
var html = this.$templateCache.get(url) as string;
const url = getOrCall(this.directive.templateUrl);
const html = this.$templateCache.get(url) as string;
if (html !== undefined) {
return this.compileHtml(html);
} else {
@ -288,8 +288,8 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy {
controllerType: angular.IController, $scope: angular.IScope,
$element: angular.IAugmentedJQuery, controllerAs: string) {
// TODO: Document that we do not pre-assign bindings on the controller instance
var locals = {$scope, $element};
var controller = this.$controller(controllerType, locals, null, controllerAs);
const locals = {$scope, $element};
const controller = this.$controller(controllerType, locals, null, controllerAs);
$element.data(controllerKey(this.directive.name), controller);
return controller;
}

View File

@ -53,7 +53,7 @@ export class UpgradeModule {
angular.element(element).data(controllerKey(INJECTOR_KEY), this.injector);
// Wire up the ng1 rootScope to run a digest cycle whenever the zone settles
var $rootScope = $injector.get('$rootScope');
const $rootScope = $injector.get('$rootScope');
this.ngZone.onMicrotaskEmpty.subscribe(
() => this.ngZone.runOutsideAngular(() => $rootScope.$evalAsync()));
}

View File

@ -37,7 +37,7 @@ export class DowngradeNg2ComponentAdapter {
}
bootstrapNg2() {
var childInjector = ReflectiveInjector.resolveAndCreate(
const childInjector = ReflectiveInjector.resolveAndCreate(
[{provide: NG1_SCOPE, useValue: this.componentScope}], this.parentInjector);
this.contentInsertionPoint = document.createComment('ng1 insertion point');
@ -48,14 +48,14 @@ export class DowngradeNg2ComponentAdapter {
}
setupInputs(): void {
var attrs = this.attrs;
var inputs = this.info.inputs || [];
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
var expr: any /** TODO #9100 */ = null;
const attrs = this.attrs;
const inputs = this.info.inputs || [];
for (let i = 0; i < inputs.length; i++) {
const input = inputs[i];
let expr: any /** TODO #9100 */ = null;
if (attrs.hasOwnProperty(input.attr)) {
var observeFn = ((prop: any /** TODO #9100 */) => {
var prevValue = INITIAL_VALUE;
const observeFn = ((prop: any /** TODO #9100 */) => {
let prevValue = INITIAL_VALUE;
return (value: any /** TODO #9100 */) => {
if (this.inputChanges !== null) {
this.inputChangeCount++;
@ -77,7 +77,7 @@ export class DowngradeNg2ComponentAdapter {
expr = (attrs as any /** TODO #9100 */)[input.bracketParenAttr];
}
if (expr != null) {
var watchFn =
const watchFn =
((prop: any /** TODO #9100 */) =>
(value: any /** TODO #9100 */, prevValue: any /** TODO #9100 */) => {
if (this.inputChanges != null) {
@ -90,12 +90,12 @@ export class DowngradeNg2ComponentAdapter {
}
}
var prototype = this.info.type.prototype;
const prototype = this.info.type.prototype;
if (prototype && (<OnChanges>prototype).ngOnChanges) {
// Detect: OnChanges interface
this.inputChanges = {};
this.componentScope.$watch(() => this.inputChangeCount, () => {
var inputChanges = this.inputChanges;
const inputChanges = this.inputChanges;
this.inputChanges = {};
(<OnChanges>this.component).ngOnChanges(inputChanges);
});
@ -104,26 +104,26 @@ export class DowngradeNg2ComponentAdapter {
}
projectContent() {
var childNodes = this.childNodes;
var parent = this.contentInsertionPoint.parentNode;
const childNodes = this.childNodes;
const parent = this.contentInsertionPoint.parentNode;
if (parent) {
for (var i = 0, ii = childNodes.length; i < ii; i++) {
for (let i = 0, ii = childNodes.length; i < ii; i++) {
parent.insertBefore(childNodes[i], this.contentInsertionPoint);
}
}
}
setupOutputs() {
var attrs = this.attrs;
var outputs = this.info.outputs || [];
for (var j = 0; j < outputs.length; j++) {
var output = outputs[j];
var expr: any /** TODO #9100 */ = null;
var assignExpr = false;
const attrs = this.attrs;
const outputs = this.info.outputs || [];
for (let j = 0; j < outputs.length; j++) {
const output = outputs[j];
let expr: any /** TODO #9100 */ = null;
let assignExpr = false;
var bindonAttr =
const bindonAttr =
output.bindonAttr ? output.bindonAttr.substring(0, output.bindonAttr.length - 6) : null;
var bracketParenAttr = output.bracketParenAttr ?
const bracketParenAttr = output.bracketParenAttr ?
`[(${output.bracketParenAttr.substring(2, output.bracketParenAttr.length - 8)})]` :
null;
@ -140,12 +140,12 @@ export class DowngradeNg2ComponentAdapter {
}
if (expr != null && assignExpr != null) {
var getter = this.parse(expr);
var setter = getter.assign;
const getter = this.parse(expr);
const setter = getter.assign;
if (assignExpr && !setter) {
throw new Error(`Expression '${expr}' is not assignable!`);
}
var emitter = this.component[output.prop] as EventEmitter<any>;
const emitter = this.component[output.prop] as EventEmitter<any>;
if (emitter) {
emitter.subscribe({
next: assignExpr ?

View File

@ -9,9 +9,9 @@
import {DirectiveResolver} from '@angular/compiler';
import {Directive, Type} from '@angular/core';
var COMPONENT_SELECTOR = /^[\w|-]*$/;
var SKEWER_CASE = /-(\w)/g;
var directiveResolver = new DirectiveResolver();
const COMPONENT_SELECTOR = /^[\w|-]*$/;
const SKEWER_CASE = /-(\w)/g;
const directiveResolver = new DirectiveResolver();
export interface AttrProp {
prop: string;
@ -32,8 +32,8 @@ export interface ComponentInfo {
}
export function getComponentInfo(type: Type<any>): ComponentInfo {
var resolvedMetadata: Directive = directiveResolver.resolve(type);
var selector = resolvedMetadata.selector;
const resolvedMetadata: Directive = directiveResolver.resolve(type);
let selector = resolvedMetadata.selector;
if (!selector.match(COMPONENT_SELECTOR)) {
throw new Error('Only selectors matching element names are supported, got: ' + selector);
}
@ -48,13 +48,13 @@ export function getComponentInfo(type: Type<any>): ComponentInfo {
}
export function parseFields(names: string[]): AttrProp[] {
var attrProps: AttrProp[] = [];
const attrProps: AttrProp[] = [];
if (names) {
for (var i = 0; i < names.length; i++) {
var parts = names[i].split(':');
var prop = parts[0].trim();
var attr = (parts[1] || parts[0]).trim();
var capitalAttr = attr.charAt(0).toUpperCase() + attr.substr(1);
for (let i = 0; i < names.length; i++) {
const parts = names[i].split(':');
const prop = parts[0].trim();
const attr = (parts[1] || parts[0]).trim();
const capitalAttr = attr.charAt(0).toUpperCase() + attr.substr(1);
attrProps.push(<AttrProp>{
prop: prop,
attr: attr,

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();

View File

@ -33,9 +33,9 @@ export class UpgradeNg1ComponentAdapterBuilder {
$controller: angular.IControllerService = null;
constructor(public name: string) {
var selector = name.replace(
const selector = name.replace(
CAMEL_CASE, (all: any /** TODO #9100 */, next: string) => '-' + next.toLowerCase());
var self = this;
const self = this;
this.type =
Directive({selector: selector, inputs: this.inputsRename, outputs: this.outputsRename})
.Class({
@ -54,14 +54,14 @@ export class UpgradeNg1ComponentAdapterBuilder {
}
extractDirective(injector: angular.IInjectorService): angular.IDirective {
var directives: angular.IDirective[] = injector.get(this.name + 'Directive');
const directives: angular.IDirective[] = injector.get(this.name + 'Directive');
if (directives.length > 1) {
throw new Error('Only support single directive definition for: ' + this.name);
}
var directive = directives[0];
const directive = directives[0];
if (directive.replace) this.notSupported('replace');
if (directive.terminal) this.notSupported('terminal');
var link = directive.link;
const link = directive.link;
if (typeof link == 'object') {
if ((<angular.IDirectivePrePost>link).post) this.notSupported('link.post');
}
@ -73,28 +73,28 @@ export class UpgradeNg1ComponentAdapterBuilder {
}
extractBindings() {
var btcIsObject = typeof this.directive.bindToController === 'object';
const btcIsObject = typeof this.directive.bindToController === 'object';
if (btcIsObject && Object.keys(this.directive.scope).length) {
throw new Error(
`Binding definitions on scope and controller at the same time are not supported.`);
}
var context = (btcIsObject) ? this.directive.bindToController : this.directive.scope;
const context = (btcIsObject) ? this.directive.bindToController : this.directive.scope;
if (typeof context == 'object') {
for (var name in context) {
for (const name in context) {
if ((<any>context).hasOwnProperty(name)) {
var localName = context[name];
var type = localName.charAt(0);
var typeOptions = localName.charAt(1);
let localName = context[name];
const type = localName.charAt(0);
const typeOptions = localName.charAt(1);
localName = typeOptions === '?' ? localName.substr(2) : localName.substr(1);
localName = localName || name;
var outputName = 'output_' + name;
var outputNameRename = outputName + ': ' + name;
var outputNameRenameChange = outputName + ': ' + name + 'Change';
var inputName = 'input_' + name;
var inputNameRename = inputName + ': ' + name;
const outputName = 'output_' + name;
const outputNameRename = outputName + ': ' + name;
const outputNameRenameChange = outputName + ': ' + name + 'Change';
const inputName = 'input_' + name;
const inputNameRename = inputName + ': ' + name;
switch (type) {
case '=':
this.propertyOutputs.push(outputName);
@ -119,7 +119,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
this.propertyMap[outputName] = localName;
break;
default:
var json = JSON.stringify(context);
let json = JSON.stringify(context);
throw new Error(
`Unexpected mapping '${type}' in '${json}' in '${this.name}' directive.`);
}
@ -136,9 +136,9 @@ export class UpgradeNg1ComponentAdapterBuilder {
typeof this.directive.template === 'function' ? this.directive.template() :
this.directive.template);
} else if (this.directive.templateUrl) {
var url = typeof this.directive.templateUrl === 'function' ? this.directive.templateUrl() :
this.directive.templateUrl;
var html = templateCache.get(url);
const url = typeof this.directive.templateUrl === 'function' ? this.directive.templateUrl() :
this.directive.templateUrl;
const html = templateCache.get(url);
if (html !== undefined) {
this.linkFn = compileHtml(html);
} else {
@ -159,7 +159,7 @@ export class UpgradeNg1ComponentAdapterBuilder {
}
return null;
function compileHtml(html: any /** TODO #9100 */): angular.ILinkFn {
var div = document.createElement('div');
const div = document.createElement('div');
div.innerHTML = html;
return compile(div.childNodes);
}
@ -171,18 +171,18 @@ export class UpgradeNg1ComponentAdapterBuilder {
static resolve(
exportedComponents: {[name: string]: UpgradeNg1ComponentAdapterBuilder},
injector: angular.IInjectorService): Promise<angular.ILinkFn[]> {
var promises: Promise<angular.ILinkFn>[] = [];
var compile: angular.ICompileService = injector.get(NG1_COMPILE);
var templateCache: angular.ITemplateCacheService = injector.get(NG1_TEMPLATE_CACHE);
var httpBackend: angular.IHttpBackendService = injector.get(NG1_HTTP_BACKEND);
var $controller: angular.IControllerService = injector.get(NG1_CONTROLLER);
for (var name in exportedComponents) {
const promises: Promise<angular.ILinkFn>[] = [];
const compile: angular.ICompileService = injector.get(NG1_COMPILE);
const templateCache: angular.ITemplateCacheService = injector.get(NG1_TEMPLATE_CACHE);
const httpBackend: angular.IHttpBackendService = injector.get(NG1_HTTP_BACKEND);
const $controller: angular.IControllerService = injector.get(NG1_CONTROLLER);
for (const name in exportedComponents) {
if ((<any>exportedComponents).hasOwnProperty(name)) {
var exportedComponent = exportedComponents[name];
const exportedComponent = exportedComponents[name];
exportedComponent.directive = exportedComponent.extractDirective(injector);
exportedComponent.$controller = $controller;
exportedComponent.extractBindings();
var promise: Promise<angular.ILinkFn> =
const promise: Promise<angular.ILinkFn> =
exportedComponent.compileTemplate(compile, templateCache, httpBackend);
if (promise) promises.push(promise);
}
@ -206,23 +206,23 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
this.element = elementRef.nativeElement;
this.componentScope = scope.$new(!!directive.scope);
this.$element = angular.element(this.element);
var controllerType = directive.controller;
const controllerType = directive.controller;
if (directive.bindToController && controllerType) {
this.destinationObj = this.buildController(controllerType);
} else {
this.destinationObj = this.componentScope;
}
for (var i = 0; i < inputs.length; i++) {
for (let i = 0; i < inputs.length; i++) {
(this as any /** TODO #9100 */)[inputs[i]] = null;
}
for (var j = 0; j < outputs.length; j++) {
var emitter = (this as any /** TODO #9100 */)[outputs[j]] = new EventEmitter();
for (let j = 0; j < outputs.length; j++) {
const emitter = (this as any /** TODO #9100 */)[outputs[j]] = new EventEmitter();
this.setComponentProperty(
outputs[j], ((emitter: any /** TODO #9100 */) => (value: any /** TODO #9100 */) =>
emitter.emit(value))(emitter));
}
for (var k = 0; k < propOuts.length; k++) {
for (let k = 0; k < propOuts.length; k++) {
(this as any /** TODO #9100 */)[propOuts[k]] = new EventEmitter();
this.checkLastValues.push(INITIAL_VALUE);
}
@ -232,24 +232,24 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
if (!this.directive.bindToController && this.directive.controller) {
this.buildController(this.directive.controller);
}
var link = this.directive.link;
let link = this.directive.link;
if (typeof link == 'object') link = (<angular.IDirectivePrePost>link).pre;
if (link) {
var attrs: angular.IAttributes = NOT_SUPPORTED;
var transcludeFn: angular.ITranscludeFunction = NOT_SUPPORTED;
var linkController = this.resolveRequired(this.$element, this.directive.require);
const attrs: angular.IAttributes = NOT_SUPPORTED;
const transcludeFn: angular.ITranscludeFunction = NOT_SUPPORTED;
const linkController = this.resolveRequired(this.$element, this.directive.require);
(<angular.IDirectiveLinkFn>this.directive.link)(
this.componentScope, this.$element, attrs, linkController, transcludeFn);
}
var childNodes: Node[] = [];
var childNode: any /** TODO #9100 */;
const childNodes: Node[] = [];
let childNode: any /** TODO #9100 */;
while (childNode = this.element.firstChild) {
this.element.removeChild(childNode);
childNodes.push(childNode);
}
this.linkFn(this.componentScope, (clonedElement, scope) => {
for (var i = 0, ii = clonedElement.length; i < ii; i++) {
for (let i = 0, ii = clonedElement.length; i < ii; i++) {
this.element.appendChild(clonedElement[i]);
}
}, {
@ -262,27 +262,27 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
}
ngOnChanges(changes: SimpleChanges) {
for (var name in changes) {
for (const name in changes) {
if ((<Object>changes).hasOwnProperty(name)) {
var change: SimpleChange = changes[name];
const change: SimpleChange = changes[name];
this.setComponentProperty(name, change.currentValue);
}
}
}
ngDoCheck(): number {
var count = 0;
var destinationObj = this.destinationObj;
var lastValues = this.checkLastValues;
var checkProperties = this.checkProperties;
for (var i = 0; i < checkProperties.length; i++) {
var value = destinationObj[checkProperties[i]];
var last = lastValues[i];
const count = 0;
const destinationObj = this.destinationObj;
const lastValues = this.checkLastValues;
const checkProperties = this.checkProperties;
for (let i = 0; i < checkProperties.length; i++) {
const value = destinationObj[checkProperties[i]];
const last = lastValues[i];
if (value !== last) {
if (typeof value == 'number' && isNaN(value) && typeof last == 'number' && isNaN(last)) {
// ignore because NaN != NaN
} else {
var eventEmitter: EventEmitter<any> = (this as any /** TODO #9100 */)[this.propOuts[i]];
const eventEmitter: EventEmitter<any> = (this as any /** TODO #9100 */)[this.propOuts[i]];
eventEmitter.emit(lastValues[i] = value);
}
}
@ -295,8 +295,8 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
}
private buildController(controllerType: any /** TODO #9100 */) {
var locals = {$scope: this.componentScope, $element: this.$element};
var controller: any =
const locals = {$scope: this.componentScope, $element: this.$element};
const controller: any =
this.$controller(controllerType, locals, null, this.directive.controllerAs);
this.$element.data(controllerKey(this.directive.name), controller);
return controller;
@ -307,11 +307,10 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
if (!require) {
return undefined;
} else if (typeof require == 'string') {
var name: string = <string>require;
var isOptional = false;
var startParent = false;
var searchParents = false;
var ch: string;
let name: string = <string>require;
let isOptional = false;
let startParent = false;
let searchParents = false;
if (name.charAt(0) == '?') {
isOptional = true;
name = name.substr(1);
@ -325,16 +324,16 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
name = name.substr(1);
}
var key = controllerKey(name);
const key = controllerKey(name);
if (startParent) $element = $element.parent();
var dep = searchParents ? $element.inheritedData(key) : $element.data(key);
const dep = searchParents ? $element.inheritedData(key) : $element.data(key);
if (!dep && !isOptional) {
throw new Error(`Can not locate '${require}' in '${this.directive.name}'.`);
}
return dep;
} else if (require instanceof Array) {
var deps: any[] /** TODO #9100 */ = [];
for (var i = 0; i < require.length; i++) {
const deps: any[] = [];
for (let i = 0; i < require.length; i++) {
deps.push(this.resolveRequired($element, require[i]));
}
return deps;