refactor: replace var usage with let/const (#7064)

This commit is contained in:
Manol Donev
2019-03-25 18:09:14 +02:00
committed by GitHub
parent 34fe24732d
commit b436ecde36
75 changed files with 1093 additions and 1085 deletions

View File

@@ -5,7 +5,7 @@
/**
* A runtime option indicating whether the build has debugging enabled.
*/
export var debug: boolean;
export let debug: boolean;
/**
* A class encapsulating information for source code origin.

View File

@@ -1,9 +1,9 @@
import { knownFolders } from "../file-system"
import { isAndroid } from "../platform"
export var debug = true;
export let debug = true;
var applicationRootPath: string;
let applicationRootPath: string;
function ensureAppRootPath() {
if (!applicationRootPath) {
applicationRootPath = knownFolders.currentApp().path;

View File

@@ -1,7 +1,7 @@
// This method iterates all the keys in the source exports object and copies them to the destination exports one.
// Note: the method will not check for naming collisions and will override any already existing entries in the destination exports.
export var merge = function (sourceExports: any, destExports: any) {
for (var key in sourceExports) {
export function merge(sourceExports: any, destExports: any) {
for (let key in sourceExports) {
destExports[key] = sourceExports[key];
}
}

View File

@@ -42,16 +42,16 @@ export function verifyCallback(value: any) {
}
}
var classInfosMap = new Map<Function, ClassInfo>();
var funcNameRegex = /function ([_a-zA-Z0-9]{1,})\(/;
const classInfosMap = new Map<Function, ClassInfo>();
const funcNameRegex = /function ([_a-zA-Z0-9]{1,})\(/;
export function getClass(object: Object): string {
return getClassInfo(object).name;
}
export function getClassInfo(object: Object): ClassInfo {
var constructor = object.constructor;
const constructor = object.constructor;
var result = classInfosMap.get(constructor);
let result = classInfosMap.get(constructor);
if (!result) {
result = new ClassInfo(constructor);
classInfosMap.set(constructor, result);
@@ -61,8 +61,8 @@ export function getClassInfo(object: Object): ClassInfo {
}
export function getBaseClasses(object): Array<string> {
var result = [];
var info = getClassInfo(object);
const result = [];
let info = getClassInfo(object);
while (info) {
result.push(info.name);
info = info.baseClassInfo;
@@ -81,7 +81,7 @@ export class ClassInfo {
get name(): string {
if (!this._name) {
var results = (funcNameRegex).exec(this._typeCosntructor.toString());
const results = (funcNameRegex).exec(this._typeCosntructor.toString());
this._name = (results && results.length > 1) ? results[1] : "";
}
@@ -102,8 +102,8 @@ export class ClassInfo {
}
private static _getBase(info: ClassInfo): ClassInfo {
var result = null;
var constructorProto = info._typeCosntructor.prototype;
let result = null;
const constructorProto = info._typeCosntructor.prototype;
if (constructorProto.__proto__) {
result = getClassInfo(constructorProto.__proto__);
}

View File

@@ -9,15 +9,13 @@ export function escapeRegexSymbols(source: string): string {
}
export function convertString(value: any): any {
var result;
let result;
if (!types.isString(value)) {
result = value;
} else if (value.trim() === "") {
if (!types.isString(value) || value.trim() === "") {
result = value;
} else {
// Try to convert value to number.
var valueAsNumber = +value;
const valueAsNumber = +value;
if (!isNaN(valueAsNumber)) {
result = valueAsNumber;
} else if (value && (value.toLowerCase() === "true" || value.toLowerCase() === "false")) {

View File

@@ -131,9 +131,9 @@ export module ad {
export module collections {
export function stringArrayToStringSet(str: string[]): java.util.HashSet<string> {
var hashSet = new java.util.HashSet<string>();
const hashSet = new java.util.HashSet<string>();
if (str !== undefined) {
for (var element in str) {
for (let element in str) {
hashSet.add("" + str[element]);
}
}
@@ -141,11 +141,11 @@ export module ad {
}
export function stringSetToStringArray(stringSet: any): string[] {
var arr = [];
const arr = [];
if (stringSet !== undefined) {
var it = stringSet.iterator();
const it = stringSet.iterator();
while (it.hasNext()) {
var element = "" + it.next();
const element = "" + it.next();
arr.push(element);
}
}
@@ -155,8 +155,8 @@ export module ad {
}
export module resources {
var attr;
var attrCache = new Map<string, number>();
let attr;
const attrCache = new Map<string, number>();
export function getDrawableId(name) {
return getId(":drawable/" + name);
@@ -167,9 +167,9 @@ export module ad {
}
export function getId(name: string): number {
var resources = getResources();
var packageName = getPackageName();
var uri = packageName + name;
const resources = getResources();
const packageName = getPackageName();
const uri = packageName + name;
return resources.getIdentifier(uri, null, null);
}
export function getPalleteColor(name: string, context: android.content.Context): number {
@@ -180,7 +180,7 @@ export module ad {
return attrCache.get(name);
}
var result = 0;
let result = 0;
try {
if (!attr) {
attr = java.lang.Class.forName("android.support.v7.appcompat.R$attr")
@@ -219,7 +219,7 @@ export function releaseNativeObject(object: java.lang.Object) {
export function openUrl(location: string): boolean {
const context = ad.getApplicationContext();
try {
var intent = new android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(location.trim()));
const intent = new android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(location.trim()));
intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

View File

@@ -24,13 +24,13 @@ export module layout {
/**
* Bits that provide the actual measured size.
*/
export var MEASURED_HEIGHT_STATE_SHIFT: number;
export var MEASURED_SIZE_MASK: number;
export var MEASURED_STATE_MASK: number;
export var MEASURED_STATE_TOO_SMALL: number;
export var UNSPECIFIED: number;
export var EXACTLY: number;
export var AT_MOST: number;
export const MEASURED_HEIGHT_STATE_SHIFT: number;
export const MEASURED_SIZE_MASK: number;
export const MEASURED_STATE_MASK: number;
export const MEASURED_STATE_TOO_SMALL: number;
export const UNSPECIFIED: number;
export const EXACTLY: number;
export const AT_MOST: number;
/**
* Gets layout mode from a given specification as string.
@@ -229,7 +229,7 @@ export module ios {
/**
* Gets the iOS device major version (for 8.1 will return 8).
*/
export var MajorVersion: number;
export const MajorVersion: number;
/**
* Opens file with associated application.

View File

@@ -12,8 +12,8 @@ function isOrientationLandscape(orientation: number) {
}
export module layout {
var MODE_SHIFT = 30;
var MODE_MASK = 0x3 << MODE_SHIFT;
const MODE_SHIFT = 30;
const MODE_MASK = 0x3 << MODE_SHIFT;
export function makeMeasureSpec(size: number, mode: number): number {
return (Math.round(Math.max(0, size)) & ~MODE_MASK) | (mode & MODE_MASK);
@@ -60,7 +60,7 @@ export module ios {
}
export function nsArrayToJSArray(a: NSArray<any>): Array<Object> {
var arr = [];
const arr = [];
if (a !== undefined) {
let count = a.count;
for (let i = 0; i < count; i++) {
@@ -79,7 +79,7 @@ export module ios {
return isOrientationLandscape(device.orientation) || isStatusBarOrientationLandscape;
}
export var MajorVersion = NSString.stringWithString(UIDevice.currentDevice.systemVersion).intValue;
export const MajorVersion = NSString.stringWithString(UIDevice.currentDevice.systemVersion).intValue;
export function openFile(filePath: string): boolean {
try {
@@ -147,7 +147,7 @@ export function releaseNativeObject(object: NSObject) {
export function openUrl(location: string): boolean {
try {
var url = NSURL.URLWithString(location.trim());
const url = NSURL.URLWithString(location.trim());
if (UIApplication.sharedApplication.canOpenURL(url)) {
return UIApplication.sharedApplication.openURL(url);
}