refactor(): use const and let instead of var
This commit is contained in:

committed by
Victor Berchet

parent
73593d4bf3
commit
77ee27c59e
@ -16,7 +16,7 @@ export class BrowserGetTestability implements GetTestability {
|
||||
|
||||
addToWindow(registry: TestabilityRegistry): void {
|
||||
global.getAngularTestability = (elem: any, findInAncestors: boolean = true) => {
|
||||
var testability = registry.findTestabilityInTree(elem, findInAncestors);
|
||||
const testability = registry.findTestabilityInTree(elem, findInAncestors);
|
||||
if (testability == null) {
|
||||
throw new Error('Could not find testability for element.');
|
||||
}
|
||||
@ -27,11 +27,11 @@ export class BrowserGetTestability implements GetTestability {
|
||||
|
||||
global.getAllAngularRootElements = () => registry.getAllRootElements();
|
||||
|
||||
var whenAllStable = (callback: any /** TODO #9100 */) => {
|
||||
var testabilities = global.getAllAngularTestabilities();
|
||||
var count = testabilities.length;
|
||||
var didWork = false;
|
||||
var decrement = function(didWork_: any /** TODO #9100 */) {
|
||||
const whenAllStable = (callback: any /** TODO #9100 */) => {
|
||||
const testabilities = global.getAllAngularTestabilities();
|
||||
let count = testabilities.length;
|
||||
let didWork = false;
|
||||
const decrement = function(didWork_: any /** TODO #9100 */) {
|
||||
didWork = didWork || didWork_;
|
||||
count--;
|
||||
if (count == 0) {
|
||||
@ -54,7 +54,7 @@ export class BrowserGetTestability implements GetTestability {
|
||||
if (elem == null) {
|
||||
return null;
|
||||
}
|
||||
var t = registry.getTestability(elem);
|
||||
const t = registry.getTestability(elem);
|
||||
if (isPresent(t)) {
|
||||
return t;
|
||||
} else if (!findInAncestors) {
|
||||
|
@ -53,15 +53,15 @@ export class AngularProfiler {
|
||||
* ```
|
||||
*/
|
||||
timeChangeDetection(config: any): ChangeDetectionPerfRecord {
|
||||
var record = config && config['record'];
|
||||
var profileName = 'Change Detection';
|
||||
const record = config && config['record'];
|
||||
const profileName = 'Change Detection';
|
||||
// Profiler is not available in Android browsers, nor in IE 9 without dev tools opened
|
||||
var isProfilerAvailable = isPresent(window.console.profile);
|
||||
const isProfilerAvailable = isPresent(window.console.profile);
|
||||
if (record && isProfilerAvailable) {
|
||||
window.console.profile(profileName);
|
||||
}
|
||||
const start = getDOM().performanceNow();
|
||||
var numTicks = 0;
|
||||
let numTicks = 0;
|
||||
while (numTicks < 5 || (getDOM().performanceNow() - start) < 500) {
|
||||
this.appRef.tick();
|
||||
numTicks++;
|
||||
|
@ -11,7 +11,7 @@ import {global} from '../../facade/lang';
|
||||
|
||||
import {AngularTools} from './common_tools';
|
||||
|
||||
var context = <any>global;
|
||||
const context = <any>global;
|
||||
|
||||
/**
|
||||
* Enabled Angular 2 debug tools that are accessible via your browser's
|
||||
|
@ -75,7 +75,7 @@ export class HammerGestureConfig {
|
||||
mc.get('pinch').set({enable: true});
|
||||
mc.get('rotate').set({enable: true});
|
||||
|
||||
for (let eventName in this.overrides) {
|
||||
for (const eventName in this.overrides) {
|
||||
mc.get(eventName).set(this.overrides[eventName]);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ export class SharedStylesHost {
|
||||
constructor() {}
|
||||
|
||||
addStyles(styles: string[]) {
|
||||
var additions: any[] /** TODO #9100 */ = [];
|
||||
const additions: any[] /** TODO #9100 */ = [];
|
||||
styles.forEach(style => {
|
||||
if (!this._stylesSet.has(style)) {
|
||||
this._stylesSet.add(style);
|
||||
@ -45,7 +45,7 @@ export class DomSharedStylesHost extends SharedStylesHost {
|
||||
}
|
||||
/** @internal */
|
||||
_addStylesToHost(styles: string[], host: Node) {
|
||||
for (var i = 0; i < styles.length; i++) {
|
||||
for (let i = 0; i < styles.length; i++) {
|
||||
const styleEl = document.createElement('style');
|
||||
styleEl.textContent = styles[i];
|
||||
host.appendChild(styleEl);
|
||||
|
@ -6,8 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
var CAMEL_CASE_REGEXP = /([A-Z])/g;
|
||||
var DASH_CASE_REGEXP = /-([a-z])/g;
|
||||
const CAMEL_CASE_REGEXP = /([A-Z])/g;
|
||||
const DASH_CASE_REGEXP = /-([a-z])/g;
|
||||
|
||||
|
||||
export function camelCaseToDashCase(input: string): string {
|
||||
|
@ -16,8 +16,8 @@ export class WebAnimationsDriver implements AnimationDriver {
|
||||
animate(
|
||||
element: any, startingStyles: AnimationStyles, keyframes: AnimationKeyframe[],
|
||||
duration: number, delay: number, easing: string): WebAnimationsPlayer {
|
||||
var formattedSteps: {[key: string]: string | number}[] = [];
|
||||
var startingStyleLookup: {[key: string]: string | number} = {};
|
||||
let formattedSteps: {[key: string]: string | number}[] = [];
|
||||
let startingStyleLookup: {[key: string]: string | number} = {};
|
||||
if (isPresent(startingStyles) && startingStyles.styles.length > 0) {
|
||||
startingStyleLookup = _populateStyles(element, startingStyles, {});
|
||||
startingStyleLookup['offset'] = 0;
|
||||
@ -25,7 +25,7 @@ export class WebAnimationsDriver implements AnimationDriver {
|
||||
}
|
||||
|
||||
keyframes.forEach((keyframe: AnimationKeyframe) => {
|
||||
let data = _populateStyles(element, keyframe.styles, startingStyleLookup);
|
||||
const data = _populateStyles(element, keyframe.styles, startingStyleLookup);
|
||||
data['offset'] = keyframe.offset;
|
||||
formattedSteps.push(data);
|
||||
});
|
||||
@ -35,12 +35,12 @@ export class WebAnimationsDriver implements AnimationDriver {
|
||||
// end with the same values. Removing the offset and having only
|
||||
// start/end values is suitable enough for the web-animations API
|
||||
if (formattedSteps.length == 1) {
|
||||
var start = formattedSteps[0];
|
||||
const start = formattedSteps[0];
|
||||
start['offset'] = null;
|
||||
formattedSteps = [start, start];
|
||||
}
|
||||
|
||||
var playerOptions: {[key: string]: string | number} = {
|
||||
const playerOptions: {[key: string]: string | number} = {
|
||||
'duration': duration,
|
||||
'delay': delay,
|
||||
'fill': 'both' // we use `both` because it allows for styling at 0% to work with `delay`
|
||||
@ -59,7 +59,7 @@ export class WebAnimationsDriver implements AnimationDriver {
|
||||
function _populateStyles(
|
||||
element: any, styles: AnimationStyles,
|
||||
defaultStyles: {[key: string]: string | number}): {[key: string]: string | number} {
|
||||
var data: {[key: string]: string | number} = {};
|
||||
const data: {[key: string]: string | number} = {};
|
||||
styles.styles.forEach(
|
||||
(entry) => { Object.keys(entry).forEach(prop => { data[prop] = entry[prop]; }); });
|
||||
Object.keys(defaultStyles).forEach(prop => {
|
||||
|
@ -42,8 +42,8 @@ export class WebAnimationsPlayer implements AnimationPlayer {
|
||||
if (this._initialized) return;
|
||||
this._initialized = true;
|
||||
|
||||
var keyframes = this.keyframes.map(styles => {
|
||||
var formattedKeyframe: {[key: string]: string | number} = {};
|
||||
const keyframes = this.keyframes.map(styles => {
|
||||
const formattedKeyframe: {[key: string]: string | number} = {};
|
||||
Object.keys(styles).forEach(prop => {
|
||||
const value = styles[prop];
|
||||
formattedKeyframe[prop] = value == AUTO_STYLE ? _computeStyle(this.element, prop) : value;
|
||||
|
@ -23,15 +23,15 @@ function getInertElement() {
|
||||
DOM = getDOM();
|
||||
|
||||
// Prefer using <template> element if supported.
|
||||
let templateEl = DOM.createElement('template');
|
||||
const templateEl = DOM.createElement('template');
|
||||
if ('content' in templateEl) return templateEl;
|
||||
|
||||
let doc = DOM.createHtmlDocument();
|
||||
const doc = DOM.createHtmlDocument();
|
||||
inertElement = DOM.querySelector(doc, 'body');
|
||||
if (inertElement == null) {
|
||||
// usually there should be only one body element in the document, but IE doesn't have any, so we
|
||||
// need to create one.
|
||||
let html = DOM.createElement('html', doc);
|
||||
const html = DOM.createElement('html', doc);
|
||||
inertElement = DOM.createElement('body', doc);
|
||||
DOM.appendChild(html, inertElement);
|
||||
DOM.appendChild(doc, html);
|
||||
@ -40,15 +40,15 @@ function getInertElement() {
|
||||
}
|
||||
|
||||
function tagSet(tags: string): {[k: string]: boolean} {
|
||||
let res: {[k: string]: boolean} = {};
|
||||
for (let t of tags.split(',')) res[t] = true;
|
||||
const res: {[k: string]: boolean} = {};
|
||||
for (const t of tags.split(',')) res[t] = true;
|
||||
return res;
|
||||
}
|
||||
|
||||
function merge(...sets: {[k: string]: boolean}[]): {[k: string]: boolean} {
|
||||
let res: {[k: string]: boolean} = {};
|
||||
for (let s of sets) {
|
||||
for (let v in s) {
|
||||
const res: {[k: string]: boolean} = {};
|
||||
for (const s of sets) {
|
||||
for (const v in s) {
|
||||
if (s.hasOwnProperty(v)) res[v] = true;
|
||||
}
|
||||
}
|
||||
@ -164,7 +164,7 @@ class SanitizingHtmlSerializer {
|
||||
this.buf.push('<');
|
||||
this.buf.push(tagName);
|
||||
DOM.attributeMap(element).forEach((value: string, attrName: string) => {
|
||||
let lower = attrName.toLowerCase();
|
||||
const lower = attrName.toLowerCase();
|
||||
if (!VALID_ATTRS.hasOwnProperty(lower)) {
|
||||
this.sanitizedSomething = true;
|
||||
return;
|
||||
@ -210,8 +210,8 @@ function encodeEntities(value: string) {
|
||||
.replace(
|
||||
SURROGATE_PAIR_REGEXP,
|
||||
function(match: string) {
|
||||
let hi = match.charCodeAt(0);
|
||||
let low = match.charCodeAt(1);
|
||||
const hi = match.charCodeAt(0);
|
||||
const low = match.charCodeAt(1);
|
||||
return '&#' + (((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000) + ';';
|
||||
})
|
||||
.replace(
|
||||
@ -234,7 +234,7 @@ function stripCustomNsAttrs(el: Element) {
|
||||
DOM.removeAttribute(el, attrName);
|
||||
}
|
||||
});
|
||||
for (let n of DOM.childNodesAsList(el)) {
|
||||
for (const n of DOM.childNodesAsList(el)) {
|
||||
if (DOM.isElementNode(n)) stripCustomNsAttrs(n as Element);
|
||||
}
|
||||
}
|
||||
@ -269,12 +269,12 @@ export function sanitizeHtml(unsafeHtmlInput: string): string {
|
||||
parsedHtml = DOM.getInnerHTML(containerEl);
|
||||
} while (unsafeHtml !== parsedHtml);
|
||||
|
||||
let sanitizer = new SanitizingHtmlSerializer();
|
||||
let safeHtml = sanitizer.sanitizeChildren(DOM.getTemplateContent(containerEl) || containerEl);
|
||||
const sanitizer = new SanitizingHtmlSerializer();
|
||||
const safeHtml = sanitizer.sanitizeChildren(DOM.getTemplateContent(containerEl) || containerEl);
|
||||
|
||||
// Clear out the body element.
|
||||
let parent = DOM.getTemplateContent(containerEl) || containerEl;
|
||||
for (let child of DOM.childNodesAsList(parent)) {
|
||||
const parent = DOM.getTemplateContent(containerEl) || containerEl;
|
||||
for (const child of DOM.childNodesAsList(parent)) {
|
||||
DOM.removeChild(parent, child);
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ function hasBalancedQuotes(value: string) {
|
||||
let outsideSingle = true;
|
||||
let outsideDouble = true;
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
let c = value.charAt(i);
|
||||
const c = value.charAt(i);
|
||||
if (c === '\'' && outsideDouble) {
|
||||
outsideSingle = !outsideSingle;
|
||||
} else if (c === '"' && outsideSingle) {
|
||||
|
Reference in New Issue
Block a user