diff --git a/tns-core-modules/application-settings/application-settings-common.ts b/tns-core-modules/application-settings/application-settings-common.ts index 6a28f3ca3..39b6008f4 100644 --- a/tns-core-modules/application-settings/application-settings-common.ts +++ b/tns-core-modules/application-settings/application-settings-common.ts @@ -1,10 +1,10 @@ -export var checkKey = function (key: string): void { +export function checkKey(key: string): void { if (typeof key !== "string") { throw new Error("key: '" + key + "' must be a string"); } } -export var ensureValidValue = function (value: any, valueType: string): void { +export function ensureValidValue(value: any, valueType: string): void { if (typeof value !== valueType) { throw new Error("value: '" + value + "' must be a " + valueType); } diff --git a/tns-core-modules/application-settings/application-settings.android.ts b/tns-core-modules/application-settings/application-settings.android.ts index ccd9e0e27..24b326d99 100644 --- a/tns-core-modules/application-settings/application-settings.android.ts +++ b/tns-core-modules/application-settings/application-settings.android.ts @@ -1,7 +1,7 @@ import * as common from "./application-settings-common"; import { getNativeApplication } from "../application"; -var sharedPreferences: android.content.SharedPreferences; +let sharedPreferences: android.content.SharedPreferences; function ensureSharedPreferences() { if (!sharedPreferences) { sharedPreferences = (getNativeApplication()).getApplicationContext().getSharedPreferences("prefs.db", 0); @@ -47,7 +47,7 @@ export function getNumber(key: string, defaultValue?: number): number { export function setBoolean(key: string, value: boolean): void { verify(key); common.ensureValidValue(value, "boolean"); - var editor = sharedPreferences.edit(); + const editor = sharedPreferences.edit(); editor.putBoolean(key, value); editor.apply(); } @@ -55,7 +55,7 @@ export function setBoolean(key: string, value: boolean): void { export function setString(key: string, value: string): void { verify(key); common.ensureValidValue(value, "string"); - var editor = sharedPreferences.edit(); + const editor = sharedPreferences.edit(); editor.putString(key, value); editor.apply(); } @@ -63,14 +63,14 @@ export function setString(key: string, value: string): void { export function setNumber(key: string, value: number): void { verify(key); common.ensureValidValue(value, "number"); - var editor = sharedPreferences.edit(); + const editor = sharedPreferences.edit(); editor.putFloat(key, float(value)); editor.apply(); } export function remove(key: string): void { verify(key); - var editor = sharedPreferences.edit(); + const editor = sharedPreferences.edit(); editor.remove(key); editor.apply(); } @@ -80,14 +80,14 @@ export function clear(): void { sharedPreferences.edit().clear().apply(); } -export var flush = function (): boolean { +export function flush(): boolean { return sharedPreferences.edit().commit(); } export function getAllKeys(): Array { - var mappedPreferences = sharedPreferences.getAll(); - var iterator = mappedPreferences.keySet().iterator(); - var result = []; + const mappedPreferences = sharedPreferences.getAll(); + const iterator = mappedPreferences.keySet().iterator(); + const result = []; while (iterator.hasNext()) { let key = iterator.next(); result.push(key); diff --git a/tns-core-modules/application-settings/application-settings.ios.ts b/tns-core-modules/application-settings/application-settings.ios.ts index 6c2c4b757..508a29237 100644 --- a/tns-core-modules/application-settings/application-settings.ios.ts +++ b/tns-core-modules/application-settings/application-settings.ios.ts @@ -2,67 +2,71 @@ import * as utils from "../utils/utils"; -var userDefaults = NSUserDefaults.standardUserDefaults; +const userDefaults = NSUserDefaults.standardUserDefaults; -export var hasKey = function (key: string): boolean { +export function hasKey(key: string): boolean { Common.checkKey(key); + return userDefaults.objectForKey(key) !== null; } // utils.ios.getters -export var getBoolean = function (key: string, defaultValue?: boolean): boolean { +export function getBoolean(key: string, defaultValue?: boolean): boolean { Common.checkKey(key); if (hasKey(key)) { return userDefaults.boolForKey(key); } + return defaultValue; } -export var getString = function (key: string, defaultValue?: string): string { +export function getString(key: string, defaultValue?: string): string { Common.checkKey(key); if (hasKey(key)) { return userDefaults.stringForKey(key); } + return defaultValue; } -export var getNumber = function (key: string, defaultValue?: number): number { +export function getNumber(key: string, defaultValue?: number): number { Common.checkKey(key); if (hasKey(key)) { return userDefaults.doubleForKey(key); } + return defaultValue; } // setters -export var setBoolean = function (key: string, value: boolean): void { +export function setBoolean(key: string, value: boolean): void { Common.checkKey(key); Common.ensureValidValue(value, "boolean"); userDefaults.setBoolForKey(value, key); } -export var setString = function (key: string, value: string): void { +export function setString(key: string, value: string): void { Common.checkKey(key); Common.ensureValidValue(value, "string"); userDefaults.setObjectForKey(value, key); } -export var setNumber = function (key: string, value: number): void { +export function setNumber(key: string, value: number): void { Common.checkKey(key); Common.ensureValidValue(value, "number"); userDefaults.setDoubleForKey(value, key); } -export var remove = function (key: string): void { +export function remove(key: string): void { Common.checkKey(key); userDefaults.removeObjectForKey(key); } -export var clear = function (): void { +export function clear(): void { userDefaults.removePersistentDomainForName(NSBundle.mainBundle.bundleIdentifier); } -export var flush = function (): boolean { +export function flush(): boolean { return userDefaults.synchronize(); } diff --git a/tns-core-modules/application/application.d.ts b/tns-core-modules/application/application.d.ts index d93c0872f..346680879 100644 --- a/tns-core-modules/application/application.d.ts +++ b/tns-core-modules/application/application.d.ts @@ -11,47 +11,47 @@ import { NavigationEntry, View, Observable, EventData } from "../ui/frame"; /** * String value used when hooking to launch event. */ -export var launchEvent: string; +export const launchEvent: string; /** * String value used when hooking to displayed event. */ -export var displayedEvent: string; +export const displayedEvent: string; /** * String value used when hooking to uncaughtError event. */ -export var uncaughtErrorEvent: string; +export const uncaughtErrorEvent: string; /** * String value used when hooking to discardedError event. */ -export var discardedErrorEvent: string; +export const discardedErrorEvent: string; /** * String value used when hooking to suspend event. */ -export var suspendEvent: string; +export const suspendEvent: string; /** * String value used when hooking to resume event. */ -export var resumeEvent: string; +export const resumeEvent: string; /** * String value used when hooking to exit event. */ -export var exitEvent: string; +export const exitEvent: string; /** * String value used when hooking to lowMemory event. */ -export var lowMemoryEvent: string; +export const lowMemoryEvent: string; /** * String value used when hooking to orientationChanged event. */ -export var orientationChangedEvent: string; +export const orientationChangedEvent: string; /** * Event data containing information for the application events. diff --git a/tns-core-modules/application/application.ios.ts b/tns-core-modules/application/application.ios.ts index 11fe3d657..4d05f90bf 100644 --- a/tns-core-modules/application/application.ios.ts +++ b/tns-core-modules/application/application.ios.ts @@ -26,7 +26,7 @@ const getVisibleViewController = ios.getVisibleViewController; // NOTE: UIResponder with implementation of window - related to https://github.com/NativeScript/ios-runtime/issues/430 // TODO: Refactor the UIResponder to use Typescript extends when this issue is resolved: // https://github.com/NativeScript/ios-runtime/issues/1012 -var Responder = (UIResponder).extend({ +const Responder = (UIResponder).extend({ get window() { return iosApp ? iosApp.window : undefined; }, @@ -124,7 +124,7 @@ class IOSApplication implements IOSApplicationDefinition { } public removeNotificationObserver(observer: any, notificationName: string) { - var index = this._observers.indexOf(observer); + const index = this._observers.indexOf(observer); if (index >= 0) { this._observers.splice(index, 1); NSNotificationCenter.defaultCenter.removeObserverNameObject(observer, notificationName, null); diff --git a/tns-core-modules/color/color-common.ts b/tns-core-modules/color/color-common.ts index 19cc12ce5..18081ff73 100644 --- a/tns-core-modules/color/color-common.ts +++ b/tns-core-modules/color/color-common.ts @@ -87,7 +87,7 @@ export class Color implements definition.Color { hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3]; } - var intVal = parseInt(hex, 16); + let intVal = parseInt(hex, 16); if (hex.length === 6) { // add the alpha component since the provided string is RRGGBB intVal = (intVal & 0x00FFFFFF) + 0xFF000000; diff --git a/tns-core-modules/color/known-colors.d.ts b/tns-core-modules/color/known-colors.d.ts index 03c241829..b846b02d4 100644 --- a/tns-core-modules/color/known-colors.d.ts +++ b/tns-core-modules/color/known-colors.d.ts @@ -2,147 +2,147 @@ * @module "color/known-colors" */ /** */ -export var AliceBlue; -export var AntiqueWhite; -export var Aqua; -export var Aquamarine; -export var Azure; -export var Beige; -export var Bisque; -export var Black; -export var BlanchedAlmond; -export var Blue; -export var BlueViolet; -export var Brown; -export var BurlyWood; -export var CadetBlue; -export var Chartreuse; -export var Chocolate; -export var Coral; -export var CornflowerBlue; -export var Cornsilk; -export var Crimson; -export var Cyan; -export var DarkBlue; -export var DarkCyan; -export var DarkGoldenRod; -export var DarkGray; -export var DarkGreen; -export var DarkKhaki; -export var DarkMagenta; -export var DarkOliveGreen; -export var DarkOrange; -export var DarkOrchid; -export var DarkRed; -export var DarkSalmon; -export var DarkSeaGreen; -export var DarkSlateBlue; -export var DarkSlateGray; -export var DarkTurquoise; -export var DarkViolet; -export var DeepPink; -export var DeepSkyBlue; -export var DimGray; -export var DodgerBlue; -export var FireBrick; -export var FloralWhite; -export var ForestGreen; -export var Fuchsia; -export var Gainsboro; -export var GhostWhite; -export var Gold; -export var GoldenRod; -export var Gray; -export var Green; -export var GreenYellow; -export var HoneyDew; -export var HotPink; -export var IndianRed; -export var Indigo; -export var Ivory; -export var Khaki; -export var Lavender; -export var LavenderBlush; -export var LawnGreen; -export var LemonChiffon; -export var LightBlue; -export var LightCoral; -export var LightCyan; -export var LightGoldenRodYellow; -export var LightGray; -export var LightGreen; -export var LightPink; -export var LightSalmon; -export var LightSeaGreen; -export var LightSkyBlue; -export var LightSlateGray; -export var LightSteelBlue; -export var LightYellow; -export var Lime; -export var LimeGreen; -export var Linen; -export var Magenta; -export var Maroon; -export var MediumAquaMarine; -export var MediumBlue; -export var MediumOrchid; -export var MediumPurple; -export var MediumSeaGreen; -export var MediumSlateBlue; -export var MediumSpringGreen; -export var MediumTurquoise; -export var MediumVioletRed; -export var MidnightBlue; -export var MintCream; -export var MistyRose; -export var Moccasin; -export var NavajoWhite; -export var Navy; -export var OldLace; -export var Olive; -export var OliveDrab; -export var Orange; -export var OrangeRed; -export var Orchid; -export var PaleGoldenRod; -export var PaleGreen; -export var PaleTurquoise; -export var PaleVioletRed; -export var PapayaWhip; -export var PeachPuff; -export var Peru; -export var Pink; -export var Plum; -export var PowderBlue; -export var Purple; -export var RebeccaPurple; -export var Red; -export var RosyBrown; -export var RoyalBlue; -export var SaddleBrown; -export var Salmon; -export var SandyBrown; -export var SeaGreen; -export var SeaShell; -export var Sienna; -export var Silver; -export var SkyBlue; -export var SlateBlue; -export var SlateGray; -export var Snow; -export var SpringGreen; -export var SteelBlue; -export var Tan; -export var Teal; -export var Thistle; -export var Tomato; -export var Turquoise; -export var Violet; -export var Wheat; -export var White; -export var WhiteSmoke; -export var Yellow; -export var YellowGreen; +export const AliceBlue; +export const AntiqueWhite; +export const Aqua; +export const Aquamarine; +export const Azure; +export const Beige; +export const Bisque; +export const Black; +export const BlanchedAlmond; +export const Blue; +export const BlueViolet; +export const Brown; +export const BurlyWood; +export const CadetBlue; +export const Chartreuse; +export const Chocolate; +export const Coral; +export const CornflowerBlue; +export const Cornsilk; +export const Crimson; +export const Cyan; +export const DarkBlue; +export const DarkCyan; +export const DarkGoldenRod; +export const DarkGray; +export const DarkGreen; +export const DarkKhaki; +export const DarkMagenta; +export const DarkOliveGreen; +export const DarkOrange; +export const DarkOrchid; +export const DarkRed; +export const DarkSalmon; +export const DarkSeaGreen; +export const DarkSlateBlue; +export const DarkSlateGray; +export const DarkTurquoise; +export const DarkViolet; +export const DeepPink; +export const DeepSkyBlue; +export const DimGray; +export const DodgerBlue; +export const FireBrick; +export const FloralWhite; +export const ForestGreen; +export const Fuchsia; +export const Gainsboro; +export const GhostWhite; +export const Gold; +export const GoldenRod; +export const Gray; +export const Green; +export const GreenYellow; +export const HoneyDew; +export const HotPink; +export const IndianRed; +export const Indigo; +export const Ivory; +export const Khaki; +export const Lavender; +export const LavenderBlush; +export const LawnGreen; +export const LemonChiffon; +export const LightBlue; +export const LightCoral; +export const LightCyan; +export const LightGoldenRodYellow; +export const LightGray; +export const LightGreen; +export const LightPink; +export const LightSalmon; +export const LightSeaGreen; +export const LightSkyBlue; +export const LightSlateGray; +export const LightSteelBlue; +export const LightYellow; +export const Lime; +export const LimeGreen; +export const Linen; +export const Magenta; +export const Maroon; +export const MediumAquaMarine; +export const MediumBlue; +export const MediumOrchid; +export const MediumPurple; +export const MediumSeaGreen; +export const MediumSlateBlue; +export const MediumSpringGreen; +export const MediumTurquoise; +export const MediumVioletRed; +export const MidnightBlue; +export const MintCream; +export const MistyRose; +export const Moccasin; +export const NavajoWhite; +export const Navy; +export const OldLace; +export const Olive; +export const OliveDrab; +export const Orange; +export const OrangeRed; +export const Orchid; +export const PaleGoldenRod; +export const PaleGreen; +export const PaleTurquoise; +export const PaleVioletRed; +export const PapayaWhip; +export const PeachPuff; +export const Peru; +export const Pink; +export const Plum; +export const PowderBlue; +export const Purple; +export const RebeccaPurple; +export const Red; +export const RosyBrown; +export const RoyalBlue; +export const SaddleBrown; +export const Salmon; +export const SandyBrown; +export const SeaGreen; +export const SeaShell; +export const Sienna; +export const Silver; +export const SkyBlue; +export const SlateBlue; +export const SlateGray; +export const Snow; +export const SpringGreen; +export const SteelBlue; +export const Tan; +export const Teal; +export const Thistle; +export const Tomato; +export const Turquoise; +export const Violet; +export const Wheat; +export const White; +export const WhiteSmoke; +export const Yellow; +export const YellowGreen; export function isKnownName(name: string): boolean; export function getKnownColor(name: string): string diff --git a/tns-core-modules/color/known-colors.ts b/tns-core-modules/color/known-colors.ts index 8930248f5..5ebd15567 100644 --- a/tns-core-modules/color/known-colors.ts +++ b/tns-core-modules/color/known-colors.ts @@ -1,154 +1,155 @@ -export var Transparent = "#00000000"; -export var AliceBlue = "#F0F8FF"; -export var AntiqueWhite = "#FAEBD7"; -export var Aqua = "#00FFFF"; -export var Aquamarine = "#7FFFD4"; -export var Azure = "#F0FFFF"; -export var Beige = "#F5F5DC"; -export var Bisque = "#FFE4C4"; -export var Black = "#000000"; -export var BlanchedAlmond = "#FFEBCD"; -export var Blue = "#0000FF"; -export var BlueViolet = "#8A2BE2"; -export var Brown = "#A52A2A"; -export var BurlyWood = "#DEB887"; -export var CadetBlue = "#5F9EA0"; -export var Chartreuse = "#7FFF00"; -export var Chocolate = "#D2691E"; -export var Coral = "#FF7F50"; -export var CornflowerBlue = "#6495ED"; -export var Cornsilk = "#FFF8DC"; -export var Crimson = "#DC143C"; -export var Cyan = "#00FFFF"; -export var DarkBlue = "#00008B"; -export var DarkCyan = "#008B8B"; -export var DarkGoldenRod = "#B8860B"; -export var DarkGray = "#A9A9A9"; -export var DarkGreen = "#006400"; -export var DarkKhaki = "#BDB76B"; -export var DarkMagenta = "#8B008B"; -export var DarkOliveGreen = "#556B2F"; -export var DarkOrange = "#FF8C00"; -export var DarkOrchid = "#9932CC"; -export var DarkRed = "#8B0000"; -export var DarkSalmon = "#E9967A"; -export var DarkSeaGreen = "#8FBC8F"; -export var DarkSlateBlue = "#483D8B"; -export var DarkSlateGray = "#2F4F4F"; -export var DarkTurquoise = "#00CED1"; -export var DarkViolet = "#9400D3"; -export var DeepPink = "#FF1493"; -export var DeepSkyBlue = "#00BFFF"; -export var DimGray = "#696969"; -export var DodgerBlue = "#1E90FF"; -export var FireBrick = "#B22222"; -export var FloralWhite = "#FFFAF0"; -export var ForestGreen = "#228B22"; -export var Fuchsia = "#FF00FF"; -export var Gainsboro = "#DCDCDC"; -export var GhostWhite = "#F8F8FF"; -export var Gold = "#FFD700"; -export var GoldenRod = "#DAA520"; -export var Gray = "#808080"; -export var Green = "#008000"; -export var GreenYellow = "#ADFF2F"; -export var HoneyDew = "#F0FFF0"; -export var HotPink = "#FF69B4"; -export var IndianRed = "#CD5C5C"; -export var Indigo = "#4B0082"; -export var Ivory = "#FFFFF0"; -export var Khaki = "#F0E68C"; -export var Lavender = "#E6E6FA"; -export var LavenderBlush = "#FFF0F5"; -export var LawnGreen = "#7CFC00"; -export var LemonChiffon = "#FFFACD"; -export var LightBlue = "#ADD8E6"; -export var LightCoral = "#F08080"; -export var LightCyan = "#E0FFFF"; -export var LightGoldenRodYellow = "#FAFAD2"; -export var LightGray = "#D3D3D3"; -export var LightGreen = "#90EE90"; -export var LightPink = "#FFB6C1"; -export var LightSalmon = "#FFA07A"; -export var LightSeaGreen = "#20B2AA"; -export var LightSkyBlue = "#87CEFA"; -export var LightSlateGray = "#778899"; -export var LightSteelBlue = "#B0C4DE"; -export var LightYellow = "#FFFFE0"; -export var Lime = "#00FF00"; -export var LimeGreen = "#32CD32"; -export var Linen = "#FAF0E6"; -export var Magenta = "#FF00FF"; -export var Maroon = "#800000"; -export var MediumAquaMarine = "#66CDAA"; -export var MediumBlue = "#0000CD"; -export var MediumOrchid = "#BA55D3"; -export var MediumPurple = "#9370DB"; -export var MediumSeaGreen = "#3CB371"; -export var MediumSlateBlue = "#7B68EE"; -export var MediumSpringGreen = "#00FA9A"; -export var MediumTurquoise = "#48D1CC"; -export var MediumVioletRed = "#C71585"; -export var MidnightBlue = "#191970"; -export var MintCream = "#F5FFFA"; -export var MistyRose = "#FFE4E1"; -export var Moccasin = "#FFE4B5"; -export var NavajoWhite = "#FFDEAD"; -export var Navy = "#000080"; -export var OldLace = "#FDF5E6"; -export var Olive = "#808000"; -export var OliveDrab = "#6B8E23"; -export var Orange = "#FFA500"; -export var OrangeRed = "#FF4500"; -export var Orchid = "#DA70D6"; -export var PaleGoldenRod = "#EEE8AA"; -export var PaleGreen = "#98FB98"; -export var PaleTurquoise = "#AFEEEE"; -export var PaleVioletRed = "#DB7093"; -export var PapayaWhip = "#FFEFD5"; -export var PeachPuff = "#FFDAB9"; -export var Peru = "#CD853F"; -export var Pink = "#FFC0CB"; -export var Plum = "#DDA0DD"; -export var PowderBlue = "#B0E0E6"; -export var Purple = "#800080"; -export var RebeccaPurple = "#663399"; -export var Red = "#FF0000"; -export var RosyBrown = "#BC8F8F"; -export var RoyalBlue = "#4169E1"; -export var SaddleBrown = "#8B4513"; -export var Salmon = "#FA8072"; -export var SandyBrown = "#F4A460"; -export var SeaGreen = "#2E8B57"; -export var SeaShell = "#FFF5EE"; -export var Sienna = "#A0522D"; -export var Silver = "#C0C0C0"; -export var SkyBlue = "#87CEEB"; -export var SlateBlue = "#6A5ACD"; -export var SlateGray = "#708090"; -export var Snow = "#FFFAFA"; -export var SpringGreen = "#00FF7F"; -export var SteelBlue = "#4682B4"; -export var Tan = "#D2B48C"; -export var Teal = "#008080"; -export var Thistle = "#D8BFD8"; -export var Tomato = "#FF6347"; -export var Turquoise = "#40E0D0"; -export var Violet = "#EE82EE"; -export var Wheat = "#F5DEB3"; -export var White = "#FFFFFF"; -export var WhiteSmoke = "#F5F5F5"; -export var Yellow = "#FFFF00"; -export var YellowGreen = "#9ACD32"; +export const Transparent = "#00000000"; +export const AliceBlue = "#F0F8FF"; +export const AntiqueWhite = "#FAEBD7"; +export const Aqua = "#00FFFF"; +export const Aquamarine = "#7FFFD4"; +export const Azure = "#F0FFFF"; +export const Beige = "#F5F5DC"; +export const Bisque = "#FFE4C4"; +export const Black = "#000000"; +export const BlanchedAlmond = "#FFEBCD"; +export const Blue = "#0000FF"; +export const BlueViolet = "#8A2BE2"; +export const Brown = "#A52A2A"; +export const BurlyWood = "#DEB887"; +export const CadetBlue = "#5F9EA0"; +export const Chartreuse = "#7FFF00"; +export const Chocolate = "#D2691E"; +export const Coral = "#FF7F50"; +export const CornflowerBlue = "#6495ED"; +export const Cornsilk = "#FFF8DC"; +export const Crimson = "#DC143C"; +export const Cyan = "#00FFFF"; +export const DarkBlue = "#00008B"; +export const DarkCyan = "#008B8B"; +export const DarkGoldenRod = "#B8860B"; +export const DarkGray = "#A9A9A9"; +export const DarkGreen = "#006400"; +export const DarkKhaki = "#BDB76B"; +export const DarkMagenta = "#8B008B"; +export const DarkOliveGreen = "#556B2F"; +export const DarkOrange = "#FF8C00"; +export const DarkOrchid = "#9932CC"; +export const DarkRed = "#8B0000"; +export const DarkSalmon = "#E9967A"; +export const DarkSeaGreen = "#8FBC8F"; +export const DarkSlateBlue = "#483D8B"; +export const DarkSlateGray = "#2F4F4F"; +export const DarkTurquoise = "#00CED1"; +export const DarkViolet = "#9400D3"; +export const DeepPink = "#FF1493"; +export const DeepSkyBlue = "#00BFFF"; +export const DimGray = "#696969"; +export const DodgerBlue = "#1E90FF"; +export const FireBrick = "#B22222"; +export const FloralWhite = "#FFFAF0"; +export const ForestGreen = "#228B22"; +export const Fuchsia = "#FF00FF"; +export const Gainsboro = "#DCDCDC"; +export const GhostWhite = "#F8F8FF"; +export const Gold = "#FFD700"; +export const GoldenRod = "#DAA520"; +export const Gray = "#808080"; +export const Green = "#008000"; +export const GreenYellow = "#ADFF2F"; +export const HoneyDew = "#F0FFF0"; +export const HotPink = "#FF69B4"; +export const IndianRed = "#CD5C5C"; +export const Indigo = "#4B0082"; +export const Ivory = "#FFFFF0"; +export const Khaki = "#F0E68C"; +export const Lavender = "#E6E6FA"; +export const LavenderBlush = "#FFF0F5"; +export const LawnGreen = "#7CFC00"; +export const LemonChiffon = "#FFFACD"; +export const LightBlue = "#ADD8E6"; +export const LightCoral = "#F08080"; +export const LightCyan = "#E0FFFF"; +export const LightGoldenRodYellow = "#FAFAD2"; +export const LightGray = "#D3D3D3"; +export const LightGreen = "#90EE90"; +export const LightPink = "#FFB6C1"; +export const LightSalmon = "#FFA07A"; +export const LightSeaGreen = "#20B2AA"; +export const LightSkyBlue = "#87CEFA"; +export const LightSlateGray = "#778899"; +export const LightSteelBlue = "#B0C4DE"; +export const LightYellow = "#FFFFE0"; +export const Lime = "#00FF00"; +export const LimeGreen = "#32CD32"; +export const Linen = "#FAF0E6"; +export const Magenta = "#FF00FF"; +export const Maroon = "#800000"; +export const MediumAquaMarine = "#66CDAA"; +export const MediumBlue = "#0000CD"; +export const MediumOrchid = "#BA55D3"; +export const MediumPurple = "#9370DB"; +export const MediumSeaGreen = "#3CB371"; +export const MediumSlateBlue = "#7B68EE"; +export const MediumSpringGreen = "#00FA9A"; +export const MediumTurquoise = "#48D1CC"; +export const MediumVioletRed = "#C71585"; +export const MidnightBlue = "#191970"; +export const MintCream = "#F5FFFA"; +export const MistyRose = "#FFE4E1"; +export const Moccasin = "#FFE4B5"; +export const NavajoWhite = "#FFDEAD"; +export const Navy = "#000080"; +export const OldLace = "#FDF5E6"; +export const Olive = "#808000"; +export const OliveDrab = "#6B8E23"; +export const Orange = "#FFA500"; +export const OrangeRed = "#FF4500"; +export const Orchid = "#DA70D6"; +export const PaleGoldenRod = "#EEE8AA"; +export const PaleGreen = "#98FB98"; +export const PaleTurquoise = "#AFEEEE"; +export const PaleVioletRed = "#DB7093"; +export const PapayaWhip = "#FFEFD5"; +export const PeachPuff = "#FFDAB9"; +export const Peru = "#CD853F"; +export const Pink = "#FFC0CB"; +export const Plum = "#DDA0DD"; +export const PowderBlue = "#B0E0E6"; +export const Purple = "#800080"; +export const RebeccaPurple = "#663399"; +export const Red = "#FF0000"; +export const RosyBrown = "#BC8F8F"; +export const RoyalBlue = "#4169E1"; +export const SaddleBrown = "#8B4513"; +export const Salmon = "#FA8072"; +export const SandyBrown = "#F4A460"; +export const SeaGreen = "#2E8B57"; +export const SeaShell = "#FFF5EE"; +export const Sienna = "#A0522D"; +export const Silver = "#C0C0C0"; +export const SkyBlue = "#87CEEB"; +export const SlateBlue = "#6A5ACD"; +export const SlateGray = "#708090"; +export const Snow = "#FFFAFA"; +export const SpringGreen = "#00FF7F"; +export const SteelBlue = "#4682B4"; +export const Tan = "#D2B48C"; +export const Teal = "#008080"; +export const Thistle = "#D8BFD8"; +export const Tomato = "#FF6347"; +export const Turquoise = "#40E0D0"; +export const Violet = "#EE82EE"; +export const Wheat = "#F5DEB3"; +export const White = "#FFFFFF"; +export const WhiteSmoke = "#F5F5F5"; +export const Yellow = "#FFFF00"; +export const YellowGreen = "#9ACD32"; -var _allColors = {}; +declare var exports; + +const _allColors = {}; // populate all the declared colors in the _allColors object with name to lower case for faster lookup. -declare var exports; (function () { - var name: string; - var underscore = "_"; - for (var p in exports) { + let name: string; + const underscore = "_"; + for (let p in exports) { name = p; if (name.charAt(0) !== underscore) { _allColors[name.toLowerCase()] = exports[p]; diff --git a/tns-core-modules/css/parser.ts b/tns-core-modules/css/parser.ts index a7451b7c3..b8818caea 100644 --- a/tns-core-modules/css/parser.ts +++ b/tns-core-modules/css/parser.ts @@ -518,7 +518,7 @@ function parseArgumentsList(text: string, start: number, argument: (value: st return { start, end, value }; } - for (var index = 0; true; index++) { + for (let index = 0; true; index++) { const arg = argument(text, end, index); if (!arg) { return null; @@ -1490,7 +1490,7 @@ export class CSSNativeScript { let value = ""; let reading: "property" | "value" = "property"; - for (var i = 0; i < declarationsInputTokens.length; i++) { + for (let i = 0; i < declarationsInputTokens.length; i++) { let inputToken = declarationsInputTokens[i]; if (reading === "property") { if (inputToken === ":") { diff --git a/tns-core-modules/debugger/debugger.ts b/tns-core-modules/debugger/debugger.ts index ae219b2f1..205aaf631 100644 --- a/tns-core-modules/debugger/debugger.ts +++ b/tns-core-modules/debugger/debugger.ts @@ -36,7 +36,7 @@ export namespace domains { } } -var network; +let network; export function getNetwork(): domains.network.NetworkDomainDebugger { return network; @@ -45,7 +45,7 @@ export function setNetwork(newNetwork: domains.network.NetworkDomainDebugger) { network = newNetwork; } -var dom; +let dom; export function getDOM(): any { return dom; @@ -55,7 +55,7 @@ export function setDOM(newDOM) { dom = newDOM; } -var css; +let css; export function getCSS(): any { return css; @@ -121,7 +121,7 @@ export namespace NetworkAgent { // Content-Type and content-type are both common in headers spelling const mimeType: string = headers["Content-Type"] || headers["content-type"] || "application/octet-stream"; const contentLengthHeader: string = headers["Content-Length"] || headers["content-length"]; - var contentLength = parseInt(contentLengthHeader, 10); + let contentLength = parseInt(contentLengthHeader, 10); if (isNaN(contentLength)) { contentLength = 0; } @@ -203,7 +203,7 @@ export namespace NetworkAgent { } function getTimeStamp(): number { - var d = new Date(); + const d = new Date(); return Math.round(d.getTime() / 1000); } diff --git a/tns-core-modules/debugger/webinspector-css.ios.ts b/tns-core-modules/debugger/webinspector-css.ios.ts index 8e7c353f4..d14936be6 100644 --- a/tns-core-modules/debugger/webinspector-css.ios.ts +++ b/tns-core-modules/debugger/webinspector-css.ios.ts @@ -1,5 +1,5 @@ import * as inspectorCommandTypes from "./InspectorBackendCommands.ios"; -var inspectorCommands: typeof inspectorCommandTypes = require("./InspectorBackendCommands"); +const inspectorCommands: typeof inspectorCommandTypes = require("./InspectorBackendCommands"); import * as debuggerDomains from "./debugger"; diff --git a/tns-core-modules/debugger/webinspector-dom.ios.ts b/tns-core-modules/debugger/webinspector-dom.ios.ts index 54f934e34..d62175ccb 100644 --- a/tns-core-modules/debugger/webinspector-dom.ios.ts +++ b/tns-core-modules/debugger/webinspector-dom.ios.ts @@ -1,6 +1,5 @@ import * as inspectorCommandTypes from "./InspectorBackendCommands.ios"; -var inspectorCommands: typeof inspectorCommandTypes = require("./InspectorBackendCommands"); -// var inspectorCommandTypes: any = inspectorCommands; +const inspectorCommands: typeof inspectorCommandTypes = require("./InspectorBackendCommands"); import * as debuggerDomains from "./debugger"; diff --git a/tns-core-modules/debugger/webinspector-network.ios.ts b/tns-core-modules/debugger/webinspector-network.ios.ts index 80b627e6c..06bc44517 100644 --- a/tns-core-modules/debugger/webinspector-network.ios.ts +++ b/tns-core-modules/debugger/webinspector-network.ios.ts @@ -1,5 +1,5 @@ import * as inspectorCommandTypes from "./InspectorBackendCommands.ios"; -var inspectorCommands: typeof inspectorCommandTypes = require("./InspectorBackendCommands"); +const inspectorCommands: typeof inspectorCommandTypes = require("./InspectorBackendCommands"); import * as debuggerDomains from "./debugger"; @@ -10,9 +10,9 @@ declare var __inspectorTimestamp; const frameId = "NativeScriptMainFrameIdentifier"; const loaderId = "Loader Identifier"; -var resources_datas = []; +const resources_datas = []; -var documentTypeByMimeType = { +const documentTypeByMimeType = { "text/xml": "Document", "text/plain": "Document", "text/html": "Document", @@ -54,7 +54,7 @@ export class Request { this._mimeType = value; - var resourceType = "Other"; + let resourceType = "Other"; if (this._mimeType in documentTypeByMimeType) { resourceType = documentTypeByMimeType[this._mimeType]; @@ -169,8 +169,8 @@ export class NetworkDomainDebugger implements inspectorCommandTypes.NetworkDomai * Returns content served for the given request. */ getResponseBody(params: inspectorCommandTypes.NetworkDomain.GetResponseBodyMethodArguments): { body: string, base64Encoded: boolean } { - var resource_data = resources_datas[params.requestId]; - var body = resource_data.hasTextContent ? NSString.alloc().initWithDataEncoding(resource_data.data, 4).toString() : + const resource_data = resources_datas[params.requestId]; + const body = resource_data.hasTextContent ? NSString.alloc().initWithDataEncoding(resource_data.data, 4).toString() : resource_data.data.base64EncodedStringWithOptions(0); if (resource_data) { diff --git a/tns-core-modules/file-system/file-name-resolver/file-name-resolver.ts b/tns-core-modules/file-system/file-name-resolver/file-name-resolver.ts index c010f0b5d..800bb9bdb 100644 --- a/tns-core-modules/file-system/file-name-resolver/file-name-resolver.ts +++ b/tns-core-modules/file-system/file-name-resolver/file-name-resolver.ts @@ -190,9 +190,10 @@ export function _findFileMatch(path: string, ext: string, candidates: Array, context: PlatformContext): number { let result = 0; - for (var i = 0; i < qualifiers.length; i++) { + let value: number; + for (let i = 0; i < qualifiers.length; i++) { if (qualifiers[i]) { - var value = checkQualifier(qualifiers[i], context); + value = checkQualifier(qualifiers[i], context); if (value < 0) { // Non of the supported qualifiers matched this or the match was not satisified return -1; @@ -206,9 +207,10 @@ function checkQualifiers(qualifiers: Array, context: PlatformContext): n } function checkQualifier(value: string, context: PlatformContext) { -for (var i = 0; i < supportedQualifiers.length; i++) { + let result: number; + for (let i = 0; i < supportedQualifiers.length; i++) { if (supportedQualifiers[i].isMatch(value)) { - var result = supportedQualifiers[i].getMatchValue(value, context); + result = supportedQualifiers[i].getMatchValue(value, context); if (result > 0) { result += (supportedQualifiers.length - i) * PRIORITY_STEP; } diff --git a/tns-core-modules/file-system/file-system-access.android.ts b/tns-core-modules/file-system/file-system-access.android.ts index 13da55dd6..60dacb59e 100644 --- a/tns-core-modules/file-system/file-system-access.android.ts +++ b/tns-core-modules/file-system/file-system-access.android.ts @@ -14,7 +14,7 @@ export class FileSystemAccess { private _pathSeparator = "/"; public getLastModified(path: string): Date { - var javaFile = new java.io.File(path); + const javaFile = new java.io.File(path); return new Date(javaFile.lastModified()); } @@ -25,8 +25,8 @@ export class FileSystemAccess { public getParent(path: string, onError?: (error: any) => any): { path: string; name: string } { try { - var javaFile = new java.io.File(path); - var parent = javaFile.getParentFile(); + const javaFile = new java.io.File(path); + const parent = javaFile.getParentFile(); return { path: parent.getAbsolutePath(), name: parent.getName() }; } catch (exception) { @@ -44,8 +44,8 @@ export class FileSystemAccess { } public getFolder(path: string, onError?: (error: any) => any): { path: string; name: string } { - var javaFile = new java.io.File(path); - var dirInfo = this.ensureFile(javaFile, true, onError); + const javaFile = new java.io.File(path); + const dirInfo = this.ensureFile(javaFile, true, onError); if (!dirInfo) { return undefined; } @@ -62,14 +62,14 @@ export class FileSystemAccess { } public getEntities(path: string, onError?: (error: any) => any): Array<{ path: string; name: string; extension: string }> { - var fileInfos = new Array<{ path: string; name: string; extension: string }>(); - var onEntity = function (entity: { path: string; name: string; extension: string }): boolean { + const fileInfos = new Array<{ path: string; name: string; extension: string }>(); + const onEntity = function (entity: { path: string; name: string; extension: string }): boolean { fileInfos.push(entity); return true; } - var errorOccurred; - var localError = function (error: any) { + let errorOccurred; + const localError = function (error: any) { if (onError) { onError(error); } @@ -87,18 +87,18 @@ export class FileSystemAccess { } public fileExists(path: string): boolean { - var file = new java.io.File(path); + const file = new java.io.File(path); return file.exists(); } public folderExists(path: string): boolean { - var file = new java.io.File(path); + const file = new java.io.File(path); return file.exists() && file.isDirectory(); } public deleteFile(path: string, onError?: (error: any) => any) { try { - var javaFile = new java.io.File(path); + const javaFile = new java.io.File(path); if (!javaFile.isFile()) { if (onError) { onError({ message: "The specified parameter is not a File entity." }); @@ -121,7 +121,7 @@ export class FileSystemAccess { public deleteFolder(path: string, onError?: (error: any) => any) { try { - var javaFile = new java.io.File(path); + const javaFile = new java.io.File(path); if (!javaFile.getCanonicalFile().isDirectory()) { if (onError) { onError({ message: "The specified parameter is not a Folder entity." }); @@ -147,7 +147,7 @@ export class FileSystemAccess { public emptyFolder(path: string, onError?: (error: any) => any) { try { - var javaFile = new java.io.File(path); + const javaFile = new java.io.File(path); if (!javaFile.getCanonicalFile().isDirectory()) { if (onError) { onError({ message: "The specified parameter is not a Folder entity." }); @@ -166,7 +166,7 @@ export class FileSystemAccess { } public rename(path: string, newPath: string, onError?: (error: any) => any) { - var javaFile = new java.io.File(path); + const javaFile = new java.io.File(path); if (!javaFile.exists()) { if (onError) { onError(new Error("The file to rename does not exist")); @@ -175,7 +175,7 @@ export class FileSystemAccess { return; } - var newFile = new java.io.File(newPath); + const newFile = new java.io.File(newPath); if (newFile.exists()) { if (onError) { onError(new Error("A file with the same name already exists.")); @@ -192,17 +192,17 @@ export class FileSystemAccess { } public getDocumentsFolderPath(): string { - var dir = getApplicationContext().getFilesDir(); + const dir = getApplicationContext().getFilesDir(); return dir.getAbsolutePath(); } public getLogicalRootPath(): string { - var dir = getApplicationContext().getFilesDir(); + const dir = getApplicationContext().getFilesDir(); return dir.getCanonicalPath(); } public getTempFolderPath(): string { - var dir = getApplicationContext().getCacheDir(); + const dir = getApplicationContext().getCacheDir(); return dir.getAbsolutePath(); } @@ -212,10 +212,10 @@ export class FileSystemAccess { public read(path: string, onError?: (error: any) => any) { try { - var javaFile = new java.io.File(path); - var stream = new java.io.FileInputStream(javaFile); - var bytes = (Array).create("byte", javaFile.length()); - var dataInputStream = new java.io.DataInputStream(stream); + const javaFile = new java.io.File(path); + const stream = new java.io.FileInputStream(javaFile); + const bytes = (Array).create("byte", javaFile.length()); + const dataInputStream = new java.io.DataInputStream(stream); dataInputStream.readFully(bytes); return bytes; } catch (exception) { @@ -227,8 +227,8 @@ export class FileSystemAccess { public write(path: string, bytes: native.Array, onError?: (error: any) => any) { try { - var javaFile = new java.io.File(path); - var stream = new java.io.FileOutputStream(javaFile); + const javaFile = new java.io.File(path); + const stream = new java.io.FileOutputStream(javaFile); stream.write(bytes, 0, bytes.length); stream.close(); } catch (exception) { @@ -240,20 +240,20 @@ export class FileSystemAccess { public readText(path: string, onError?: (error: any) => any, encoding?: any) { try { - var javaFile = new java.io.File(path); - var stream = new java.io.FileInputStream(javaFile); + const javaFile = new java.io.File(path); + const stream = new java.io.FileInputStream(javaFile); - var actualEncoding = encoding; + let actualEncoding = encoding; if (!actualEncoding) { actualEncoding = textModule.encoding.UTF_8; } - var reader = new java.io.InputStreamReader(stream, actualEncoding); - var bufferedReader = new java.io.BufferedReader(reader); + const reader = new java.io.InputStreamReader(stream, actualEncoding); + const bufferedReader = new java.io.BufferedReader(reader); // TODO: We will need to read the entire file to a CharBuffer instead of reading it line by line // TODO: bufferedReader.read(CharBuffer) does not currently work - var line = undefined; - var result = ""; + let line = undefined; + let result = ""; while (true) { line = bufferedReader.readLine(); if (line === null) { @@ -295,14 +295,14 @@ export class FileSystemAccess { public writeText(path: string, content: string, onError?: (error: any) => any, encoding?: any) { try { - var javaFile = new java.io.File(path); - var stream = new java.io.FileOutputStream(javaFile); + const javaFile = new java.io.File(path); + const stream = new java.io.FileOutputStream(javaFile); - var actualEncoding = encoding; + let actualEncoding = encoding; if (!actualEncoding) { actualEncoding = textModule.encoding.UTF_8; } - var writer = new java.io.OutputStreamWriter(stream, actualEncoding); + const writer = new java.io.OutputStreamWriter(stream, actualEncoding); writer.write(content); writer.close(); @@ -314,16 +314,15 @@ export class FileSystemAccess { } private deleteFolderContent(file: java.io.File): boolean { - var filesList = file.listFiles(); + const filesList = file.listFiles(); if (filesList.length === 0) { return true; // Nothing to delete, so success! } - var i, - childFile: java.io.File, - success: boolean = false; + let childFile: java.io.File; + let success: boolean = false; - for (i = 0; i < filesList.length; i++) { + for (let i = 0; i < filesList.length; i++) { childFile = filesList[i]; if (childFile.getCanonicalFile().isDirectory()) { success = this.deleteFolderContent(childFile); @@ -341,7 +340,7 @@ export class FileSystemAccess { private ensureFile(javaFile: java.io.File, isFolder: boolean, onError?: (error: any) => any): { path: string; name: string; extension: string } { try { if (!javaFile.exists()) { - var created; + let created; if (isFolder) { created = javaFile.mkdirs(); } else { @@ -362,7 +361,7 @@ export class FileSystemAccess { } } - var path = javaFile.getAbsolutePath(); + const path = javaFile.getAbsolutePath(); return { path: path, name: javaFile.getName(), extension: this.getFileExtension(path) }; } catch (exception) { // TODO: unified approach for error messages @@ -377,7 +376,7 @@ export class FileSystemAccess { // TODO: This method is the same as in the iOS implementation. // Make it in a separate file / module so it can be reused from both implementations. private getFileExtension(path: string): string { - var dotIndex = path.lastIndexOf("."); + const dotIndex = path.lastIndexOf("."); if (dotIndex && dotIndex >= 0 && dotIndex < path.length) { return path.substring(dotIndex); } @@ -387,7 +386,7 @@ export class FileSystemAccess { private enumEntities(path: string, callback: (entity: { path: string; name: string; extension: string }) => boolean, onError?: (error) => any) { try { - var javaFile = new java.io.File(path); + let javaFile = new java.io.File(path); if (!javaFile.getCanonicalFile().isDirectory()) { if (onError) { onError("There is no folder existing at path " + path); @@ -396,13 +395,12 @@ export class FileSystemAccess { return; } - var filesList = javaFile.listFiles(); - var length = filesList.length; - var i; - var info; - var retVal; + const filesList = javaFile.listFiles(); + const length = filesList.length; + let info; + let retVal; - for (i = 0; i < length; i++) { + for (let i = 0; i < length; i++) { javaFile = filesList[i]; info = { @@ -431,13 +429,13 @@ export class FileSystemAccess { } public normalizePath(path: string): string { - var file = new java.io.File(path); + const file = new java.io.File(path); return file.getAbsolutePath(); } public joinPath(left: string, right: string): string { - var file1 = new java.io.File(left); - var file2 = new java.io.File(file1, right); + const file1 = new java.io.File(left); + const file2 = new java.io.File(file1, right); return file2.getPath(); } @@ -451,9 +449,8 @@ export class FileSystemAccess { return paths[0]; } - var i, - result = paths[0]; - for (i = 1; i < paths.length; i++) { + let result = paths[0]; + for (let i = 1; i < paths.length; i++) { result = this.joinPath(result, paths[i]); } diff --git a/tns-core-modules/file-system/file-system.d.ts b/tns-core-modules/file-system/file-system.d.ts index ffed227c9..d3c6e1023 100644 --- a/tns-core-modules/file-system/file-system.d.ts +++ b/tns-core-modules/file-system/file-system.d.ts @@ -279,5 +279,5 @@ export module path { /** * Gets the string used to separate file paths. */ - export var separator: string; + export const separator: string; } diff --git a/tns-core-modules/file-system/file-system.ts b/tns-core-modules/file-system/file-system.ts index 14fab4118..da7144d35 100644 --- a/tns-core-modules/file-system/file-system.ts +++ b/tns-core-modules/file-system/file-system.ts @@ -1,12 +1,14 @@ -import * as file_access_module from "./file-system-access"; +// imported for definition purposes only import * as platformModule from "../platform"; + +import { FileSystemAccess } from "./file-system-access"; import { profile } from "../profiling"; // The FileSystemAccess implementation, used through all the APIs. -var fileAccess; -var getFileAccess = function (): file_access_module.FileSystemAccess { +let fileAccess: FileSystemAccess; +function getFileAccess(): FileSystemAccess { if (!fileAccess) { - fileAccess = new file_access_module.FileSystemAccess(); + fileAccess = new FileSystemAccess(); } return fileAccess; @@ -19,8 +21,8 @@ function ensurePlatform() { } } -var createFile = function (info: { path: string; name: string; extension: string }) { - var file = new File(); +function createFile(info: { path: string; name: string; extension: string }) { + const file = new File(); file._path = info.path; file._name = info.name; file._extension = info.extension; @@ -28,18 +30,18 @@ var createFile = function (info: { path: string; name: string; extension: string return file; }; -var createFolder = function (info: { path: string; name: string; }) { - var documents = knownFolders.documents(); +function createFolder(info: { path: string; name: string; }) { + const documents = knownFolders.documents(); if (info.path === documents.path) { return documents; } - var temp = knownFolders.temp(); + const temp = knownFolders.temp(); if (info.path === temp.path) { return temp; } - var folder = new Folder(); + const folder = new Folder(); folder._path = info.path; folder._name = info.name; @@ -56,11 +58,11 @@ export class FileSystemEntity { _isKnown: boolean; get parent(): Folder { - var onError = function (error) { + const onError = function (error) { throw error; } - var folderInfo = getFileAccess().getParent(this.path, onError); + const folderInfo = getFileAccess().getParent(this.path, onError); if (!folderInfo) { return undefined; } @@ -70,8 +72,8 @@ export class FileSystemEntity { public remove(): Promise { return new Promise((resolve, reject) => { - var hasError = false; - var localError = function (error: any) { + let hasError = false; + const localError = function (error: any) { hasError = true; reject(error); }; @@ -92,7 +94,7 @@ export class FileSystemEntity { return; } - var fileAccess = getFileAccess(); + const fileAccess = getFileAccess(); if (this instanceof File) { fileAccess.deleteFile(this.path, onError); @@ -103,8 +105,8 @@ export class FileSystemEntity { public rename(newName: string): Promise { return new Promise((resolve, reject) => { - var hasError = false; - var localError = function (error) { + let hasError = false; + const localError = function (error) { hasError = true; reject(error); } @@ -125,22 +127,24 @@ export class FileSystemEntity { return; } - var parentFolder = this.parent; + const parentFolder = this.parent; if (!parentFolder) { if (onError) { onError(new Error("No parent folder.")); } + return; } - var fileAccess = getFileAccess(); - var path = parentFolder.path; - var newPath = fileAccess.joinPath(path, newName); + const fileAccess = getFileAccess(); + const path = parentFolder.path; + const newPath = fileAccess.joinPath(path, newName); - var localError = function (error) { + const localError = function (error) { if (onError) { onError(error); } + return null; } @@ -162,7 +166,7 @@ export class FileSystemEntity { } get lastModified(): Date { - var value = this._lastModified; + let value = this._lastModified; if (!this._lastModified) { value = this._lastModified = getFileAccess().getLastModified(this.path); } @@ -173,11 +177,11 @@ export class FileSystemEntity { export class File extends FileSystemEntity { public static fromPath(path: string) { - var onError = function (error) { + const onError = function (error) { throw error; } - var fileInfo = getFileAccess().getFile(path, onError); + const fileInfo = getFileAccess().getFile(path, onError); if (!fileInfo) { return undefined; } @@ -207,15 +211,15 @@ export class File extends FileSystemEntity { this._locked = true; - var that = this; - var localError = (error) => { + const that = this; + const localError = (error) => { that._locked = false; if (onError) { onError(error); } }; - var content = getFileAccess().read(this.path, localError); + const content = getFileAccess().read(this.path, localError); this._locked = false; @@ -229,8 +233,8 @@ export class File extends FileSystemEntity { try { this._locked = true; - var that = this; - var localError = function (error) { + const that = this; + const localError = function (error) { that._locked = false; if (onError) { onError(error); @@ -245,13 +249,13 @@ export class File extends FileSystemEntity { public readText(encoding?: string): Promise { return new Promise((resolve, reject) => { - var hasError = false; - var localError = (error) => { + let hasError = false; + const localError = (error) => { hasError = true; reject(error); }; - var content = this.readTextSync(localError, encoding); + const content = this.readTextSync(localError, encoding); if (!hasError) { resolve(content); } @@ -264,15 +268,15 @@ export class File extends FileSystemEntity { this._locked = true; - var that = this; - var localError = (error) => { + const that = this; + const localError = (error) => { that._locked = false; if (onError) { onError(error); } }; - var content = getFileAccess().readText(this.path, localError, encoding); + const content = getFileAccess().readText(this.path, localError, encoding); this._locked = false; return content; @@ -280,8 +284,8 @@ export class File extends FileSystemEntity { public writeText(content: string, encoding?: string): Promise { return new Promise((resolve, reject) => { - var hasError = false; - var localError = function (error) { + let hasError = false; + const localError = function (error) { hasError = true; reject(error); }; @@ -299,8 +303,8 @@ export class File extends FileSystemEntity { try { this._locked = true; - var that = this; - var localError = function (error) { + const that = this; + const localError = function (error) { that._locked = false; if (onError) { onError(error); @@ -323,11 +327,11 @@ export class File extends FileSystemEntity { export class Folder extends FileSystemEntity { public static fromPath(path: string): Folder { - var onError = function (error) { + const onError = function (error) { throw error; } - var folderInfo = getFileAccess().getFolder(path, onError); + const folderInfo = getFileAccess().getFolder(path, onError); if (!folderInfo) { return undefined; } @@ -340,8 +344,8 @@ export class Folder extends FileSystemEntity { } public contains(name: string): boolean { - var fileAccess = getFileAccess(); - var path = fileAccess.joinPath(this.path, name); + const fileAccess = getFileAccess(); + const path = fileAccess.joinPath(this.path, name); if (fileAccess.fileExists(path)) { return true; @@ -352,8 +356,8 @@ export class Folder extends FileSystemEntity { public clear(): Promise { return new Promise((resolve, reject) => { - var hasError = false; - var onError = function (error) { + let hasError = false; + const onError = function (error) { hasError = true; reject(error); }; @@ -374,14 +378,14 @@ export class Folder extends FileSystemEntity { } public getFile(name: string): File { - var fileAccess = getFileAccess(); - var path = fileAccess.joinPath(this.path, name); + const fileAccess = getFileAccess(); + const path = fileAccess.joinPath(this.path, name); - var onError = function (error) { + const onError = function (error) { throw error; } - var fileInfo = fileAccess.getFile(path, onError); + const fileInfo = fileAccess.getFile(path, onError); if (!fileInfo) { return undefined; } @@ -390,14 +394,14 @@ export class Folder extends FileSystemEntity { } public getFolder(name: string): Folder { - var fileAccess = getFileAccess(); - var path = fileAccess.joinPath(this.path, name); + const fileAccess = getFileAccess(); + const path = fileAccess.joinPath(this.path, name); - var onError = function (error) { + const onError = function (error) { throw error; } - var folderInfo = fileAccess.getFolder(path, onError); + const folderInfo = fileAccess.getFolder(path, onError); if (!folderInfo) { return undefined; } @@ -407,13 +411,13 @@ export class Folder extends FileSystemEntity { public getEntities(): Promise> { return new Promise((resolve, reject) => { - var hasError = false; - var localError = function (error) { + let hasError = false; + const localError = function (error) { hasError = true; reject(error); }; - var entities = this.getEntitiesSync(localError); + const entities = this.getEntitiesSync(localError); if (!hasError) { resolve(entities); } @@ -421,15 +425,13 @@ export class Folder extends FileSystemEntity { } public getEntitiesSync(onError?: (error: any) => any): Array { - var fileInfos = getFileAccess().getEntities(this.path, onError); + const fileInfos = getFileAccess().getEntities(this.path, onError); if (!fileInfos) { return null; } - var entities = new Array(); - - var i; - for (i = 0; i < fileInfos.length; i++) { + const entities = new Array(); + for (let i = 0; i < fileInfos.length; i++) { if (fileInfos[i].extension) { entities.push(createFile(fileInfos[i])); } else { @@ -445,8 +447,8 @@ export class Folder extends FileSystemEntity { return; } - var onSuccess = function (fileInfo: { path: string; name: string; extension: string }): boolean { - var entity; + const onSuccess = function (fileInfo: { path: string; name: string; extension: string }): boolean { + let entity; if (fileInfo.extension) { entity = createFile(fileInfo); } else { @@ -456,7 +458,7 @@ export class Folder extends FileSystemEntity { return onEntity(entity); } - var onError = function (error) { + const onError = function (error) { throw error; } @@ -465,13 +467,13 @@ export class Folder extends FileSystemEntity { } export module knownFolders { - var _documents: Folder; - var _temp: Folder; - var _app: Folder; + let _documents: Folder; + let _temp: Folder; + let _app: Folder; - export var documents = function (): Folder { + export function documents(): Folder { if (!_documents) { - var path = getFileAccess().getDocumentsFolderPath(); + const path = getFileAccess().getDocumentsFolderPath(); _documents = new Folder(); _documents._path = path; _documents._isKnown = true; @@ -480,9 +482,9 @@ export module knownFolders { return _documents; }; - export var temp = function (): Folder { + export function temp(): Folder { if (!_temp) { - var path = getFileAccess().getTempFolderPath(); + const path = getFileAccess().getTempFolderPath(); _temp = new Folder(); _temp._path = path; _temp._isKnown = true; @@ -491,9 +493,9 @@ export module knownFolders { return _temp; }; - export var currentApp = function (): Folder { + export function currentApp(): Folder { if (!_app) { - var path = getFileAccess().getCurrentAppPath(); + const path = getFileAccess().getCurrentAppPath(); _app = new Folder(); _app._path = path; _app._isKnown = true; @@ -511,7 +513,7 @@ export module knownFolders { } let _library: Folder; - export var library = function(): Folder { + export function library(): Folder { _checkPlatform("library"); if (!_library) { let existingFolderInfo = getExistingFolderInfo(NSSearchPathDirectory.LibraryDirectory); @@ -527,7 +529,7 @@ export module knownFolders { }; let _developer: Folder; - export var developer = function(): Folder { + export function developer(): Folder { _checkPlatform("developer"); if (!_developer) { let existingFolderInfo = getExistingFolderInfo(NSSearchPathDirectory.DeveloperDirectory); @@ -543,7 +545,7 @@ export module knownFolders { }; let _desktop: Folder; - export var desktop = function(): Folder { + export function desktop(): Folder { _checkPlatform("desktop"); if (!_desktop) { let existingFolderInfo = getExistingFolderInfo(NSSearchPathDirectory.DesktopDirectory); @@ -559,7 +561,7 @@ export module knownFolders { }; let _downloads: Folder; - export var downloads = function(): Folder { + export function downloads(): Folder { _checkPlatform("downloads"); if (!_downloads) { let existingFolderInfo = getExistingFolderInfo(NSSearchPathDirectory.DownloadsDirectory); @@ -575,7 +577,7 @@ export module knownFolders { }; let _movies: Folder; - export var movies = function(): Folder { + export function movies(): Folder { _checkPlatform("movies"); if (!_movies) { let existingFolderInfo = getExistingFolderInfo(NSSearchPathDirectory.MoviesDirectory); @@ -591,7 +593,7 @@ export module knownFolders { }; let _music: Folder; - export var music = function(): Folder { + export function music(): Folder { _checkPlatform("music"); if (!_music) { let existingFolderInfo = getExistingFolderInfo(NSSearchPathDirectory.MusicDirectory); @@ -607,7 +609,7 @@ export module knownFolders { }; let _pictures: Folder; - export var pictures = function(): Folder { + export function pictures(): Folder { _checkPlatform("pictures"); if (!_pictures) { let existingFolderInfo = getExistingFolderInfo(NSSearchPathDirectory.PicturesDirectory); @@ -623,7 +625,7 @@ export module knownFolders { }; let _sharedPublic: Folder; - export var sharedPublic = function(): Folder { + export function sharedPublic(): Folder { _checkPlatform("sharedPublic"); if (!_sharedPublic) { let existingFolderInfo = getExistingFolderInfo(NSSearchPathDirectory.SharedPublicDirectory); @@ -639,9 +641,9 @@ export module knownFolders { }; function getExistingFolderInfo(pathDirectory: any /* NSSearchPathDirectory */): { folder: Folder; path: string } { - var fileAccess = (getFileAccess()); - var folderPath = fileAccess.getKnownPath(pathDirectory); - var folderInfo = fileAccess.getExistingFolder(folderPath); + const fileAccess = (getFileAccess()); + const folderPath = fileAccess.getKnownPath(pathDirectory); + const folderInfo = fileAccess.getExistingFolder(folderPath); if (folderInfo) { return { @@ -661,9 +663,9 @@ export module path { } export function join(...paths: string[]): string { - var fileAccess = getFileAccess(); + const fileAccess = getFileAccess(); return fileAccess.joinPaths(paths); } - export var separator = getFileAccess().getPathSeparator(); + export const separator = getFileAccess().getPathSeparator(); } diff --git a/tns-core-modules/globals/globals.ts b/tns-core-modules/globals/globals.ts index d4b6fa6d5..7e4715852 100644 --- a/tns-core-modules/globals/globals.ts +++ b/tns-core-modules/globals/globals.ts @@ -4,7 +4,7 @@ require("./ts-helpers"); // 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. global.moduleMerge = function (sourceExports: any, destExports: any) { - for (var key in sourceExports) { + for (let key in sourceExports) { destExports[key] = sourceExports[key]; } } @@ -135,10 +135,10 @@ export function install() { if ((global).__snapshot || (global).__snapshotEnabled) { if (!snapshotGlobals) { // require in snapshot mode is cheap - var timer: typeof timerModule = require("timer"); - var dialogs: typeof dialogsModule = require("ui/dialogs"); - var xhr = require("xhr"); - var fetch = require("fetch"); + const timer: typeof timerModule = require("timer"); + const dialogs: typeof dialogsModule = require("ui/dialogs"); + const xhr = require("xhr"); + const fetch = require("fetch"); snapshotGlobals = snapshotGlobals || { setTimeout: timer.setTimeout, @@ -161,7 +161,7 @@ export function install() { Response: fetch.Response, } } - var consoleModule = require("console").Console; + const consoleModule = require("console").Console; // Object.assign call will fire an error when trying to write to a read-only property of an object, such as 'console' global.console = global.console || new consoleModule(); Object.assign(global, snapshotGlobals); @@ -190,7 +190,7 @@ install(); export function Deprecated(target: Object, key?: string | symbol, descriptor?: any) { if (descriptor) { - var originalMethod = descriptor.value; + const originalMethod = descriptor.value; descriptor.value = function (...args: any[]) { console.log(`${key.toString()} is deprecated`); @@ -209,7 +209,7 @@ global.Deprecated = Deprecated; export function Experimental(target: Object, key?: string | symbol, descriptor?: any) { if (descriptor) { - var originalMethod = descriptor.value; + const originalMethod = descriptor.value; descriptor.value = function (...args: any[]) { console.log(`${key.toString()} is experimental`); diff --git a/tns-core-modules/globals/ts-helpers.ts b/tns-core-modules/globals/ts-helpers.ts index bee3c471e..337b37b9f 100644 --- a/tns-core-modules/globals/ts-helpers.ts +++ b/tns-core-modules/globals/ts-helpers.ts @@ -1,7 +1,7 @@ // Required by V8 snapshot generator if (!global.__extends) { global.__extends = function (d, b) { - for (var p in b) { + for (let p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } diff --git a/tns-core-modules/http/http-request/http-request.d.ts b/tns-core-modules/http/http-request/http-request.d.ts index 5907ee534..59261430a 100644 --- a/tns-core-modules/http/http-request/http-request.d.ts +++ b/tns-core-modules/http/http-request/http-request.d.ts @@ -6,5 +6,5 @@ //@private import * as http from ".."; -export var request: (options: http.HttpRequestOptions) => Promise; +export const request: (options: http.HttpRequestOptions) => Promise; export function addHeader(headers: http.Headers, key: string, value: string): void; diff --git a/tns-core-modules/http/http.ts b/tns-core-modules/http/http.ts index 251aa7c00..26300c277 100644 --- a/tns-core-modules/http/http.ts +++ b/tns-core-modules/http/http.ts @@ -7,7 +7,7 @@ export function getString(arg: any): Promise { httpRequest.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) .then(r => { try { - var str = r.content.toString(); + const str = r.content.toString(); resolve(str); } catch (e) { reject(e); @@ -21,7 +21,7 @@ export function getJSON(arg: any): Promise { httpRequest.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) .then(r => { try { - var json = r.content.toJSON(); + const json = r.content.toJSON(); resolve(json); } catch (e) { reject(e); @@ -50,7 +50,7 @@ export function getFile(arg: any, destinationFilePath?: string): Promise { httpRequest.request(typeof arg === "string" ? { url: arg, method: "GET" } : arg) .then(r => { try { - var file = r.content.toFile(destinationFilePath); + const file = r.content.toFile(destinationFilePath); resolve(file); } catch (e) { reject(e); diff --git a/tns-core-modules/image-asset/image-asset-common.ts b/tns-core-modules/image-asset/image-asset-common.ts index 0bed79c2c..3897d833c 100644 --- a/tns-core-modules/image-asset/image-asset-common.ts +++ b/tns-core-modules/image-asset/image-asset-common.ts @@ -47,10 +47,10 @@ export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, req } export function getRequestedImageSize(src: { width: number, height: number }, options: definition.ImageAssetOptions): { width: number, height: number } { - var screen = platform.screen.mainScreen; + const screen = platform.screen.mainScreen; - var reqWidth = options.width || Math.min(src.width, screen.widthPixels); - var reqHeight = options.height || Math.min(src.height, screen.heightPixels); + let reqWidth = options.width || Math.min(src.width, screen.widthPixels); + let reqHeight = options.height || Math.min(src.height, screen.heightPixels); if (options && options.keepAspectRatio) { let safeAspectSize = getAspectSafeDimensions(src.width, src.height, reqWidth, reqHeight); diff --git a/tns-core-modules/image-asset/image-asset.android.ts b/tns-core-modules/image-asset/image-asset.android.ts index 411b772a4..2d7ace664 100644 --- a/tns-core-modules/image-asset/image-asset.android.ts +++ b/tns-core-modules/image-asset/image-asset.android.ts @@ -69,7 +69,7 @@ export class ImageAsset extends common.ImageAsset { } } -var calculateAngleFromFile = function (filename: string) { +function calculateAngleFromFile(filename: string) { let rotationAngle = 0; const ei = new android.media.ExifInterface(filename); const orientation = ei.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL); diff --git a/tns-core-modules/image-source/image-source.ios.ts b/tns-core-modules/image-source/image-source.ios.ts index c5228b80f..be18c1056 100644 --- a/tns-core-modules/image-source/image-source.ios.ts +++ b/tns-core-modules/image-source/image-source.ios.ts @@ -106,7 +106,7 @@ export class ImageSource implements ImageSourceDefinition { public fromBase64(source: string): Promise { return new Promise((resolve, reject) => { try { - var data = NSData.alloc().initWithBase64EncodedStringOptions(source, NSDataBase64DecodingOptions.IgnoreUnknownCharacters); + const data = NSData.alloc().initWithBase64EncodedStringOptions(source, NSDataBase64DecodingOptions.IgnoreUnknownCharacters); UIImage.imageWithData["async"](UIImage, [data]).then(image => { this.ios = image; resolve(true); @@ -191,7 +191,7 @@ function getFileName(path: string): string { } function getImageData(instance: UIImage, format: "png" | "jpeg" | "jpg", quality = 0.9): NSData { - var data = null; + let data = null; switch (format) { case "png": data = UIImagePNGRepresentation(instance); @@ -201,6 +201,7 @@ function getImageData(instance: UIImage, format: "png" | "jpeg" | "jpg", quality data = UIImageJPEGRepresentation(instance, quality); break; } + return data; } diff --git a/tns-core-modules/js-libs/esprima/esprima.d.ts b/tns-core-modules/js-libs/esprima/esprima.d.ts index 9ce9dd962..c0570dabb 100644 --- a/tns-core-modules/js-libs/esprima/esprima.d.ts +++ b/tns-core-modules/js-libs/esprima/esprima.d.ts @@ -9,7 +9,7 @@ // Definitions by: teppeis // Definitions: https://github.com/borisyankov/DefinitelyTyped -export var version: string; +export const version: string; export function parse(code: string, options?: Options): Syntax.Program; export function tokenize(code: string, options?: Options): Array; diff --git a/tns-core-modules/platform/platform.d.ts b/tns-core-modules/platform/platform.d.ts index 94aaf9967..bc08f2c58 100644 --- a/tns-core-modules/platform/platform.d.ts +++ b/tns-core-modules/platform/platform.d.ts @@ -8,19 +8,19 @@ /** * Gets a value indicating if the app is running on the Android platform. */ -export var isAndroid: boolean; +export const isAndroid: boolean; /** * Gets a value indicating if the app is running on the iOS platform. */ -export var isIOS: boolean; +export const isIOS: boolean; /* * Enum holding platform names. */ export module platformNames { - export var android: string; - export var ios: string; + export const android: string; + export const ios: string; } /* @@ -119,10 +119,10 @@ export module screen { /** * Gets information about the main screen of the current device. */ - export var mainScreen: ScreenMetrics; + export const mainScreen: ScreenMetrics; } /** * Gets the current device information. */ -export var device: Device; +export const device: Device; diff --git a/tns-core-modules/platform/platform.ios.ts b/tns-core-modules/platform/platform.ios.ts index f9fd215d8..881b34e85 100644 --- a/tns-core-modules/platform/platform.ios.ts +++ b/tns-core-modules/platform/platform.ios.ts @@ -62,9 +62,9 @@ class Device implements DeviceDefinition { } get uuid(): string { - var userDefaults = NSUserDefaults.standardUserDefaults; - var uuid_key = "TNSUUID"; - var app_uuid = userDefaults.stringForKey(uuid_key); + const userDefaults = NSUserDefaults.standardUserDefaults; + const uuid_key = "TNSUUID"; + let app_uuid = userDefaults.stringForKey(uuid_key); if (!app_uuid) { app_uuid = NSUUID.UUID().UUIDString; @@ -77,7 +77,7 @@ class Device implements DeviceDefinition { get language(): string { if (!this._language) { - var languages = NSLocale.preferredLanguages; + const languages = NSLocale.preferredLanguages; this._language = languages[0]; } diff --git a/tns-core-modules/profiling/profiling.ts b/tns-core-modules/profiling/profiling.ts index dd8bb5257..e2c521ad8 100644 --- a/tns-core-modules/profiling/profiling.ts +++ b/tns-core-modules/profiling/profiling.ts @@ -177,7 +177,7 @@ const profileMethodUnnamed = (target, key, descriptor) => { if (descriptor === undefined) { descriptor = Object.getOwnPropertyDescriptor(target, key); } - var originalMethod = descriptor.value; + const originalMethod = descriptor.value; let className = ""; if (target && target.constructor && target.constructor.name) { @@ -199,7 +199,7 @@ const profileStaticMethodUnnamed = (ctor, key, descriptor) => { if (descriptor === undefined) { descriptor = Object.getOwnPropertyDescriptor(ctor, key); } - var originalMethod = descriptor.value; + const originalMethod = descriptor.value; let className = ""; if (ctor && ctor.name) { @@ -222,7 +222,7 @@ function profileMethodNamed(name: string): MethodDecorator { if (descriptor === undefined) { descriptor = Object.getOwnPropertyDescriptor(target, key); } - var originalMethod = descriptor.value; + const originalMethod = descriptor.value; //editing the descriptor/value parameter descriptor.value = profileFunctionFactory(originalMethod, name); diff --git a/tns-core-modules/text/text.android.ts b/tns-core-modules/text/text.android.ts index c94c44641..f21c80c3c 100644 --- a/tns-core-modules/text/text.android.ts +++ b/tns-core-modules/text/text.android.ts @@ -1,8 +1,8 @@ export module encoding { - export var ISO_8859_1 = "ISO-8859-1"; - export var US_ASCII = "US-ASCII"; - export var UTF_16 = "UTF-16"; - export var UTF_16BE = "UTF-16BE"; - export var UTF_16LE = "UTF-16LE"; - export var UTF_8 = "UTF-8"; + export const ISO_8859_1 = "ISO-8859-1"; + export const US_ASCII = "US-ASCII"; + export const UTF_16 = "UTF-16"; + export const UTF_16BE = "UTF-16BE"; + export const UTF_16LE = "UTF-16LE"; + export const UTF_8 = "UTF-8"; } \ No newline at end of file diff --git a/tns-core-modules/text/text.d.ts b/tns-core-modules/text/text.d.ts index b6712ee26..7e572947e 100644 --- a/tns-core-modules/text/text.d.ts +++ b/tns-core-modules/text/text.d.ts @@ -10,30 +10,30 @@ export module encoding { /** * Denotes ISO-8859-1 character encoding. */ - export var ISO_8859_1: any; + export const ISO_8859_1: any; /** * Denotes US_ASCII character encoding. */ - export var US_ASCII: any; + export const US_ASCII: any; /** * Denotes UTF_16 character encoding. */ - export var UTF_16: any; + export const UTF_16: any; /** * Denotes UTF_16BE character encoding. */ - export var UTF_16BE: any; + export const UTF_16BE: any; /** * Denotes UTF_16LE character encoding. */ - export var UTF_16LE: any; + export const UTF_16LE: any; /** * Denotes UTF_8 character encoding. */ - export var UTF_8: any; + export const UTF_8: any; } diff --git a/tns-core-modules/text/text.ios.ts b/tns-core-modules/text/text.ios.ts index 228c03df5..55b9659ce 100644 --- a/tns-core-modules/text/text.ios.ts +++ b/tns-core-modules/text/text.ios.ts @@ -1,8 +1,8 @@ export module encoding { - export var ISO_8859_1 = 5; //NSISOLatin1StringEncoding - export var US_ASCII = 1; //NSASCIIStringEncoding - export var UTF_16 = 10; //NSUnicodeStringEncoding - export var UTF_16BE = 0x90000100; //NSUTF16BigEndianStringEncoding - export var UTF_16LE = 0x94000100; //NSUTF16LittleEndianStringEncoding - export var UTF_8 = 4; //NSUTF8StringEncoding + export const ISO_8859_1 = 5; //NSISOLatin1StringEncoding + export const US_ASCII = 1; //NSASCIIStringEncoding + export const UTF_16 = 10; //NSUnicodeStringEncoding + export const UTF_16BE = 0x90000100; //NSUTF16BigEndianStringEncoding + export const UTF_16LE = 0x94000100; //NSUTF16LittleEndianStringEncoding + export const UTF_8 = 4; //NSUTF8StringEncoding } \ No newline at end of file diff --git a/tns-core-modules/timer/timer.android.ts b/tns-core-modules/timer/timer.android.ts index beedf6ea5..1551d9a8f 100644 --- a/tns-core-modules/timer/timer.android.ts +++ b/tns-core-modules/timer/timer.android.ts @@ -1,9 +1,9 @@ /** * Android specific timer functions implementation. */ -var timeoutHandler; -var timeoutCallbacks = {}; -var timerId = 0; +let timeoutHandler; +const timeoutCallbacks = {}; +let timerId = 0; function createHandlerAndGetId(): number { if (!timeoutHandler) { @@ -19,7 +19,7 @@ export function setTimeout(callback: Function, milliseconds = 0, ...args): numbe const invoke = () => callback(...args); const zoneBound = zonedCallback(invoke); - var runnable = new java.lang.Runnable({ + const runnable = new java.lang.Runnable({ run: () => { zoneBound(); @@ -52,7 +52,7 @@ export function setInterval(callback: Function, milliseconds = 0, ...args): numb const invoke = () => callback(...args); const zoneBound = zonedCallback(invoke); - var runnable = new java.lang.Runnable({ + const runnable = new java.lang.Runnable({ run: () => { zoneBound(); if (timeoutCallbacks[id]) { @@ -70,4 +70,4 @@ export function setInterval(callback: Function, milliseconds = 0, ...args): numb return id; } -export var clearInterval = clearTimeout; +export const clearInterval = clearTimeout; diff --git a/tns-core-modules/timer/timer.ios.ts b/tns-core-modules/timer/timer.ios.ts index 097a19bdf..88dbb036f 100644 --- a/tns-core-modules/timer/timer.ios.ts +++ b/tns-core-modules/timer/timer.ios.ts @@ -1,8 +1,8 @@ import * as utils from "../utils/utils"; //iOS specific timer functions implementation. -var timeoutCallbacks = new Map>(); -var timerId = 0; +const timeoutCallbacks = new Map>(); +let timerId = 0; interface KeyValuePair { k: K; @@ -80,4 +80,4 @@ export function setInterval(callback: Function, milliseconds = 0, ...args): numb return createTimerAndGetId(zonedCallback(invoke), milliseconds, true); } -export var clearInterval = clearTimeout; +export const clearInterval = clearTimeout; diff --git a/tns-core-modules/trace/trace.d.ts b/tns-core-modules/trace/trace.d.ts index ef818be8a..838a8729f 100644 --- a/tns-core-modules/trace/trace.d.ts +++ b/tns-core-modules/trace/trace.d.ts @@ -88,22 +88,22 @@ export function setErrorHandler(handler: ErrorHandler); * An enum that defines all predefined categories. */ export module categories { - export var VisualTreeEvents: string; - export var Layout: string; - export var Style: string; - export var ViewHierarchy: string; - export var NativeLifecycle: string; - export var Debug: string; - export var Navigation: string; - export var Test: string; - export var Binding: string; - export var Error: string; - export var Animation: string; - export var Transition: string; + export const VisualTreeEvents: string; + export const Layout: string; + export const Style: string; + export const ViewHierarchy: string; + export const NativeLifecycle: string; + export const Debug: string; + export const Navigation: string; + export const Test: string; + export const Binding: string; + export const Error: string; + export const Animation: string; + export const Transition: string; - export var All: string; + export const All: string; - export var separator: string; + export const separator: string; export function concat(...categories: string[]): string; } @@ -111,10 +111,10 @@ export module categories { * An enum that defines all predefined message types. */ export module messageType { - export var log: number; - export var info: number; - export var warn: number; - export var error: number; + export const log: number; + export const info: number; + export const warn: number; + export const error: number; } /** diff --git a/tns-core-modules/trace/trace.ts b/tns-core-modules/trace/trace.ts index 7c7c84664..497fcf11e 100644 --- a/tns-core-modules/trace/trace.ts +++ b/tns-core-modules/trace/trace.ts @@ -102,41 +102,40 @@ export function addEventListener(listener: EventListener) { } export function removeEventListener(listener: EventListener) { - var index = _eventListeners.indexOf(listener); + const index = _eventListeners.indexOf(listener); if (index >= 0) { _eventListeners.splice(index, 1); } } export module messageType { - export var log = 0; - export var info = 1; - export var warn = 2; - export var error = 3; + export const log = 0; + export const info = 1; + export const warn = 2; + export const error = 3; } export module categories { - export var VisualTreeEvents = "VisualTreeEvents"; - export var Layout = "Layout"; - export var Style = "Style"; - export var ViewHierarchy = "ViewHierarchy"; - export var NativeLifecycle = "NativeLifecycle"; - export var Debug = "Debug"; - export var Navigation = "Navigation"; - export var Test = "Test"; - export var Binding = "Binding"; - export var BindingError = "BindingError"; - export var Error = "Error"; - export var Animation = "Animation"; - export var Transition = "Transition"; - export var All = VisualTreeEvents + "," + Layout + "," + Style + "," + ViewHierarchy + "," + NativeLifecycle + "," + Debug + "," + Navigation + "," + Test + "," + Binding + "," + Error + "," + Animation + "," + Transition; + export const VisualTreeEvents = "VisualTreeEvents"; + export const Layout = "Layout"; + export const Style = "Style"; + export const ViewHierarchy = "ViewHierarchy"; + export const NativeLifecycle = "NativeLifecycle"; + export const Debug = "Debug"; + export const Navigation = "Navigation"; + export const Test = "Test"; + export const Binding = "Binding"; + export const BindingError = "BindingError"; + export const Error = "Error"; + export const Animation = "Animation"; + export const Transition = "Transition"; + export const All = VisualTreeEvents + "," + Layout + "," + Style + "," + ViewHierarchy + "," + NativeLifecycle + "," + Debug + "," + Navigation + "," + Test + "," + Binding + "," + Error + "," + Animation + "," + Transition; - export var separator = ","; + export const separator = ","; export function concat(): string { - var i; - var result: string; - for (i = 0; i < arguments.length; i++) { + let result: string; + for (let i = 0; i < arguments.length; i++) { if (!result) { result = arguments[i]; continue; @@ -155,7 +154,7 @@ class ConsoleWriter implements TraceWriter { return; } - var msgType; + let msgType; if (type === undefined) { msgType = messageType.log; } else { diff --git a/tns-core-modules/ui/action-bar/action-bar-common.ts b/tns-core-modules/ui/action-bar/action-bar-common.ts index 5701364d8..b43d2e47d 100644 --- a/tns-core-modules/ui/action-bar/action-bar-common.ts +++ b/tns-core-modules/ui/action-bar/action-bar-common.ts @@ -18,7 +18,7 @@ import { } from "../core/view"; export module knownCollections { - export var actionItems = "actionItems"; + export const actionItems = "actionItems"; } @CSSType("ActionBar") @@ -235,7 +235,7 @@ export class ActionItems implements ActionItemsDefinition { } // Add new items - for (var i = 0; i < items.length; i++) { + for (let i = 0; i < items.length; i++) { this.addItem(items[i]); } diff --git a/tns-core-modules/ui/animation/animation-common.ts b/tns-core-modules/ui/animation/animation-common.ts index 20d29c4fb..bf021e52e 100644 --- a/tns-core-modules/ui/animation/animation-common.ts +++ b/tns-core-modules/ui/animation/animation-common.ts @@ -16,11 +16,11 @@ export { Color, traceEnabled, traceWrite, traceCategories, traceType }; export { AnimationPromise } from "."; export module Properties { - export var opacity = "opacity"; - export var backgroundColor = "backgroundColor"; - export var translate = "translate"; - export var rotate = "rotate"; - export var scale = "scale"; + export const opacity = "opacity"; + export const backgroundColor = "backgroundColor"; + export const translate = "translate"; + export const rotate = "rotate"; + export const scale = "scale"; } export interface PropertyAnimation { @@ -96,7 +96,7 @@ export abstract class AnimationBase implements AnimationBaseDefinition { public play(): AnimationPromiseDefinition { // We have to actually create a "Promise" due to a bug in the v8 engine and decedent promises // We just cast it to a animationPromise so that all the rest of the code works fine - var animationFinishedPromise = new Promise((resolve, reject) => { + const animationFinishedPromise = new Promise((resolve, reject) => { this._resolve = resolve; this._reject = reject; }); @@ -109,19 +109,19 @@ export abstract class AnimationBase implements AnimationBaseDefinition { private fixupAnimationPromise(promise: AnimationPromiseDefinition): void { // Since we are using function() below because of arguments, TS won't automatically do a _this for those functions. - var _this = this; + const _this = this; promise.cancel = () => { _this.cancel(); }; - var _then = promise.then; + const _then = promise.then; promise.then = function () { - var r = _then.apply(promise, arguments); + const r = _then.apply(promise, arguments); _this.fixupAnimationPromise(r); return r; }; - var _catch = promise.catch; + const _catch = promise.catch; promise.catch = function () { - var r = _catch.apply(promise, arguments); + const r = _catch.apply(promise, arguments); _this.fixupAnimationPromise(r); return r; }; diff --git a/tns-core-modules/ui/builder/binding-builder.d.ts b/tns-core-modules/ui/builder/binding-builder.d.ts index 2eed5b7a4..d0e14be7c 100644 --- a/tns-core-modules/ui/builder/binding-builder.d.ts +++ b/tns-core-modules/ui/builder/binding-builder.d.ts @@ -5,17 +5,17 @@ //@private export module bindingConstants { - export var sourceProperty: string; - export var targetProperty: string; - export var expression: string; - export var twoWay: string; - export var source: string; - export var bindingValueKey: string; - export var parentValueKey: string; - export var parentsValueKey: string; - export var newPropertyValueKey: string; + export const sourceProperty: string; + export const targetProperty: string; + export const expression: string; + export const twoWay: string; + export const source: string; + export const bindingValueKey: string; + export const parentValueKey: string; + export const parentsValueKey: string; + export const newPropertyValueKey: string; } export function getBindingOptions(name: string, value: string): any; -export var parentsRegex: RegExp; +export const parentsRegex: RegExp; diff --git a/tns-core-modules/ui/builder/binding-builder.ts b/tns-core-modules/ui/builder/binding-builder.ts index 899b8b5fa..17d6e879f 100644 --- a/tns-core-modules/ui/builder/binding-builder.ts +++ b/tns-core-modules/ui/builder/binding-builder.ts @@ -1,54 +1,55 @@ // regex that contains all symbols applicable for expression used to AI detect an expression. -var expressionSymbolsRegex = /[\+\-\*\/%\?:<>=!\|&\(\)^~]/; +const expressionSymbolsRegex = /[\+\-\*\/%\?:<>=!\|&\(\)^~]/; export module bindingConstants { - export var sourceProperty = "sourceProperty"; - export var targetProperty = "targetProperty"; - export var expression = "expression"; - export var twoWay = "twoWay"; - export var source = "source"; - export var bindingValueKey = "$value"; - export var parentValueKey = "$parent"; - export var parentsValueKey = "$parents"; - export var newPropertyValueKey = "$newPropertyValue"; + export const sourceProperty = "sourceProperty"; + export const targetProperty = "targetProperty"; + export const expression = "expression"; + export const twoWay = "twoWay"; + export const source = "source"; + export const bindingValueKey = "$value"; + export const parentValueKey = "$parent"; + export const parentsValueKey = "$parents"; + export const newPropertyValueKey = "$newPropertyValue"; }; -var hasEqualSignRegex = /=+/; -var equalSignComparisionOperatorsRegex = /(==|===|>=|<=|!=|!==)/; +const hasEqualSignRegex = /=+/; +const equalSignComparisionOperatorsRegex = /(==|===|>=|<=|!=|!==)/; // this regex is used to search for all instaces of '$parents[]' within an expression -export var parentsRegex = /\$parents\s*\[\s*(['"]*)\w*\1\s*\]/g; +export const parentsRegex = /\$parents\s*\[\s*(['"]*)\w*\1\s*\]/g; function isNamedParam(value) { - var equalSignIndex = value.search(hasEqualSignRegex); + const equalSignIndex = value.search(hasEqualSignRegex); if (equalSignIndex > -1) { - var equalSignSurround = value.substr(equalSignIndex > 0 ? equalSignIndex - 1 : 0, 3); + const equalSignSurround = value.substr(equalSignIndex > 0 ? equalSignIndex - 1 : 0, 3); if (equalSignSurround.search(equalSignComparisionOperatorsRegex) === -1) { return true; } } + return false; } function areNamedParams(params: Array) { - var i; - for (i = 0; i < params.length; i++) { + for (let i = 0; i < params.length; i++) { if (isNamedParam(params[i])) { return true; } } + return false; } -var namedParamConstants = { +const namedParamConstants = { propName: "propName", propValue: "propValue" } function getPropertyNameValuePair(param, knownOptions, callback) { - var nameValuePair = {}; - var propertyName = param.substr(0, param.indexOf("=")).trim(); - var propertyValue = param.substr(param.indexOf("=") + 1).trim(); + let nameValuePair = {}; + let propertyName = param.substr(0, param.indexOf("=")).trim(); + const propertyValue = param.substr(param.indexOf("=") + 1).trim(); if (knownOptions) { if (!propertyName) { propertyName = knownOptions.defaultProperty; @@ -73,25 +74,26 @@ function getPropertyNameValuePair(param, knownOptions, callback) { } function parseNamedProperties(parameterList, knownOptions, callback) { - var result = {}; - var i; - for (i = 0; i < parameterList.length; i++) { - var nameValuePair = getPropertyNameValuePair(parameterList[i], knownOptions, callback); + const result = {}; + let nameValuePair; + for (let i = 0; i < parameterList.length; i++) { + nameValuePair = getPropertyNameValuePair(parameterList[i], knownOptions, callback); if (nameValuePair) { result[nameValuePair[namedParamConstants.propName]] = nameValuePair[namedParamConstants.propValue]; } } + return result; } function getParamsArray(value: string) { - var result = []; - var i; - var skipComma = 0; - var indexReached = 0; - var singleQuoteBlock, doubleQuoteBlock = false; + const result = []; + let skipComma = 0; + let indexReached = 0; + let singleQuoteBlock = false; + let doubleQuoteBlock = false; - for (i = 0; i < value.length; i++) { + for (let i = 0; i < value.length; i++) { if (value[i] === "\"") { doubleQuoteBlock = !doubleQuoteBlock; } @@ -121,26 +123,28 @@ function getParamsArray(value: string) { function isExpression(expression: string): boolean { if (expression.search(expressionSymbolsRegex) > -1) { - var parentsMatches = expression.match(parentsRegex); + const parentsMatches = expression.match(parentsRegex); if (parentsMatches) { - var restOfExpression = expression.substr(expression.indexOf(parentsMatches[0]) + parentsMatches[0].length); + const restOfExpression = expression.substr(expression.indexOf(parentsMatches[0]) + parentsMatches[0].length); // no more expression regognition symbols so it is safe for sourceProperty if (!(restOfExpression.search(expressionSymbolsRegex) > -1)) { return false; } } + return true; } + return false; } export function getBindingOptions(name: string, value: string): any { - var namedParams = []; - var params = getParamsArray(value); + let namedParams = []; + const params = getParamsArray(value); if (!areNamedParams(params)) { if (params.length === 1) { - var trimmedValue = params[0].trim(); - var sourceProp; + const trimmedValue = params[0].trim(); + let sourceProp; if (isExpression(trimmedValue)) { sourceProp = bindingConstants.bindingValueKey; namedParams.push(bindingConstants.expression + " = " + trimmedValue); @@ -155,7 +159,7 @@ export function getBindingOptions(name: string, value: string): any { else { namedParams.push(bindingConstants.sourceProperty + " = " + params[0].trim()); namedParams.push(bindingConstants.expression + " = " + params[1].trim()); - var twoWay = params[2] ? params[2].toLowerCase().trim() === "true" : true; + const twoWay = params[2] ? params[2].toLowerCase().trim() === "true" : true; namedParams.push(bindingConstants.twoWay + " = " + twoWay); } } @@ -163,8 +167,8 @@ export function getBindingOptions(name: string, value: string): any { namedParams = params; } - var bindingPropertyHandler = function (prop, value) { - var result = {}; + const bindingPropertyHandler = function (prop, value) { + const result = {}; result[namedParamConstants.propName] = prop; if (prop === bindingConstants.twoWay) { // create a real boolean value @@ -182,12 +186,12 @@ export function getBindingOptions(name: string, value: string): any { return result; }; - var bindingOptionsParameters = parseNamedProperties(namedParams, xmlBindingProperties, bindingPropertyHandler); - var bindOptions = { + const bindingOptionsParameters = parseNamedProperties(namedParams, xmlBindingProperties, bindingPropertyHandler); + const bindOptions = { targetProperty: name }; - for (var prop in bindingOptionsParameters) { + for (let prop in bindingOptionsParameters) { if (bindingOptionsParameters.hasOwnProperty(prop)) { bindOptions[prop] = bindingOptionsParameters[prop]; } @@ -200,10 +204,10 @@ export function getBindingOptions(name: string, value: string): any { return bindOptions; } -var xmlBindingProperties = { +const xmlBindingProperties = { sourceProperty: true, expression: true, twoWay: true, source: true, defaultProperty: bindingConstants.sourceProperty -}; \ No newline at end of file +}; diff --git a/tns-core-modules/ui/builder/builder.ts b/tns-core-modules/ui/builder/builder.ts index 4d4b3e5c1..d3dd8e099 100644 --- a/tns-core-modules/ui/builder/builder.ts +++ b/tns-core-modules/ui/builder/builder.ts @@ -2,6 +2,7 @@ import { LoadOptions } from "."; import { View, ViewBase, Template, KeyedTemplate } from "../core/view"; import { ViewEntry } from "../frame"; +import * as traceModule from "../../trace"; // Types. import { debug, ScopeError, SourceError, Source } from "../../utils/debug"; @@ -12,14 +13,13 @@ import { ComponentModule, setPropertyValue, getComponentModule } from "./compone import { platformNames, device } from "../../platform"; import { resolveFileName } from "../../file-system/file-name-resolver"; import { profile } from "../../profiling"; -import * as traceModule from "../../trace"; const ios = platformNames.ios.toLowerCase(); const android = platformNames.android.toLowerCase(); const defaultNameSpaceMatcher = /tns\.xsd$/i; -var trace: typeof traceModule; +let trace: typeof traceModule; function ensureTrace() { if (!trace) { trace = require("trace"); @@ -151,7 +151,7 @@ function loadInternal(fileName: string, context?: any, moduleNamePath?: string): const filePathRelativeToApp = (moduleNamePath && moduleNamePath.startsWith(appPath) ? "./" + moduleNamePath.substr(appPath.length + 1) : moduleNamePath) + ".xml"; if (global.moduleExists(filePathRelativeToApp)) { - var text = global.loadModule(filePathRelativeToApp); + const text = global.loadModule(filePathRelativeToApp); componentModule = parseInternal(text, context, fileName, moduleNamePath); } else if (fileName && File.exists(fileName)) { const file = File.fromPath(fileName); @@ -228,7 +228,7 @@ function loadCustomComponent(componentPath: string, componentName?: string, attr // webpack modules require paths to be relative to /app folder. let cssModulePath = fullComponentPathFilePathWithoutExt + ".css"; if (cssModulePath.startsWith("/")) { - var app = knownFolders.currentApp().path + "/"; + const app = knownFolders.currentApp().path + "/"; if (cssModulePath.startsWith(app)) { cssModulePath = "./" + cssModulePath.substr(app.length); } @@ -238,7 +238,7 @@ function loadCustomComponent(componentPath: string, componentName?: string, attr if (global.moduleExists(cssModulePath)) { (parentPage).addCssFile(cssModulePath); } else { - var cssFilePath = resolveFileName(fullComponentPathFilePathWithoutExt, "css"); + const cssFilePath = resolveFileName(fullComponentPathFilePathWithoutExt, "css"); // Add component CSS file if exists. if (cssFilePath) { if (parentPage && typeof (parentPage).addCssFile === "function") { @@ -270,11 +270,11 @@ function getExports(instance: ViewBase): any { } function parseInternal(value: string, context: any, uri?: string, moduleNamePath?: string): ComponentModule { - var start: xml2ui.XmlStringParser; - var ui: xml2ui.ComponentParser; + let start: xml2ui.XmlStringParser; + let ui: xml2ui.ComponentParser; - var errorFormat = (debug && uri) ? xml2ui.SourceErrorFormat(uri) : xml2ui.PositionErrorFormat; - var componentSourceTracker = (debug && uri) ? xml2ui.ComponentSourceTracker(uri) : () => { + const errorFormat = (debug && uri) ? xml2ui.SourceErrorFormat(uri) : xml2ui.PositionErrorFormat; + const componentSourceTracker = (debug && uri) ? xml2ui.ComponentSourceTracker(uri) : () => { // no-op }; @@ -320,7 +320,7 @@ namespace xml2ui { } public parse(value: string) { - var xmlParser = new xml.XmlParser((args: xml.ParserEvent) => { + const xmlParser = new xml.XmlParser((args: xml.ParserEvent) => { try { this.next(args); } catch (e) { @@ -346,7 +346,7 @@ namespace xml2ui { export function SourceErrorFormat(uri): ErrorFormatter { return (e: Error, p: xml.Position) => { - var source = p ? new Source(uri, p.line, p.column) : new Source(uri, -1, -1); + const source = p ? new Source(uri, p.line, p.column) : new Source(uri, -1, -1); e = new SourceError(e, source, "Building UI from XML."); return e; } @@ -359,7 +359,7 @@ namespace xml2ui { export function ComponentSourceTracker(uri): SourceTracker { return (component: any, p: xml.Position) => { if (!Source.get(component)) { - var source = p ? new Source(uri, p.line, p.column) : new Source(uri, -1, -1); + const source = p ? new Source(uri, p.line, p.column) : new Source(uri, -1, -1); Source.set(component, source); } } @@ -528,12 +528,12 @@ namespace xml2ui { } public buildTemplate(): Template { - var context = this._context; - var errorFormat = this._templateProperty.errorFormat; - var sourceTracker = this._templateProperty.sourceTracker; - var template: Template = profile("Template()", () => { - var start: xml2ui.XmlArgsReplay; - var ui: xml2ui.ComponentParser; + const context = this._context; + const errorFormat = this._templateProperty.errorFormat; + const sourceTracker = this._templateProperty.sourceTracker; + const template: Template = profile("Template()", () => { + let start: xml2ui.XmlArgsReplay; + let ui: xml2ui.ComponentParser; (start = new xml2ui.XmlArgsReplay(this._recordedXmlStream, errorFormat)) // No platform filter, it has been filtered already @@ -543,6 +543,7 @@ namespace xml2ui { return ui.rootComponentModule.component; }); + return template; } } @@ -633,14 +634,14 @@ namespace xml2ui { public parse(args: xml.ParserEvent): XmlStateConsumer { // Get the current parent. - var parent = this.parents[this.parents.length - 1]; - var complexProperty = this.complexProperties[this.complexProperties.length - 1]; + const parent = this.parents[this.parents.length - 1]; + const complexProperty = this.complexProperties[this.complexProperties.length - 1]; // Create component instance from every element declaration. if (args.eventType === xml.ParserEventType.StartElement) { if (ComponentParser.isComplexProperty(args.elementName)) { - var name = ComponentParser.getComplexPropertyName(args.elementName); + const name = ComponentParser.getComplexPropertyName(args.elementName); const complexProperty: ComponentParser.ComplexProperty = { parent: parent, @@ -677,7 +678,7 @@ namespace xml2ui { } else { - var componentModule = this.buildComponent(args); + const componentModule = this.buildComponent(args); if (componentModule) { this.sourceTracker(componentModule.component, args.position); @@ -734,10 +735,10 @@ namespace xml2ui { } public static getComplexPropertyName(fullName: string): string { - var name: string; + let name: string; if (isString(fullName)) { - var names = fullName.split("."); + const names = fullName.split("."); name = names[names.length - 1]; } @@ -754,7 +755,7 @@ namespace xml2ui { private static addToComplexProperty(parent: ComponentModule, complexProperty: ComponentParser.ComplexProperty, elementModule: ComponentModule) { // If property name is known collection we populate array with elements. - var parentComponent = parent.component; + const parentComponent = parent.component; if (ComponentParser.isKnownCollection(complexProperty.name, parent.exports)) { complexProperty.items.push(elementModule.component); } else if (parentComponent._addChildFromBuilder) { diff --git a/tns-core-modules/ui/builder/component-builder/component-builder.ts b/tns-core-modules/ui/builder/component-builder/component-builder.ts index fe20bfa18..add4aa427 100644 --- a/tns-core-modules/ui/builder/component-builder/component-builder.ts +++ b/tns-core-modules/ui/builder/component-builder/component-builder.ts @@ -28,10 +28,10 @@ const CSSFILE = "cssFile"; const IMPORT = "import"; const createComponentInstance = profile("createComponentInstance", (elementName: string, namespace: string): { instance: View, instanceModule: Object } => { - var instance: View; - var instanceModule: Object; + let instance: View; + let instanceModule: Object; // Get module id. - var moduleId = MODULES[elementName] || UI_PATH + + let moduleId = MODULES[elementName] || UI_PATH + (elementName.toLowerCase().indexOf("layout") !== -1 ? "layouts/" : "") + elementName.split(/(?=[A-Z])/).join("-").toLowerCase(); @@ -141,10 +141,10 @@ const applyComponentAttributes = profile("applyComponentAttributes", (instance: if (instance && instanceModule) { for (let attr in attributes) { - var attrValue = attributes[attr]; + const attrValue = attributes[attr]; if (attr.indexOf(":") !== -1) { - var platformName = attr.split(":")[0].trim(); + const platformName = attr.split(":")[0].trim(); if (platformName.toLowerCase() === platform.device.os.toLowerCase()) { attr = attr.split(":")[1].trim(); @@ -186,7 +186,7 @@ export function getComponentModule(elementName: string, namespace: string, attri applyComponentAttributes(instance, instanceModule, moduleExports, attributes); - var componentModule; + let componentModule; if (instance && instanceModule) { componentModule = { component: instance, exports: instanceModule }; } @@ -196,7 +196,7 @@ export function getComponentModule(elementName: string, namespace: string, attri export function setPropertyValue(instance: View, instanceModule: Object, exports: Object, propertyName: string, propertyValue: any) { // Note: instanceModule can be null if we are loading custom compnenet with no code-behind. if (isBinding(propertyValue) && instance.bind) { - var bindOptions = getBindingOptions(propertyName, getBindingExpressionFromAttribute(propertyValue)); + const bindOptions = getBindingOptions(propertyName, getBindingExpressionFromAttribute(propertyValue)); instance.bind({ sourceProperty: bindOptions[bindingConstants.sourceProperty], targetProperty: bindOptions[bindingConstants.targetProperty], @@ -206,7 +206,7 @@ export function setPropertyValue(instance: View, instanceModule: Object, exports } else if (isEventOrGesture(propertyName, instance)) { // Get the event handler from page module exports. - var handler = exports && exports[propertyValue]; + const handler = exports && exports[propertyValue]; // Check if the handler is function and add it to the instance for specified event name. if (typeof handler === "function") { @@ -226,10 +226,10 @@ function getBindingExpressionFromAttribute(value: string): string { } function isBinding(value: any): boolean { - var isBinding; + let isBinding; if (typeof value === "string") { - var str = value.trim(); + const str = value.trim(); isBinding = str.indexOf("{{") === 0 && str.lastIndexOf("}}") === str.length - 2; } diff --git a/tns-core-modules/ui/core/control-state-change/control-state-change.ios.ts b/tns-core-modules/ui/core/control-state-change/control-state-change.ios.ts index 87546d616..e903adebf 100644 --- a/tns-core-modules/ui/core/control-state-change/control-state-change.ios.ts +++ b/tns-core-modules/ui/core/control-state-change/control-state-change.ios.ts @@ -59,7 +59,7 @@ export class ControlStateChangeListener implements ControlStateChangeListenerDef } private _updateState() { - var state = "normal"; + let state = "normal"; if (this._control.highlighted) { state = "highlighted"; } diff --git a/tns-core-modules/ui/core/dependency-observable/dependency-observable.d.ts b/tns-core-modules/ui/core/dependency-observable/dependency-observable.d.ts index e611b834f..d31aaae77 100644 --- a/tns-core-modules/ui/core/dependency-observable/dependency-observable.d.ts +++ b/tns-core-modules/ui/core/dependency-observable/dependency-observable.d.ts @@ -251,19 +251,19 @@ export module PropertyMetadataSettings { /** * No options are specified. This is the default value. */ - export var None: number; + export const None: number; /** * A change in the Property associated with the metadata will invalidate the layout. */ - export var AffectsLayout; + export const AffectsLayout; /** * The Property associated with the metadata is inheritable and its value should be propagated down in the visual tree. */ - export var Inheritable: number; + export const Inheritable: number; /** * A change in the Property associated with the metadata will cause all CSS styles to be re-evaluated for for owning element. */ - export var AffectsStyle: number; + export const AffectsStyle: number; } /** @@ -273,21 +273,21 @@ export module ValueSource { /** * Default value, coming from the PropertyMetadata.defaultValue. */ - export var Default: number; + export const Default: number; /** * Inherited value, coming from the logical parent of the current DependencyObservable instance. */ - export var Inherited: number; + export const Inherited: number; /** * Css value, coming a css selector and rule that matches the current DependencyObservable instance. */ - export var Css: number; + export const Css: number; /** * Local value, set directly to the current DependencyObservable instance. */ - export var Local: number; + export const Local: number; /** * VisualState value, coming from a visual-state css selector. E.g. { button:pressed }. */ - export var VisualState: number; + export const VisualState: number; } diff --git a/tns-core-modules/ui/core/dependency-observable/dependency-observable.ts b/tns-core-modules/ui/core/dependency-observable/dependency-observable.ts index 6848faf35..9cbd2c15a 100644 --- a/tns-core-modules/ui/core/dependency-observable/dependency-observable.ts +++ b/tns-core-modules/ui/core/dependency-observable/dependency-observable.ts @@ -9,8 +9,7 @@ import { getClassInfo, isString } from "../../../utils/types"; import { unsetValue } from "../properties"; // use private variables in the scope of the module rather than static members of the class since a member is still accessible through JavaScript and may be changed. -var propertyFromKey = {}; -// var propertyIdCounter = 0; +const propertyFromKey = {}; function generatePropertyKey(name: string, ownerType: string, validate?: boolean) { if (validate) { @@ -30,9 +29,9 @@ function validateRegisterParameters(name: string, ownerType: string) { } function getPropertyByNameAndType(name: string, owner: any): Property { - var result; - var key; - var classInfo = getClassInfo(owner); + let result; + let key; + let classInfo = getClassInfo(owner); while (classInfo) { key = generatePropertyKey(name, classInfo.name); result = propertyFromKey[key]; @@ -45,18 +44,18 @@ function getPropertyByNameAndType(name: string, owner: any): Property { } export module PropertyMetadataSettings { - export var None = 0; - export var AffectsLayout = 1; - export var AffectsStyle = 1 << 1; - export var Inheritable = 1 << 2; + export const None = 0; + export const AffectsLayout = 1; + export const AffectsStyle = 1 << 1; + export const Inheritable = 1 << 2; } export module ValueSource { - export var Default = 0; - export var Inherited = 1; - export var Css = 2; - export var Local = 3; - export var VisualState = 4; + export const Default = 0; + export const Inherited = 1; + export const Css = 2; + export const Local = 3; + export const VisualState = 4; } export class PropertyMetadata implements PropertyMetadataDefinition { @@ -127,7 +126,7 @@ export class DependencyObservable extends Observable implements DependencyObserv throw new Error("* @deprecated use 'ui/core/view-base or ui/core/view' as base class."); } public set(name: string, value: any) { - var property = getPropertyByNameAndType(name, this); + const property = getPropertyByNameAndType(name, this); if (property) { this._setValueInternal(property, value, ValueSource.Local); } else { @@ -136,7 +135,7 @@ export class DependencyObservable extends Observable implements DependencyObserv } public get(name: string): any { - var property = getPropertyByNameAndType(name, this); + const property = getPropertyByNameAndType(name, this); if (property) { return this._getValue(property); } else { @@ -149,7 +148,7 @@ export class DependencyObservable extends Observable implements DependencyObserv } public _getValueSource(property: Property): number { - var entry: PropertyEntry = this._propertyEntries[property.id]; + const entry: PropertyEntry = this._propertyEntries[property.id]; if (entry) { return entry.valueSource; } @@ -158,7 +157,7 @@ export class DependencyObservable extends Observable implements DependencyObserv } public _getValue(property: Property): any { - var entry: PropertyEntry = this._propertyEntries[property.id]; + const entry: PropertyEntry = this._propertyEntries[property.id]; if (entry) { return entry.effectiveValue; } diff --git a/tns-core-modules/ui/core/properties/properties.ts b/tns-core-modules/ui/core/properties/properties.ts index 5f54f7b97..bf6c7ba0d 100644 --- a/tns-core-modules/ui/core/properties/properties.ts +++ b/tns-core-modules/ui/core/properties/properties.ts @@ -1100,7 +1100,7 @@ export const initNativeView = profile("\"properties\".initNativeView", function export function applyPendingNativeSetters(view: ViewBase): void { // TODO: Check what happens if a view was suspended and its value was reset, or set back to default! const suspendedUpdates = view._suspendedUpdates; - for (var propertyName in suspendedUpdates) { + for (let propertyName in suspendedUpdates) { const property = suspendedUpdates[propertyName]; const setNative = property.setNative; if (view[setNative]) { @@ -1305,7 +1305,7 @@ export function getSetProperties(view: ViewBase): [string, any][] { export function getComputedCssValues(view: ViewBase): [string, any][] { const result = []; const style = view.style; - for (var prop of cssPropertyNames) { + for (let prop of cssPropertyNames) { result.push([prop, style[prop]]); } diff --git a/tns-core-modules/ui/core/weak-event-listener/weak-event-listener.ts b/tns-core-modules/ui/core/weak-event-listener/weak-event-listener.ts index 864291f8a..a58b3b018 100644 --- a/tns-core-modules/ui/core/weak-event-listener/weak-event-listener.ts +++ b/tns-core-modules/ui/core/weak-event-listener/weak-event-listener.ts @@ -14,27 +14,28 @@ class TargetHandlerPair { } function getHandlerForEventName(eventName: string): (eventData: EventData) => void { - var handler = handlersForEventName.get(eventName); + let handler = handlersForEventName.get(eventName); if (!handler) { handler = function (eventData: EventData) { - var source = eventData.object; - var sourceEventMap = sourcesMap.get(source); + const source = eventData.object; + const sourceEventMap = sourcesMap.get(source); if (!sourceEventMap) { // There is no event map for this source - it is safe to detach the listener; source.removeEventListener(eventName, handlersForEventName.get(eventName)); return; } - var targetHandlerPairList = sourceEventMap.get(eventName); + const targetHandlerPairList = sourceEventMap.get(eventName); if (!targetHandlerPairList) { return; } - var deadPairsIndexes = []; - for (var i = 0; i < targetHandlerPairList.length; i++) { - var pair = targetHandlerPairList[i]; - - var target = pair.tagetRef.get(); + const deadPairsIndexes = []; + let pair; + let target; + for (let i = 0; i < targetHandlerPairList.length; i++) { + pair = targetHandlerPairList[i]; + target = pair.tagetRef.get(); if (target) { pair.handler.call(target, eventData); } @@ -49,7 +50,7 @@ function getHandlerForEventName(eventName: string): (eventData: EventData) => vo sourceEventMap.delete(eventName); } else { - for (var j = deadPairsIndexes.length - 1; j >= 0; j--) { + for (let j = deadPairsIndexes.length - 1; j >= 0; j--) { targetHandlerPairList.splice(deadPairsIndexes[j], 1); } } @@ -81,16 +82,16 @@ function validateArgs(source: Observable, eventName: string, handler: (eventData export function addWeakEventListener(source: Observable, eventName: string, handler: (eventData: EventData) => void, target: any) { validateArgs(source, eventName, handler, target); - var shouldAttach: boolean = false; + let shouldAttach: boolean = false; - var sourceEventMap = sourcesMap.get(source); + let sourceEventMap = sourcesMap.get(source); if (!sourceEventMap) { sourceEventMap = new Map>(); sourcesMap.set(source, sourceEventMap); shouldAttach = true; } - var pairList = sourceEventMap.get(eventName); + let pairList = sourceEventMap.get(eventName); if (!pairList) { pairList = new Array(); sourceEventMap.set(eventName, pairList); @@ -107,28 +108,30 @@ export function addWeakEventListener(source: Observable, eventName: string, hand export function removeWeakEventListener(source: Observable, eventName: string, handler: (eventData: EventData) => void, target: any) { validateArgs(source, eventName, handler, target); - var handlerForEventWithName = handlersForEventName.get(eventName); + const handlerForEventWithName = handlersForEventName.get(eventName); if (!handlerForEventWithName) { // We have never created handler for event with this name; return; } - var sourceEventMap = sourcesMap.get(source); + const sourceEventMap = sourcesMap.get(source); if (!sourceEventMap) { return; } - var targetHandlerPairList = sourceEventMap.get(eventName); + const targetHandlerPairList = sourceEventMap.get(eventName); if (!targetHandlerPairList) { return; } // Remove all pairs that match given target and handler or have a dead target - var targetHandlerPairsToRemove = []; - for (var i = 0; i < targetHandlerPairList.length; i++) { - var pair = targetHandlerPairList[i]; + const targetHandlerPairsToRemove = []; + let pair; + let registeredTarget; + for (let i = 0; i < targetHandlerPairList.length; i++) { + pair = targetHandlerPairList[i]; - var registeredTarget = pair.tagetRef.get(); + registeredTarget = pair.tagetRef.get(); if (!registeredTarget || (registeredTarget === target && handler === pair.handler)) { targetHandlerPairsToRemove.push(i); } @@ -140,7 +143,7 @@ export function removeWeakEventListener(source: Observable, eventName: string, h sourceEventMap.delete(eventName); } else { - for (var j = targetHandlerPairsToRemove.length - 1; j >= 0; j--) { + for (let j = targetHandlerPairsToRemove.length - 1; j >= 0; j--) { targetHandlerPairList.splice(targetHandlerPairsToRemove[j], 1); } } diff --git a/tns-core-modules/ui/dialogs/dialogs.d.ts b/tns-core-modules/ui/dialogs/dialogs.d.ts index 2b24c73cb..d200b4a43 100644 --- a/tns-core-modules/ui/dialogs/dialogs.d.ts +++ b/tns-core-modules/ui/dialogs/dialogs.d.ts @@ -10,32 +10,32 @@ export module inputType { /** * Plain text input type. */ - export var text: string; + export const text: string; /** * Password input type. */ - export var password: string; + export const password: string; /** * Email input type. */ - export var email: string; + export const email: string; /** * Number input type. */ - export var number: string; + export const number: string; /** * Decimal input type. */ - export var decimal: string; + export const decimal: string; /** * Phone input type. */ - export var phone: string; + export const phone: string; } /** @@ -45,22 +45,22 @@ export module capitalizationType { /** * No automatic capitalization. */ - export var none: string; + export const none: string; /** * Capitalizes every character. */ - export var all: string; + export const all: string; /** * Capitalize the first word of each sentence. */ - export var sentences: string; + export const sentences: string; /** * Capitalize the first letter of every word. */ - export var words: string; + export const words: string; } /** diff --git a/tns-core-modules/ui/enums/enums.d.ts b/tns-core-modules/ui/enums/enums.d.ts index d54ac27d9..fe7b6eee4 100644 --- a/tns-core-modules/ui/enums/enums.d.ts +++ b/tns-core-modules/ui/enums/enums.d.ts @@ -49,30 +49,30 @@ export module KeyboardType { * Android: [TYPE_CLASS_DATETIME](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_DATETIME) | [TYPE_DATETIME_VARIATION_NORMAL](http://developer.android.com/reference/android/text/InputType.html#TYPE_DATETIME_VARIATION_NORMAL) * iOS: [UIKeyboardTypeNumbersAndPunctuation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export var datetime: BaseKeyboardType + export const datetime: BaseKeyboardType /** * Android: [TYPE_CLASS_PHONE](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_PHONE) * iOS: [UIKeyboardTypePhonePad](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export var phone: BaseKeyboardType + export const phone: BaseKeyboardType /** * Android: [TYPE_CLASS_NUMBER](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_NUMBER) | [TYPE_NUMBER_VARIATION_NORMAL](http://developer.android.com/intl/es/reference/android/text/InputType.html#TYPE_NUMBER_VARIATION_NORMAL) | [TYPE_NUMBER_FLAG_SIGNED](http://developer.android.com/reference/android/text/InputType.html#TYPE_NUMBER_FLAG_SIGNED) | [TYPE_NUMBER_FLAG_DECIMAL](http://developer.android.com/reference/android/text/InputType.html#TYPE_NUMBER_FLAG_DECIMAL) * iOS: [UIKeyboardTypeNumbersAndPunctuation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export var number: BaseKeyboardType + export const number: BaseKeyboardType /** * Android: [TYPE_CLASS_TEXT](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_TEXT) | [TYPE_TEXT_VARIATION_URI](http://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_VARIATION_URI) * iOS: [UIKeyboardTypeURL](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export var url: BaseKeyboardType + export const url: BaseKeyboardType /** * Android: [TYPE_CLASS_TEXT](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_TEXT) | [TYPE_TEXT_VARIATION_EMAIL_ADDRESS](http://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_VARIATION_EMAIL_ADDRESS) * iOS: [UIKeyboardTypeEmailAddress](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType) */ - export var email: BaseKeyboardType + export const email: BaseKeyboardType } /** @@ -83,31 +83,31 @@ export module ReturnKeyType { * Android: [IME_ACTION_DONE](http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_DONE) * iOS: [UIReturnKeyDone](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType) */ - export var done: BaseReturnKeyType; + export const done: BaseReturnKeyType; /** * Android: [IME_ACTION_NEXT](http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_NEXT) * iOS: [UIReturnKeyNext](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType) */ - export var next: BaseReturnKeyType; + export const next: BaseReturnKeyType; /** * Android: [IME_ACTION_GO](http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_GO) * iOS: [UIReturnKeyGo](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType) */ - export var go: BaseReturnKeyType; + export const go: BaseReturnKeyType; /** * Android: [IME_ACTION_SEARCH](http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_SEARCH) * iOS: [UIReturnKeySearch](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType) */ - export var search: BaseReturnKeyType; + export const search: BaseReturnKeyType; /** * Android: [IME_ACTION_SEND](http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_SEND) * iOS: [UIReturnKeySend](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType) */ - export var send: string; + export const send: string; } /** @@ -117,17 +117,17 @@ export module TextAlignment { /** * Represents left text-align. */ - export var left: BaseTextAlignment; + export const left: BaseTextAlignment; /** * Represents center text-align. */ - export var center: BaseTextAlignment; + export const center: BaseTextAlignment; /** * Represents right text-align. */ - export var right: BaseTextAlignment; + export const right: BaseTextAlignment; } /** @@ -137,11 +137,11 @@ export module Orientation { /** * Layout should be horizontally oriented. */ - export var horizontal: BaseOrientation; + export const horizontal: BaseOrientation; /** * Layout should be vertically oriented. */ - export var vertical: BaseOrientation; + export const vertical: BaseOrientation; } /** @@ -151,15 +151,15 @@ export module DeviceOrientation { /** * Portrait orientation. */ - export var portrait: string; + export const portrait: string; /** * Landscape orientation. */ - export var landscape: string; + export const landscape: string; /** * Orientation cannot be determined. */ - export var unknown: string; + export const unknown: string; } /** @@ -169,22 +169,22 @@ export module HorizontalAlignment { /** * An element should be left aligned. */ - export var left: BaseHorizontalAlignment; + export const left: BaseHorizontalAlignment; /** * An element should be center aligned. */ - export var center: BaseHorizontalAlignment; + export const center: BaseHorizontalAlignment; /** * An element should be right aligned. */ - export var right: BaseHorizontalAlignment; + export const right: BaseHorizontalAlignment; /** * An element should be stretched to fill all the available size. */ - export var stretch: BaseHorizontalAlignment; + export const stretch: BaseHorizontalAlignment; } /** @@ -194,27 +194,27 @@ export module VerticalAlignment { /** * An element should be top aligned. */ - export var top: BaseVerticalAlignment; + export const top: BaseVerticalAlignment; /** * An element should be center aligned. */ - export var center: BaseVerticalAlignment; + export const center: BaseVerticalAlignment; /** * Same as center. An element should be aligned in the middle. */ - export var middle: BaseVerticalAlignment; + export const middle: BaseVerticalAlignment; /** * An element should be bottom aligned. */ - export var bottom: BaseVerticalAlignment; + export const bottom: BaseVerticalAlignment; /** * An element should be stretched to fill all the available size. */ - export var stretch: BaseVerticalAlignment; + export const stretch: BaseVerticalAlignment; } /** @@ -224,25 +224,25 @@ export module Stretch { /** * The image preserves its original size. */ - export var none: BaseStretch; + export const none: BaseStretch; /** * The image is resized to fill in the destination dimensions while it preserves its native aspect ratio. * If the aspect ratio of the destination rectangle differs from the image, the image is clipped to fill * in the destination. */ - export var aspectFill: BaseStretch; + export const aspectFill: BaseStretch; /** * The image is resized to fit the destination dimensions while it preserves * its native aspect ratio. */ - export var aspectFit: BaseStretch; + export const aspectFit: BaseStretch; /** * The image is resized to fill the destination dimensions. The aspect ratio is not preserved. */ - export var fill: BaseStretch; + export const fill: BaseStretch; } /** @@ -252,17 +252,17 @@ export module Visibility { /** * The view is visible. */ - export var visible: BaseVisibility; + export const visible: BaseVisibility; /** * The view is not visible and won't take place in the layout. */ - export var collapse: BaseVisibility; + export const collapse: BaseVisibility; /** * The view is not visible but will take place in the layout. */ - export var hidden: BaseVisibility; + export const hidden: BaseVisibility; } /** @@ -272,17 +272,17 @@ export module FontAttributes { /** * Denotes that text should be drawn in a normal style. */ - export var Normal: number; + export const Normal: number; /** * Denotes that text should be drawn in a bold weight. */ - export var Bold: number; + export const Bold: number; /** * Denotes that text should be drawn in a italic style. */ - export var Italic: number; + export const Italic: number; } /** @@ -292,12 +292,12 @@ export module DeviceType { /** * Indicates a smart-phone device. */ - export var Phone: string; + export const Phone: string; /** * Indicates a tablet device. */ - export var Tablet: string; + export const Tablet: string; } /** @@ -307,12 +307,12 @@ export module UpdateTextTrigger { /** * The text property will be udpaded when the widget loses focus. */ - export var focusLost: BaseUpdateTrigger; + export const focusLost: BaseUpdateTrigger; /** * The text property will be udpaded on every single character typed by the user. */ - export var textChanged: BaseUpdateTrigger; + export const textChanged: BaseUpdateTrigger; } /** @@ -322,12 +322,12 @@ export module Accuracy { /** * The default accuracy. About 300 meters. */ - export var any: number; + export const any: number; /** * High accuracy. About 3 meters. */ - export var high: number; + export const high: number; } /** @@ -337,22 +337,22 @@ export module Dock { /** * A child element that is positioned on the left side of the DockLayout. */ - export var left: BaseDock; + export const left: BaseDock; /** * A child element that is positioned on the top side of the DockLayout. */ - export var top: BaseDock; + export const top: BaseDock; /** * A child element that is positioned on the right side of the DockLayout. */ - export var right: BaseDock; + export const right: BaseDock; /** * A child element that is positioned on the bottom side of the DockLayout. */ - export var bottom: BaseDock; + export const bottom: BaseDock; } /** @@ -362,22 +362,22 @@ export module AutocapitalizationType { /** * Do not capitalize any text automatically. */ - export var none: BaseAutocapitalizationType; + export const none: BaseAutocapitalizationType; /** * Capitalize the first letter of each word automatically. */ - export var words: BaseAutocapitalizationType; + export const words: BaseAutocapitalizationType; /** * Capitalize the first letter of each sentence automatically. */ - export var sentences: BaseAutocapitalizationType; + export const sentences: BaseAutocapitalizationType; /** * Capitalize all characters automatically. */ - export var allCharacters: BaseAutocapitalizationType; + export const allCharacters: BaseAutocapitalizationType; } /** @@ -387,17 +387,17 @@ export module ImageFormat { /** * The W3C Portable Network Graphics (PNG) image format. */ - export var png: string; + export const png: string; /** * The Joint Photographic Experts Group (JPEG) image format. */ - export var jpeg: string; + export const jpeg: string; /** * The Joint Photographic Experts Group (JPEG) image format. */ - export var jpg: string; + export const jpg: string; } /** @@ -407,26 +407,26 @@ export module NavigationBarVisibility { /** * NavigationBar will be visible if there if frame backstack canGoBack is true or if the page Action Bar is not empty. */ - export var auto: string; + export const auto: string; /** * NavigationBar will be hidden. */ - export var never: string; + export const never: string; /** * NavigationBar will be visible. */ - export var always: string; + export const always: string; } /** * Specifies the visibility of the application bar icon */ export module AndroidActionBarIconVisibility { - export var auto: string; - export var never: string; - export var always: string; + export const auto: string; + export const never: string; + export const always: string; } /** @@ -436,17 +436,17 @@ export module AndroidActionItemPosition { /** * Always show this item as a button in an Action Bar. */ - export var actionBar: string; + export const actionBar: string; /** * Show this item as a button in an Action Bar if the system decides there is room for it. */ - export var actionBarIfRoom: string; + export const actionBarIfRoom: string; /** * Never show this item as a button in an Action Bar. */ - export var popup: string; + export const popup: string; } /** @@ -456,12 +456,12 @@ export module FontStyle { /** * Normal font style. */ - export var normal: BaseFontStyle; + export const normal: BaseFontStyle; /** * Italic font style. */ - export var italic: BaseFontStyle; + export const italic: BaseFontStyle; } /** @@ -471,17 +471,17 @@ export module TextDecoration { /** * No decoration. */ - export var none: BaseTextDecoration; + export const none: BaseTextDecoration; /** * Text decoration underline. */ - export var underline: BaseTextDecoration; + export const underline: BaseTextDecoration; /** * Text decoration line-through. */ - export var lineThrough: BaseTextDecoration; + export const lineThrough: BaseTextDecoration; } /** @@ -491,22 +491,22 @@ export module TextTransform { /** * No transform. */ - export var none: BaseTextTransform; + export const none: BaseTextTransform; /** * Text transform capitalize. */ - export var capitalize: BaseTextTransform; + export const capitalize: BaseTextTransform; /** * Text transform uppercase. */ - export var uppercase: BaseTextTransform; + export const uppercase: BaseTextTransform; /** * Text transform lowercase. */ - export var lowercase: BaseTextTransform; + export const lowercase: BaseTextTransform; } /** @@ -516,12 +516,12 @@ export module WhiteSpace { /** * Normal wrap. */ - export var normal: BaseWhiteSpace; + export const normal: BaseWhiteSpace; /** * No wrap. */ - export var nowrap: BaseWhiteSpace; + export const nowrap: BaseWhiteSpace; } /** @@ -531,57 +531,57 @@ export module FontWeight { /** * Thin font weight. CSS font-weight 100. */ - export var thin: BaseFontWeight; + export const thin: BaseFontWeight; /** * Extra-light / Ultra-light font weight. CSS font-weight 200. */ - export var extraLight: BaseFontWeight; + export const extraLight: BaseFontWeight; /** * Light font weight. CSS font-weight 300. */ - export var light: BaseFontWeight; + export const light: BaseFontWeight; /** * Normal font weight. CSS font-weight 400. */ - export var normal: BaseFontWeight; + export const normal: BaseFontWeight; /** * Medium font weight. CSS font-weight 500. */ - export var medium: BaseFontWeight; + export const medium: BaseFontWeight; /** * Semi-bold / Demi-bold font weight. CSS font-weight 600. */ - export var semiBold: BaseFontWeight; + export const semiBold: BaseFontWeight; /** * Bold font weight. CSS font-weight 700. */ - export var bold: BaseFontWeight; + export const bold: BaseFontWeight; /** * Extra-bold / Ultra-bold font weight. CSS font-weight 800. */ - export var extraBold: BaseFontWeight; + export const extraBold: BaseFontWeight; /** * Black font weight. CSS font-weight 900. */ - export var black: BaseFontWeight; + export const black: BaseFontWeight; } /** * Specifies background repeat. */ export module BackgroundRepeat { - export var repeat: BaseBackgroundRepeat; - export var repeatX: BaseBackgroundRepeat; - export var repeatY: BaseBackgroundRepeat; - export var noRepeat: BaseBackgroundRepeat; + export const repeat: BaseBackgroundRepeat; + export const repeatX: BaseBackgroundRepeat; + export const repeatY: BaseBackgroundRepeat; + export const noRepeat: BaseBackgroundRepeat; } /** @@ -591,12 +591,12 @@ export module IOSActionItemPosition { /** * Show this item at the left of the navigation bar. */ - export var left: string; + export const left: string; /** * Show this item at the right of the action bar. */ - export var right: string; + export const right: string; } /** @@ -607,32 +607,32 @@ export module AnimationCurve { /** * Default value. Specifies a transition effect with a slow start, then fast, then end slowly (equivalent to cubic-bezier(0.25,0.1,0.25,1)) */ - export var ease: string; + export const ease: string; /** * An ease-in curve causes the animation to begin slowly, and then speed up as it progresses. */ - export var easeIn: string; + export const easeIn: string; /** * An ease-out curve causes the animation to begin quickly, and then slow down as it completes. */ - export var easeOut: string; + export const easeOut: string; /** * An ease-in ease-out curve causes the animation to begin slowly, accelerate through the middle of its duration, and then slow again before completing. */ - export var easeInOut: string; + export const easeInOut: string; /** * A linear animation curve causes an animation to occur evenly over its duration. */ - export var linear: string; + export const linear: string; /** * A spring animation curve causes an animation to produce a spring (bounce) effect. */ - export var spring: string; + export const spring: string; /** * A custom cubic bezier function defined by its two control points. Possible values are numeric values from 0 to 1 @@ -647,10 +647,10 @@ export module StatusBarStyle { /** * The light style of the status bar - light background with dark letters. */ - export var light: string; + export const light: string; /** * The dark style of the status bar - dark background with light letters. */ - export var dark: string; + export const dark: string; } diff --git a/tns-core-modules/ui/enums/enums.ts b/tns-core-modules/ui/enums/enums.ts index 7b7779f4e..624000da1 100644 --- a/tns-core-modules/ui/enums/enums.ts +++ b/tns-core-modules/ui/enums/enums.ts @@ -1,185 +1,188 @@ +// imported for definition purposes only +import * as animationModule from "../../ui/animation"; + export module KeyboardType { - export var datetime = "datetime"; - export var phone = "phone"; - export var number = "number"; - export var url = "url"; - export var email = "email"; + export const datetime = "datetime"; + export const phone = "phone"; + export const number = "number"; + export const url = "url"; + export const email = "email"; } export module ReturnKeyType { - export var done = "done"; - export var next = "next"; - export var go = "go"; - export var search = "search"; - export var send = "send"; + export const done = "done"; + export const next = "next"; + export const go = "go"; + export const search = "search"; + export const send = "send"; } export module TextAlignment { - export var left = "left"; - export var center = "center"; - export var right = "right"; + export const left = "left"; + export const center = "center"; + export const right = "right"; } export module TextDecoration { - export var none = "none"; - export var underline = "underline"; - export var lineThrough = "line-through"; + export const none = "none"; + export const underline = "underline"; + export const lineThrough = "line-through"; } export module TextTransform { - export var none = "none"; - export var capitalize = "capitalize"; - export var uppercase = "uppercase"; - export var lowercase = "lowercase"; + export const none = "none"; + export const capitalize = "capitalize"; + export const uppercase = "uppercase"; + export const lowercase = "lowercase"; } export module WhiteSpace { - export var normal = "normal"; - export var nowrap = "nowrap"; + export const normal = "normal"; + export const nowrap = "nowrap"; } export module Orientation { - export var horizontal = "horizontal"; - export var vertical = "vertical"; + export const horizontal = "horizontal"; + export const vertical = "vertical"; } export module DeviceOrientation { - export var portrait = "portrait"; - export var landscape = "landscape"; - export var unknown = "unknown"; + export const portrait = "portrait"; + export const landscape = "landscape"; + export const unknown = "unknown"; } export module HorizontalAlignment { - export var left = "left"; - export var center = "center"; - export var right = "right"; - export var stretch = "stretch"; + export const left = "left"; + export const center = "center"; + export const right = "right"; + export const stretch = "stretch"; } export module VerticalAlignment { - export var top = "top"; - export var middle = "middle"; - export var bottom = "bottom"; - export var stretch = "stretch"; + export const top = "top"; + export const middle = "middle"; + export const bottom = "bottom"; + export const stretch = "stretch"; } export module Stretch { - export var none: string = "none"; - export var aspectFill: string = "aspectFill"; - export var aspectFit: string = "aspectFit"; - export var fill: string = "fill"; + export const none: string = "none"; + export const aspectFill: string = "aspectFill"; + export const aspectFit: string = "aspectFit"; + export const fill: string = "fill"; } export module Visibility { - export var visible: string = "visible"; - export var collapse: string = "collapse"; - export var collapsed: string = "collapsed"; + export const visible: string = "visible"; + export const collapse: string = "collapse"; + export const collapsed: string = "collapsed"; } export module FontAttributes { - export var Normal = 0; - export var Bold = 1; - export var Italic = 1 << 1; + export const Normal = 0; + export const Bold = 1; + export const Italic = 1 << 1; } export module DeviceType { - export var Phone: string = "Phone"; - export var Tablet: string = "Tablet"; + export const Phone: string = "Phone"; + export const Tablet: string = "Tablet"; } export module UpdateTextTrigger { - export var focusLost: string = "focusLost"; - export var textChanged: string = "textChanged"; + export const focusLost: string = "focusLost"; + export const textChanged: string = "textChanged"; } export module Accuracy { - export var any: number = 300; - export var high: number = 3; + export const any: number = 300; + export const high: number = 3; } export module Dock { - export var left: string = "left"; - export var top: string = "top"; - export var right: string = "right"; - export var bottom: string = "bottom"; + export const left: string = "left"; + export const top: string = "top"; + export const right: string = "right"; + export const bottom: string = "bottom"; } export module AutocapitalizationType { - export var none: string = "none"; - export var words: string = "words"; - export var sentences: string = "sentences"; - export var allCharacters: string = "allcharacters"; + export const none: string = "none"; + export const words: string = "words"; + export const sentences: string = "sentences"; + export const allCharacters: string = "allcharacters"; } export module NavigationBarVisibility { - export var auto: string = "auto"; - export var never: string = "never"; - export var always: string = "always"; + export const auto: string = "auto"; + export const never: string = "never"; + export const always: string = "always"; } export module AndroidActionBarIconVisibility { - export var auto: string = "auto"; - export var never: string = "never"; - export var always: string = "always"; + export const auto: string = "auto"; + export const never: string = "never"; + export const always: string = "always"; } export module AndroidActionItemPosition { - export var actionBar: string = "actionBar"; - export var actionBarIfRoom: string = "actionBarIfRoom"; - export var popup: string = "popup"; + export const actionBar: string = "actionBar"; + export const actionBarIfRoom: string = "actionBarIfRoom"; + export const popup: string = "popup"; } export module IOSActionItemPosition { - export var left: string = "left"; - export var right: string = "right"; + export const left: string = "left"; + export const right: string = "right"; } export module ImageFormat { - export var png: string = "png"; - export var jpeg: string = "jpeg"; - export var jpg: string = "jpg"; + export const png: string = "png"; + export const jpeg: string = "jpeg"; + export const jpg: string = "jpg"; } export module FontStyle { - export var normal: string = "normal"; - export var italic: string = "italic"; + export const normal: string = "normal"; + export const italic: string = "italic"; } export module FontWeight { - export var thin: string = "100"; - export var extraLight: string = "200"; - export var light: string = "300"; - export var normal: string = "normal"; // 400 - export var medium: string = "500"; - export var semiBold: string = "600"; - export var bold: string = "bold"; // 700 - export var extraBold: string = "800"; - export var black: string = "900"; + export const thin: string = "100"; + export const extraLight: string = "200"; + export const light: string = "300"; + export const normal: string = "normal"; // 400 + export const medium: string = "500"; + export const semiBold: string = "600"; + export const bold: string = "bold"; // 700 + export const extraBold: string = "800"; + export const black: string = "900"; } export module BackgroundRepeat { - export var repeat: string = "repeat"; - export var repeatX: string = "repeat-x"; - export var repeatY: string = "repeat-y"; - export var noRepeat: string = "no-repeat"; + export const repeat: string = "repeat"; + export const repeatX: string = "repeat-x"; + export const repeatY: string = "repeat-y"; + export const noRepeat: string = "no-repeat"; } -var animationModule; +let animation: typeof animationModule; export module AnimationCurve { - export var ease = "ease"; - export var easeIn = "easeIn"; - export var easeOut = "easeOut"; - export var easeInOut = "easeInOut"; - export var linear = "linear"; - export var spring = "spring"; + export const ease = "ease"; + export const easeIn = "easeIn"; + export const easeOut = "easeOut"; + export const easeInOut = "easeInOut"; + export const linear = "linear"; + export const spring = "spring"; export function cubicBezier(x1: number, y1: number, x2: number, y2: number): Object { - animationModule = animationModule || require("ui/animation"); - return new animationModule.CubicBezierAnimationCurve(x1, y1 , x2, y2); + animation = animation || require("ui/animation"); + return new animation.CubicBezierAnimationCurve(x1, y1 , x2, y2); } } export module StatusBarStyle { - export var light = "light"; - export var dark = "dark"; -} \ No newline at end of file + export const light = "light"; + export const dark = "dark"; +} diff --git a/tns-core-modules/ui/frame/frame.d.ts b/tns-core-modules/ui/frame/frame.d.ts index 9718f39ed..ec3793fee 100644 --- a/tns-core-modules/ui/frame/frame.d.ts +++ b/tns-core-modules/ui/frame/frame.d.ts @@ -37,7 +37,7 @@ export class Frame extends View { * This method will require the module and will check for a Page property in the exports of the module. * @param pageModuleName The name of the module to require starting from the application root. * For example if you want to navigate to page called "myPage.js" in a folder called "subFolder" and your root folder is "app" you can call navigate method like this: - * var frames = require("ui/frame"); + * const frames = require("ui/frame"); * frames.topmost().navigate("app/subFolder/myPage"); */ navigate(pageModuleName: string); diff --git a/tns-core-modules/ui/gestures/gestures.d.ts b/tns-core-modules/ui/gestures/gestures.d.ts index 6be6706e8..43891978b 100644 --- a/tns-core-modules/ui/gestures/gestures.d.ts +++ b/tns-core-modules/ui/gestures/gestures.d.ts @@ -94,22 +94,22 @@ export module TouchAction { /** * Down action. */ - export var down: string; + export const down: string; /** * Up action. */ - export var up: string; + export const up: string; /** * Move action. */ - export var move: string; + export const move: string; /** * Cancel action. */ - export var cancel: string; + export const cancel: string; } /** diff --git a/tns-core-modules/ui/image-cache/image-cache-common.ts b/tns-core-modules/ui/image-cache/image-cache-common.ts index 3dbd50809..967e3d3ad 100644 --- a/tns-core-modules/ui/image-cache/image-cache-common.ts +++ b/tns-core-modules/ui/image-cache/image-cache-common.ts @@ -28,7 +28,7 @@ export class Cache extends observable.Observable implements definition.Cache { // schedule all pending downloads this._enabled = true; - var request: DownloadRequest; + let request: DownloadRequest; while (this._queue.length > 0 && this._currentDownloads < this.maxRequests) { request = this._queue.pop(); @@ -56,13 +56,13 @@ export class Cache extends observable.Observable implements definition.Cache { private _addRequest(request: DownloadRequest, onTop: boolean): void { if (request.key in this._pendingDownloads) { - var existingRequest = this._pendingDownloads[request.key]; + const existingRequest = this._pendingDownloads[request.key]; this._mergeRequests(existingRequest, request); } else { // TODO: Potential performance bottleneck - traversing the whole queue on each download request. - var queueRequest: DownloadRequest; - for (var i = 0; i < this._queue.length; i++) { + let queueRequest: DownloadRequest; + for (let i = 0; i < this._queue.length; i++) { if (this._queue[i].key === request.key) { queueRequest = this._queue[i]; break; @@ -83,8 +83,8 @@ export class Cache extends observable.Observable implements definition.Cache { private _mergeRequests(existingRequest: DownloadRequest, newRequest: DownloadRequest) { if (existingRequest.completed) { if (newRequest.completed) { - var existingCompleted = existingRequest.completed; - var stackCompleted = function (result: imageSource.ImageSource, key: string) { + const existingCompleted = existingRequest.completed; + const stackCompleted = function (result: imageSource.ImageSource, key: string) { existingCompleted(result, key); newRequest.completed(result, key); } @@ -97,8 +97,8 @@ export class Cache extends observable.Observable implements definition.Cache { } if (existingRequest.error) { if (newRequest.error) { - var existingError = existingRequest.error; - var stackError = function (key: string) { + const existingError = existingRequest.error; + const stackError = function (key: string) { existingError(key); newRequest.error(key); } @@ -139,7 +139,7 @@ export class Cache extends observable.Observable implements definition.Cache { /* tslint:enable:no-unused-variable */ public _onDownloadCompleted(key: string, image: any) { - var request = this._pendingDownloads[key]; + const request = this._pendingDownloads[key]; this.set(request.key, image); this._currentDownloads--; @@ -163,7 +163,7 @@ export class Cache extends observable.Observable implements definition.Cache { } public _onDownloadError(key: string, err: Error) { - var request = this._pendingDownloads[key]; + const request = this._pendingDownloads[key]; this._currentDownloads--; if (request.error) { @@ -215,7 +215,7 @@ export class Cache extends observable.Observable implements definition.Cache { return; } - var request = this._queue.pop(); + const request = this._queue.pop(); this._download(request); } } diff --git a/tns-core-modules/ui/image-cache/image-cache.android.ts b/tns-core-modules/ui/image-cache/image-cache.android.ts index 96118aeed..acd8c0ee9 100644 --- a/tns-core-modules/ui/image-cache/image-cache.android.ts +++ b/tns-core-modules/ui/image-cache/image-cache.android.ts @@ -1,7 +1,7 @@ import * as common from "./image-cache-common"; import * as trace from "../../trace"; -var LruBitmapCacheClass; +let LruBitmapCacheClass; function ensureLruBitmapCacheClass() { if (LruBitmapCacheClass) { return; @@ -16,14 +16,10 @@ function ensureLruBitmapCacheClass() { public sizeOf(key: string, bitmap: android.graphics.Bitmap): number { // The cache size will be measured in kilobytes rather than // number of items. - var result = Math.round(bitmap.getByteCount() / 1024); - //console.log("sizeOf key: " + result); + const result = Math.round(bitmap.getByteCount() / 1024); + return result; } - - //protected entryRemoved(evicted: boolean, key: string, oldValue: android.graphics.Bitmap, newValue: android.graphics.Bitmap): void { - // console.log("entryRemoved("+evicted+", "+key+", "+oldValue+", "+newValue+")"); - //} }; LruBitmapCacheClass = LruBitmapCache; @@ -37,14 +33,14 @@ export class Cache extends common.Cache { super(); ensureLruBitmapCacheClass(); - var maxMemory = java.lang.Runtime.getRuntime().maxMemory() / 1024; - var cacheSize = maxMemory / 8; + const maxMemory = java.lang.Runtime.getRuntime().maxMemory() / 1024; + const cacheSize = maxMemory / 8; this._cache = new LruBitmapCacheClass(cacheSize); - var that = new WeakRef(this); + const that = new WeakRef(this); this._callback = new org.nativescript.widgets.Async.CompleteCallback({ onComplete: function (result: any, context: any) { - var instance = that.get(); + const instance = that.get(); if (instance) { if (result) { instance._onDownloadCompleted(context, result); @@ -54,7 +50,7 @@ export class Cache extends common.Cache { } }, onError: function (err: string, context: any) { - var instance = that.get(); + const instance = that.get(); if (instance) { instance._onDownloadError(context, new Error(err)); } @@ -67,7 +63,7 @@ export class Cache extends common.Cache { } public get(key: string): any { - var result = this._cache.get(key); + const result = this._cache.get(key); return result; } diff --git a/tns-core-modules/ui/image-cache/image-cache.ios.ts b/tns-core-modules/ui/image-cache/image-cache.ios.ts index c4f298a4c..f82391381 100644 --- a/tns-core-modules/ui/image-cache/image-cache.ios.ts +++ b/tns-core-modules/ui/image-cache/image-cache.ios.ts @@ -5,7 +5,7 @@ import * as common from "./image-cache-common"; import * as trace from "../../trace"; import * as utils from "../../utils/utils"; -var httpRequest: typeof httpRequestModule; +let httpRequest: typeof httpRequestModule; function ensureHttpRequest() { if (!httpRequest) { httpRequest = require("http/http-request"); @@ -53,6 +53,7 @@ class MemmoryWarningHandler extends NSObject { export class Cache extends common.Cache { private _cache: NSCache; + //@ts-ignore private _memoryWarningHandler: MemmoryWarningHandler; @@ -70,7 +71,7 @@ export class Cache extends common.Cache { httpRequest.request({ url: request.url, method: "GET" }) .then((response) => { try { - var image = UIImage.alloc().initWithData(response.content.raw); + const image = UIImage.alloc().initWithData(response.content.raw); this._onDownloadCompleted(request.key, image); } catch (err) { this._onDownloadError(request.key, err); diff --git a/tns-core-modules/ui/layouts/grid-layout/grid-layout-common.ts b/tns-core-modules/ui/layouts/grid-layout/grid-layout-common.ts index 0f2bef6ac..e9f2f5009 100644 --- a/tns-core-modules/ui/layouts/grid-layout/grid-layout-common.ts +++ b/tns-core-modules/ui/layouts/grid-layout/grid-layout-common.ts @@ -195,7 +195,7 @@ export class GridLayoutBase extends LayoutBase implements GridLayoutDefinition { throw new Error("Value is null."); } - var index = this._rows.indexOf(itemSpec); + const index = this._rows.indexOf(itemSpec); if (itemSpec.owner !== this || index < 0) { throw new Error("Row is not child of this GridLayout"); } @@ -211,7 +211,7 @@ export class GridLayoutBase extends LayoutBase implements GridLayoutDefinition { throw new Error("Value is null."); } - var index = this._cols.indexOf(itemSpec); + const index = this._cols.indexOf(itemSpec); if (itemSpec.owner !== this || index < 0) { throw new Error("Column is not child of this GridLayout"); } @@ -223,7 +223,7 @@ export class GridLayoutBase extends LayoutBase implements GridLayoutDefinition { } public removeColumns() { - for (var i = this._cols.length - 1; i >= 0; i--) { + for (let i = this._cols.length - 1; i >= 0; i--) { const colSpec = this._cols[i]; this._onColumnRemoved(colSpec, i); colSpec.index = -1; @@ -233,7 +233,7 @@ export class GridLayoutBase extends LayoutBase implements GridLayoutDefinition { } public removeRows() { - for (var i = this._rows.length - 1; i >= 0; i--) { + for (let i = this._rows.length - 1; i >= 0; i--) { const rowSpec = this._rows[i]; this._onRowRemoved(rowSpec, i); rowSpec.index = -1; diff --git a/tns-core-modules/ui/layouts/layout-base-common.ts b/tns-core-modules/ui/layouts/layout-base-common.ts index 104338337..6b7d27f89 100644 --- a/tns-core-modules/ui/layouts/layout-base-common.ts +++ b/tns-core-modules/ui/layouts/layout-base-common.ts @@ -59,7 +59,7 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi this._removeView(child); // TODO: consider caching the index on the child. - var index = this._subViews.indexOf(child); + const index = this._subViews.indexOf(child); this._subViews.splice(index, 1); this._unregisterLayoutChild(child); } @@ -129,7 +129,7 @@ export class LayoutBaseCommon extends CustomLayoutView implements LayoutBaseDefi } public eachLayoutChild(callback: (child: View, isLast: boolean) => void): void { - var lastChild: View = null; + let lastChild: View = null; this.eachChildView((cv) => { cv._eachLayoutView((lv) => { diff --git a/tns-core-modules/ui/layouts/wrap-layout/wrap-layout.ios.ts b/tns-core-modules/ui/layouts/wrap-layout/wrap-layout.ios.ts index 2d1d3a3d0..1d95a78d0 100644 --- a/tns-core-modules/ui/layouts/wrap-layout/wrap-layout.ios.ts +++ b/tns-core-modules/ui/layouts/wrap-layout/wrap-layout.ios.ts @@ -42,10 +42,10 @@ export class WrapLayout extends WrapLayoutBase { let remainingHeight = availableHeight; this._lengths.length = 0; - var rowOrColumn = 0; - var maxLength = 0; + let rowOrColumn = 0; + let maxLength = 0; - var isVertical = this.orientation === "vertical"; + const isVertical = this.orientation === "vertical"; let useItemWidth: boolean = this.effectiveItemWidth > 0; let useItemHeight: boolean = this.effectiveItemHeight > 0; diff --git a/tns-core-modules/ui/list-picker/list-picker-common.ts b/tns-core-modules/ui/list-picker/list-picker-common.ts index 75eb8aab8..d6e44374d 100644 --- a/tns-core-modules/ui/list-picker/list-picker-common.ts +++ b/tns-core-modules/ui/list-picker/list-picker-common.ts @@ -29,7 +29,7 @@ export class ListPickerBase extends View implements ListPickerDefinition { } public updateSelectedValue(index) { - var newVal = null; + let newVal = null; if (index >= 0) { const item = this.items[index]; diff --git a/tns-core-modules/ui/list-view/list-view.d.ts b/tns-core-modules/ui/list-view/list-view.d.ts index b64181693..4cc3ba1ab 100644 --- a/tns-core-modules/ui/list-view/list-view.d.ts +++ b/tns-core-modules/ui/list-view/list-view.d.ts @@ -12,7 +12,7 @@ export module knownTemplates { /** * The ListView item template. */ - export var itemTemplate: string; + export const itemTemplate: string; } /** diff --git a/tns-core-modules/ui/list-view/list-view.ios.ts b/tns-core-modules/ui/list-view/list-view.ios.ts index a68067c5f..8fb180625 100644 --- a/tns-core-modules/ui/list-view/list-view.ios.ts +++ b/tns-core-modules/ui/list-view/list-view.ios.ts @@ -365,7 +365,7 @@ export class ListView extends ListViewBase { public measure(widthMeasureSpec: number, heightMeasureSpec: number): void { this.widthMeasureSpec = widthMeasureSpec; - var changed = this._setCurrentMeasureSpecs(widthMeasureSpec, heightMeasureSpec); + const changed = this._setCurrentMeasureSpecs(widthMeasureSpec, heightMeasureSpec); super.measure(widthMeasureSpec, heightMeasureSpec); if (changed) { this.ios.reloadData(); diff --git a/tns-core-modules/ui/page/page.d.ts b/tns-core-modules/ui/page/page.d.ts index e8f973e59..942d1d5dc 100644 --- a/tns-core-modules/ui/page/page.d.ts +++ b/tns-core-modules/ui/page/page.d.ts @@ -33,7 +33,7 @@ export interface NavigatedData extends EventData { } export module knownCollections { - export var actionItems: string; + export const actionItems: string; } /** diff --git a/tns-core-modules/ui/repeater/repeater.ts b/tns-core-modules/ui/repeater/repeater.ts index ee1470b01..4c6553ffe 100644 --- a/tns-core-modules/ui/repeater/repeater.ts +++ b/tns-core-modules/ui/repeater/repeater.ts @@ -85,13 +85,7 @@ export class Repeater extends CustomLayoutView implements RepeaterDefinition { } get _childrenCount(): number { - var count = 0; - - if (this.itemsLayout) { - count++; - } - - return count; + return this.itemsLayout ? 1 : 0; } public eachChildView(callback: (child: View) => boolean) { diff --git a/tns-core-modules/ui/segmented-bar/segmented-bar-common.ts b/tns-core-modules/ui/segmented-bar/segmented-bar-common.ts index 7180dce45..780fb32fd 100644 --- a/tns-core-modules/ui/segmented-bar/segmented-bar-common.ts +++ b/tns-core-modules/ui/segmented-bar/segmented-bar-common.ts @@ -7,7 +7,7 @@ import { export * from "../core/view"; export module knownCollections { - export var items = "items"; + export const items = "items"; } @CSSType("SegmentedBarItem") diff --git a/tns-core-modules/ui/styling/css-selector/css-selector.ts b/tns-core-modules/ui/styling/css-selector/css-selector.ts index 875425508..c97daa760 100644 --- a/tns-core-modules/ui/styling/css-selector/css-selector.ts +++ b/tns-core-modules/ui/styling/css-selector/css-selector.ts @@ -38,11 +38,11 @@ namespace Match { /** * Depends on attributes or pseudoclasses state; */ - export var Dynamic = true; + export const Dynamic = true; /** * Depends only on the tree structure. */ - export var Static = false; + export const Static = false; } function getNodeDirectSibling(node): null | Node { @@ -436,14 +436,17 @@ function createSelectorFromAst(ast: parser.Selector): SimpleSelector | SimpleSel return createSimpleSelectorSequenceFromAst(ast[0][0]); } else { let simpleSelectorSequences = []; - for (var i = 0; i < ast.length; i ++) { - const simpleSelectorSequence = createSimpleSelectorSequenceFromAst(ast[i][0]); - const combinator = ast[i][1]; + let simpleSelectorSequence: SimpleSelectorSequence | SimpleSelector; + let combinator: parser.Combinator; + for (let i = 0; i < ast.length; i ++) { + simpleSelectorSequence = createSimpleSelectorSequenceFromAst(ast[i][0]); + combinator = ast[i][1]; if (combinator) { simpleSelectorSequence.combinator = combinator; } simpleSelectorSequences.push(simpleSelectorSequence); } + return new Selector(simpleSelectorSequences); } } diff --git a/tns-core-modules/ui/web-view/web-view.ios.ts b/tns-core-modules/ui/web-view/web-view.ios.ts index ebe6c640a..8a124ff07 100644 --- a/tns-core-modules/ui/web-view/web-view.ios.ts +++ b/tns-core-modules/ui/web-view/web-view.ios.ts @@ -145,7 +145,7 @@ export class WebView extends WebViewBase { public _loadUrl(src: string) { if (src.startsWith("file:///")) { - var cachePath = src.substring(0, src.lastIndexOf("/")); + const cachePath = src.substring(0, src.lastIndexOf("/")); this.ios.loadFileURLAllowingReadAccessToURL(NSURL.URLWithString(src), NSURL.URLWithString(cachePath)); } else { this.ios.loadRequest(NSURLRequest.requestWithURL(NSURL.URLWithString(src))); diff --git a/tns-core-modules/utils/debug.d.ts b/tns-core-modules/utils/debug.d.ts index dfcf448a1..93dd43f9c 100644 --- a/tns-core-modules/utils/debug.d.ts +++ b/tns-core-modules/utils/debug.d.ts @@ -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. diff --git a/tns-core-modules/utils/debug.ts b/tns-core-modules/utils/debug.ts index 189941756..83684d0a3 100644 --- a/tns-core-modules/utils/debug.ts +++ b/tns-core-modules/utils/debug.ts @@ -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; diff --git a/tns-core-modules/utils/module-merge.ts b/tns-core-modules/utils/module-merge.ts index a88a565e3..7fe2ba210 100644 --- a/tns-core-modules/utils/module-merge.ts +++ b/tns-core-modules/utils/module-merge.ts @@ -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]; } } \ No newline at end of file diff --git a/tns-core-modules/utils/types.ts b/tns-core-modules/utils/types.ts index 53ccc87d8..02327e96a 100644 --- a/tns-core-modules/utils/types.ts +++ b/tns-core-modules/utils/types.ts @@ -42,16 +42,16 @@ export function verifyCallback(value: any) { } } -var classInfosMap = new Map(); -var funcNameRegex = /function ([_a-zA-Z0-9]{1,})\(/; +const classInfosMap = new Map(); +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 { - 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__); } diff --git a/tns-core-modules/utils/utils-common.ts b/tns-core-modules/utils/utils-common.ts index 76bb98bbd..ae8c03cd6 100644 --- a/tns-core-modules/utils/utils-common.ts +++ b/tns-core-modules/utils/utils-common.ts @@ -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")) { diff --git a/tns-core-modules/utils/utils.android.ts b/tns-core-modules/utils/utils.android.ts index 2b3845652..b050042f9 100644 --- a/tns-core-modules/utils/utils.android.ts +++ b/tns-core-modules/utils/utils.android.ts @@ -131,9 +131,9 @@ export module ad { export module collections { export function stringArrayToStringSet(str: string[]): java.util.HashSet { - var hashSet = new java.util.HashSet(); + const hashSet = new java.util.HashSet(); 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(); + let attr; + const attrCache = new Map(); 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); diff --git a/tns-core-modules/utils/utils.d.ts b/tns-core-modules/utils/utils.d.ts index 1b8fe4959..3cab654c1 100644 --- a/tns-core-modules/utils/utils.d.ts +++ b/tns-core-modules/utils/utils.d.ts @@ -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. diff --git a/tns-core-modules/utils/utils.ios.ts b/tns-core-modules/utils/utils.ios.ts index 976a43880..941782f16 100644 --- a/tns-core-modules/utils/utils.ios.ts +++ b/tns-core-modules/utils/utils.ios.ts @@ -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): Array { - 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); } diff --git a/tns-core-modules/xhr/xhr.ts b/tns-core-modules/xhr/xhr.ts index a8df0c2cf..4ade3a2c3 100644 --- a/tns-core-modules/xhr/xhr.ts +++ b/tns-core-modules/xhr/xhr.ts @@ -2,9 +2,9 @@ import * as http from "../http"; import * as types from "../utils/types"; module XMLHttpRequestResponseType { - export var empty = ""; - export var text = "text"; - export var json = "json"; + export const empty = ""; + export const text = "text"; + export const json = "json"; } export class XMLHttpRequest { diff --git a/tns-core-modules/xml/xml.ts b/tns-core-modules/xml/xml.ts index f9ab1a73f..993a0f405 100644 --- a/tns-core-modules/xml/xml.ts +++ b/tns-core-modules/xml/xml.ts @@ -69,13 +69,13 @@ export class ParserEvent implements definition.ParserEvent { } } -var _ampCodes; -var _entitySearchRegEx = /&#(\d+);|&#x([0123456789abcdef]+);|&(\w+);/ig; +let _ampCodes; +const _entitySearchRegEx = /&#(\d+);|&#x([0123456789abcdef]+);|&(\w+);/ig; function _generateAmpMap(): any { - var objCodes = { Tab: 9, NewLine: 10, excl: 33, quot: 34, QUOT: 34, num: 35, dollar: 36, percent: 37, amp: 38, AMP: 38, apos: 39, lpar: 40, rpar: 41, ast: 42, midast: 42, plus: 43, comma: 44, period: 46, sol: 47, colon: 58, semi: 59, lt: 60, LT: 60, equals: 61, gt: 62, GT: 62, quest: 63, commat: 64, lsqb: 91, lbrack: 91, bsol: 92, rsqb: 92, rbrack: 92, Hat: 94, lowbar: 95, grave: 96, DiacriticalGrave: 96, lcub: 123, lbrace: 123, verbar: 124, vert: 124, VerticalLine: 124, rcub: 125, rbrace: 125, nbsp: 160, iexcl: 161, cent: 162, pound: 163, curren: 164, yen: 165, brvbar: 166, brkbar: 166, sect: 167, uml: 168, copy: 169, ordf: 170, laquo: 171, not: 172, shy: 173, reg: 174, macr: 175, hibar: 175, deg: 176, plusmn: 177, sup2: 178, sup3: 179, acute: 180, micro: 181, para: 182, middot: 183, cedil: 184, sup1: 185, ordm: 186, raquo: 187, frac14: 188, frac12: 189, frac34: 190, iquest: 191, Agrave: 192, Aacute: 193, Acirc: 194, Atilde: 195, Auml: 196, Aring: 197, AElig: 198, Ccedil: 199, Egrave: 200, Eacute: 201, Ecirc: 202, Euml: 203, Igrave: 204, Iacute: 205, Icirc: 206, Iuml: 207, ETH: 208, Dstrok: 208, Ntilde: 209, Ograve: 210, Oacute: 211, Ocirc: 212, Otilde: 213, Ouml: 214, times: 215, Oslash: 216, Ugrave: 217, Uacute: 218, Ucirc: 219, Uuml: 220, Yacute: 221, THORN: 222, szlig: 223, agrave: 224, aacute: 225, acirc: 226, atilde: 227, auml: 228, aring: 229, aelig: 230, ccedil: 231, egrave: 232, eacute: 233, ecirc: 234, euml: 235, igrave: 236, iacute: 237, icirc: 238, iuml: 239, eth: 240, ntilde: 241, ograve: 242, oacute: 243, ocirc: 244, otilde: 245, ouml: 246, divide: 247, oslash: 248, ugrave: 249, uacute: 250, ucirc: 251, uuml: 252, yacute: 253, thorn: 254, yuml: 255, fnof: 402, imped: 437, gacute: 501, jmath: 567, circ: 710, caron: 711, Hacek: 711, breve: 728, Breve: 728, dot: 729, DiacriticalDot: 729, ring: 730, ogon: 731, tilde: 732, DiacriticalTilde: 732, dblac: 733, DiacriticalDoubleAcute: 733, DownBreve: 785, UnderBar: 818, Alpha: 913, Beta: 914, Gamma: 915, Delta: 916, Epsilon: 917, Zeta: 918, Eta: 919, Theta: 920, Iota: 921, Kappa: 922, Lambda: 923, Mu: 924, Nu: 925, Xi: 926, Omicron: 927, Pi: 928, Rho: 929 /* 930 is not real */, Sigma: 931, Tau: 932, Upsilon: 933, Phi: 934, Chi: 935, Psi: 936, Omega: 937, alpha: 945, beta: 946, gamma: 947, delta: 948, epsilon: 949, epsiv: 949, varepsilon: 949, zeta: 950, eta: 951, theta: 952, iota: 953, kappa: 954, lambda: 955, mu: 956, nu: 957, xi: 958, omicron: 959, pi: 960, rho: 961, sigmaf: 962, sigmav: 962, varsigma: 962, sigma: 963, tau: 964, upsilon: 965, phi: 966, chi: 967, psi: 968, omega: 969, thetav: 977, vartheta: 977, thetasym: 977, Upsi: 978, upsih: 978, straightphi: 981, piv: 982, varpi: 982, Gammad: 988, gammad: 989, digamma: 989, kappav: 1008, varkappa: 1008, rhov: 1009, varrho: 1009, epsi: 1013, straightepsilon: 1013, bepsi: 1014, backepsilon: 1014, /* Skipped Codes 1015 - 1119 */ euro: 8364, trade: 8482, TRADE: 8482, forall: 8704, part: 8706, larr: 8592, rarr: 8593, hyphen: 8208, dash: 8208, ndash: 8211, mdash: 8212, horbar: 8213, Vert: 8214, Verbar: 8214, lsquo: 8216, OpenCurlyQuote: 8216, rsquo: 8217, rsquor: 8217, CloseCurlyQuote: 8217, lsquor: 8218, sbquo: 8218, ldquo: 8220, OpenCurlyDoubleQuote: 8220, rdquo: 8221, rdquor: 8221, CloseCurlyDoubleQuote: 8221, ldquor: 8222, bdquo: 8222, dagger: 8224, Dagger: 8225, ddagger: 8225, bull: 8226, bullet: 8226, nldr: 8229, hellip: 8230, mldr: 8230, hybull: 8259, tdot: 8411, TripleDot: 8411, DotDot: 8412, star: 9734, phone: 9742, spades: 9824, clubs: 9827, hearts: 9829, diams: 9830, female: 9792, male: 9794, check: 10003, checkmark: 10003, cross: 10007, VerticalSeparator: 10072, EmptySmallSquare: 9723, FilledSmallSquare: 9724, starf: 9733, bigstar: 9733, square: 9633, squ: 9633, Square: 9633 }; - var ampCodes = new Map(); - for (var key in objCodes) { + const objCodes = { Tab: 9, NewLine: 10, excl: 33, quot: 34, QUOT: 34, num: 35, dollar: 36, percent: 37, amp: 38, AMP: 38, apos: 39, lpar: 40, rpar: 41, ast: 42, midast: 42, plus: 43, comma: 44, period: 46, sol: 47, colon: 58, semi: 59, lt: 60, LT: 60, equals: 61, gt: 62, GT: 62, quest: 63, commat: 64, lsqb: 91, lbrack: 91, bsol: 92, rsqb: 92, rbrack: 92, Hat: 94, lowbar: 95, grave: 96, DiacriticalGrave: 96, lcub: 123, lbrace: 123, verbar: 124, vert: 124, VerticalLine: 124, rcub: 125, rbrace: 125, nbsp: 160, iexcl: 161, cent: 162, pound: 163, curren: 164, yen: 165, brvbar: 166, brkbar: 166, sect: 167, uml: 168, copy: 169, ordf: 170, laquo: 171, not: 172, shy: 173, reg: 174, macr: 175, hibar: 175, deg: 176, plusmn: 177, sup2: 178, sup3: 179, acute: 180, micro: 181, para: 182, middot: 183, cedil: 184, sup1: 185, ordm: 186, raquo: 187, frac14: 188, frac12: 189, frac34: 190, iquest: 191, Agrave: 192, Aacute: 193, Acirc: 194, Atilde: 195, Auml: 196, Aring: 197, AElig: 198, Ccedil: 199, Egrave: 200, Eacute: 201, Ecirc: 202, Euml: 203, Igrave: 204, Iacute: 205, Icirc: 206, Iuml: 207, ETH: 208, Dstrok: 208, Ntilde: 209, Ograve: 210, Oacute: 211, Ocirc: 212, Otilde: 213, Ouml: 214, times: 215, Oslash: 216, Ugrave: 217, Uacute: 218, Ucirc: 219, Uuml: 220, Yacute: 221, THORN: 222, szlig: 223, agrave: 224, aacute: 225, acirc: 226, atilde: 227, auml: 228, aring: 229, aelig: 230, ccedil: 231, egrave: 232, eacute: 233, ecirc: 234, euml: 235, igrave: 236, iacute: 237, icirc: 238, iuml: 239, eth: 240, ntilde: 241, ograve: 242, oacute: 243, ocirc: 244, otilde: 245, ouml: 246, divide: 247, oslash: 248, ugrave: 249, uacute: 250, ucirc: 251, uuml: 252, yacute: 253, thorn: 254, yuml: 255, fnof: 402, imped: 437, gacute: 501, jmath: 567, circ: 710, caron: 711, Hacek: 711, breve: 728, Breve: 728, dot: 729, DiacriticalDot: 729, ring: 730, ogon: 731, tilde: 732, DiacriticalTilde: 732, dblac: 733, DiacriticalDoubleAcute: 733, DownBreve: 785, UnderBar: 818, Alpha: 913, Beta: 914, Gamma: 915, Delta: 916, Epsilon: 917, Zeta: 918, Eta: 919, Theta: 920, Iota: 921, Kappa: 922, Lambda: 923, Mu: 924, Nu: 925, Xi: 926, Omicron: 927, Pi: 928, Rho: 929 /* 930 is not real */, Sigma: 931, Tau: 932, Upsilon: 933, Phi: 934, Chi: 935, Psi: 936, Omega: 937, alpha: 945, beta: 946, gamma: 947, delta: 948, epsilon: 949, epsiv: 949, varepsilon: 949, zeta: 950, eta: 951, theta: 952, iota: 953, kappa: 954, lambda: 955, mu: 956, nu: 957, xi: 958, omicron: 959, pi: 960, rho: 961, sigmaf: 962, sigmav: 962, varsigma: 962, sigma: 963, tau: 964, upsilon: 965, phi: 966, chi: 967, psi: 968, omega: 969, thetav: 977, vartheta: 977, thetasym: 977, Upsi: 978, upsih: 978, straightphi: 981, piv: 982, varpi: 982, Gammad: 988, gammad: 989, digamma: 989, kappav: 1008, varkappa: 1008, rhov: 1009, varrho: 1009, epsi: 1013, straightepsilon: 1013, bepsi: 1014, backepsilon: 1014, /* Skipped Codes 1015 - 1119 */ euro: 8364, trade: 8482, TRADE: 8482, forall: 8704, part: 8706, larr: 8592, rarr: 8593, hyphen: 8208, dash: 8208, ndash: 8211, mdash: 8212, horbar: 8213, Vert: 8214, Verbar: 8214, lsquo: 8216, OpenCurlyQuote: 8216, rsquo: 8217, rsquor: 8217, CloseCurlyQuote: 8217, lsquor: 8218, sbquo: 8218, ldquo: 8220, OpenCurlyDoubleQuote: 8220, rdquo: 8221, rdquor: 8221, CloseCurlyDoubleQuote: 8221, ldquor: 8222, bdquo: 8222, dagger: 8224, Dagger: 8225, ddagger: 8225, bull: 8226, bullet: 8226, nldr: 8229, hellip: 8230, mldr: 8230, hybull: 8259, tdot: 8411, TripleDot: 8411, DotDot: 8412, star: 9734, phone: 9742, spades: 9824, clubs: 9827, hearts: 9829, diams: 9830, female: 9792, male: 9794, check: 10003, checkmark: 10003, cross: 10007, VerticalSeparator: 10072, EmptySmallSquare: 9723, FilledSmallSquare: 9724, starf: 9733, bigstar: 9733, square: 9633, squ: 9633, Square: 9633 }; + const ampCodes = new Map(); + for (let key in objCodes) { if (objCodes.hasOwnProperty(key)) { ampCodes.set(key, objCodes[key]); } @@ -94,7 +94,7 @@ function _HandleAmpEntities(found: string, decimalValue: string, hexValue: strin if (!_ampCodes) { _ampCodes = _generateAmpMap(); } - var res = _ampCodes.get(wordValue); + const res = _ampCodes.get(wordValue); if (res) { return String.fromCharCode(res); } @@ -119,17 +119,16 @@ export class XmlParser implements definition.XmlParser { this._processNamespaces = processNamespaces; this._parser = new easysax.EasySAXParser(); - var that = this; + const that = this; this._parser.on("startNode", function (elem, attr, uq, tagend, str, pos) { - var attributes = attr(); + let attributes = attr(); if (attributes === true) {//HACK: For some reason easysax returns the true literal when an element has no attributes. attributes = undefined; } if (attributes) { - var key; - for (key in attributes) { + for (let key in attributes) { if (attributes.hasOwnProperty(key)) { // Convert entities such as > to > attributes[key] = XmlParser._dereferenceEntities(attributes[key]); @@ -137,15 +136,15 @@ export class XmlParser implements definition.XmlParser { } } - var prefix = undefined; - var namespace = undefined; - var name = elem; + let prefix = undefined; + let namespace = undefined; + let name = elem; if (that._processNamespaces) { - var stackEntry = XmlParser._getNamespacesStackEntry(attributes); + const stackEntry = XmlParser._getNamespacesStackEntry(attributes); that._namespaceStack.push(stackEntry); - var resolved = that._resolveNamespace(name); + const resolved = that._resolveNamespace(name); prefix = resolved.prefix; namespace = resolved.namespace; name = resolved.name; @@ -155,18 +154,18 @@ export class XmlParser implements definition.XmlParser { }); this._parser.on("textNode", function (text, uq, pos) { - var data = uq(XmlParser._dereferenceEntities(text)); // Decode entity references such as < and > + const data = uq(XmlParser._dereferenceEntities(text)); // Decode entity references such as < and > onEvent(new ParserEvent(ParserEventType.Text, pos(), undefined, undefined, undefined, undefined, data)); }); this._parser.on("endNode", function (elem, uq, tagstart, str, pos) { - var prefix = undefined; - var namespace = undefined; - var name = elem; + let prefix = undefined; + let namespace = undefined; + let name = elem; if (that._processNamespaces) { - var resolved = that._resolveNamespace(name); + const resolved = that._resolveNamespace(name); prefix = resolved.prefix; namespace = resolved.namespace; name = resolved.name; @@ -211,23 +210,26 @@ export class XmlParser implements definition.XmlParser { } private static _getNamespacesStackEntry(attributes: any): any { - var stackEntry = {}; + const stackEntry = {}; if (!attributes) { return stackEntry; } - for (var key in attributes) { + let attributeName; + let namespacePrefix; + for (let key in attributes) { if (!attributes.hasOwnProperty(key)) { continue; } - var attributeName = key; + + attributeName = key; if (attributeName.indexOf("xmlns") !== 0) { // This is a normal attribute, so go on. continue; } - var namespacePrefix = ""; + namespacePrefix = ""; if (attributeName.indexOf(":") !== -1) { namespacePrefix = attributeName.split(":")[1]; } @@ -239,10 +241,10 @@ export class XmlParser implements definition.XmlParser { } private _resolveNamespace(fullName: string): { prefix: string; namespace: string; name: string; } { - var result: { prefix: string; namespace: string; name: string; } = { prefix: undefined, namespace: undefined, name: undefined } + const result: { prefix: string; namespace: string; name: string; } = { prefix: undefined, namespace: undefined, name: undefined } result.prefix = ""; if (fullName.indexOf(":") !== -1) { - var split = fullName.split(":"); + const split = fullName.split(":"); result.prefix = split[0]; result.name = split[1]; } @@ -250,12 +252,11 @@ export class XmlParser implements definition.XmlParser { result.name = fullName; } - var i; - var stackEntry; - for (i = this._namespaceStack.length - 1; i >= 0; i--) { + let stackEntry; + for (let i = this._namespaceStack.length - 1; i >= 0; i--) { stackEntry = this._namespaceStack[i]; - for (var key in stackEntry) { + for (let key in stackEntry) { if (!stackEntry.hasOwnProperty(key)) { continue; }