refactor(): use const and let instead of var

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

View File

@ -11,7 +11,7 @@ import {global} from '../facade/lang';
let _nextRequestId = 0;
export const JSONP_HOME = '__ng_jsonp__';
var _jsonpConnections: {[key: string]: any} = null;
let _jsonpConnections: {[key: string]: any} = null;
function _getJsonpConnections(): {[key: string]: any} {
if (_jsonpConnections === null) {
@ -25,7 +25,7 @@ function _getJsonpConnections(): {[key: string]: any} {
export class BrowserJsonp {
// Construct a <script> element with the specified URL
build(url: string): any {
let node = document.createElement('script');
const node = document.createElement('script');
node.src = url;
return node;
}
@ -35,12 +35,12 @@ export class BrowserJsonp {
requestCallback(id: string): string { return `${JSONP_HOME}.${id}.finished`; }
exposeConnection(id: string, connection: any) {
let connections = _getJsonpConnections();
const connections = _getJsonpConnections();
connections[id] = connection;
}
removeConnection(id: string) {
var connections = _getJsonpConnections();
const connections = _getJsonpConnections();
connections[id] = null;
}

View File

@ -66,13 +66,13 @@ export class JSONPConnection_ extends JSONPConnection {
this.response = new Observable<Response>((responseObserver: Observer<Response>) => {
this.readyState = ReadyState.Loading;
let id = this._id = _dom.nextRequestID();
const id = this._id = _dom.nextRequestID();
_dom.exposeConnection(id, this);
// Workaround Dart
// url = url.replace(/=JSONP_CALLBACK(&|$)/, `generated method`);
let callback = _dom.requestCallback(this._id);
const callback = _dom.requestCallback(this._id);
let url: string = req.url;
if (url.indexOf('=JSONP_CALLBACK&') > -1) {
url = url.replace('=JSONP_CALLBACK&', `=${callback}&`);
@ -80,9 +80,9 @@ export class JSONPConnection_ extends JSONPConnection {
url = url.substring(0, url.length - '=JSONP_CALLBACK'.length) + `=${callback}`;
}
let script = this._script = _dom.build(url);
const script = this._script = _dom.build(url);
let onLoad = (event: Event) => {
const onLoad = (event: Event) => {
if (this.readyState === ReadyState.Cancelled) return;
this.readyState = ReadyState.Done;
_dom.cleanup(script);
@ -105,7 +105,7 @@ export class JSONPConnection_ extends JSONPConnection {
responseObserver.complete();
};
let onError = (error: Error) => {
const onError = (error: Error) => {
if (this.readyState === ReadyState.Cancelled) return;
this.readyState = ReadyState.Done;
_dom.cleanup(script);

View File

@ -45,22 +45,22 @@ export class XHRConnection implements Connection {
constructor(req: Request, browserXHR: BrowserXhr, baseResponseOptions?: ResponseOptions) {
this.request = req;
this.response = new Observable<Response>((responseObserver: Observer<Response>) => {
let _xhr: XMLHttpRequest = browserXHR.build();
const _xhr: XMLHttpRequest = browserXHR.build();
_xhr.open(RequestMethod[req.method].toUpperCase(), req.url);
if (isPresent(req.withCredentials)) {
_xhr.withCredentials = req.withCredentials;
}
// load event handler
let onLoad = () => {
const onLoad = () => {
// responseText is the old-school way of retrieving response (supported by IE8 & 9)
// response/responseType properties were introduced in ResourceLoader Level2 spec (supported
// by IE10)
let body = _xhr.response === undefined ? _xhr.responseText : _xhr.response;
// Implicitly strip a potential XSSI prefix.
if (typeof body === 'string') body = body.replace(XSSI_PREFIX, '');
let headers = Headers.fromResponseHeaderString(_xhr.getAllResponseHeaders());
const headers = Headers.fromResponseHeaderString(_xhr.getAllResponseHeaders());
let url = getResponseURL(_xhr);
const url = getResponseURL(_xhr);
// normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
let status: number = _xhr.status === 1223 ? 204 : _xhr.status;
@ -72,13 +72,13 @@ export class XHRConnection implements Connection {
status = body ? 200 : 0;
}
let statusText = _xhr.statusText || 'OK';
const statusText = _xhr.statusText || 'OK';
var responseOptions = new ResponseOptions({body, status, headers, statusText, url});
let responseOptions = new ResponseOptions({body, status, headers, statusText, url});
if (isPresent(baseResponseOptions)) {
responseOptions = baseResponseOptions.merge(responseOptions);
}
let response = new Response(responseOptions);
const response = new Response(responseOptions);
response.ok = isSuccess(status);
if (response.ok) {
responseObserver.next(response);
@ -89,8 +89,8 @@ export class XHRConnection implements Connection {
responseObserver.error(response);
};
// error event handler
let onError = (err: any) => {
var responseOptions = new ResponseOptions({
const onError = (err: any) => {
let responseOptions = new ResponseOptions({
body: err,
type: ResponseType.Error,
status: _xhr.status,
@ -161,7 +161,7 @@ export class XHRConnection implements Connection {
_xhr.setRequestHeader('content-type', 'text/plain');
break;
case ContentType.BLOB:
var blob = req.blob();
let blob = req.blob();
if (blob.type) {
_xhr.setRequestHeader('content-type', blob.type);
}
@ -186,7 +186,7 @@ export class CookieXSRFStrategy implements XSRFStrategy {
private _cookieName: string = 'XSRF-TOKEN', private _headerName: string = 'X-XSRF-TOKEN') {}
configureRequest(req: Request) {
let xsrfToken = __platform_browser_private__.getDOM().getCookie(this._cookieName);
const xsrfToken = __platform_browser_private__.getDOM().getCookie(this._cookieName);
if (xsrfToken) {
req.headers.set(this._headerName, xsrfToken);
}

View File

@ -43,8 +43,8 @@ export function getResponseURL(xhr: any): string {
}
export function stringToArrayBuffer(input: String): ArrayBuffer {
let view = new Uint16Array(input.length);
for (var i = 0, strLen = input.length; i < strLen; i++) {
const view = new Uint16Array(input.length);
for (let i = 0, strLen = input.length; i < strLen; i++) {
view[i] = input.charCodeAt(i);
}
return view.buffer;

View File

@ -76,10 +76,10 @@ export class Request extends Body {
constructor(requestOptions: RequestArgs) {
super();
// TODO: assert that url is present
let url = requestOptions.url;
const url = requestOptions.url;
this.url = requestOptions.url;
if (isPresent(requestOptions.search)) {
let search = requestOptions.search.toString();
const search = requestOptions.search.toString();
if (search.length > 0) {
let prefix = '?';
if (this.url.indexOf('?') != -1) {

View File

@ -86,7 +86,7 @@ export class URLSearchParams {
}
clone(): URLSearchParams {
var clone = new URLSearchParams('', this.queryEncoder);
const clone = new URLSearchParams('', this.queryEncoder);
clone.appendAll(this);
return clone;
}
@ -163,7 +163,7 @@ export class URLSearchParams {
searchParams.paramsMap.forEach((value, param) => {
const list = this.paramsMap.get(param) || [];
list.length = 0;
for (var i = 0; i < value.length; ++i) {
for (let i = 0; i < value.length; ++i) {
list.push(value[i]);
}
this.paramsMap.set(param, list);