Skip to content

Commit 4fc4890

Browse files
committed
refactor: remove legacy code for IE in ajax
BREAKING CHANGE: `ajax` no longer supports IE
1 parent 7d3c4ec commit 4fc4890

File tree

5 files changed

+3
-106
lines changed

5 files changed

+3
-106
lines changed

spec/observables/dom/ajax-spec.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -330,37 +330,6 @@ describe('ajax', () => {
330330
expect(complete).to.be.true;
331331
});
332332

333-
it('should fail if fails to parse response in older IE', () => {
334-
let error: any;
335-
const obj: AjaxConfig = {
336-
url: '/flibbertyJibbet',
337-
method: '',
338-
};
339-
340-
// No `response` property on the object (for older IE).
341-
MockXMLHttpRequest.noResponseProp = true;
342-
343-
ajax(obj).subscribe({
344-
next: () => {
345-
throw new Error('should not next');
346-
},
347-
error: (err: any) => {
348-
error = err;
349-
},
350-
complete: () => {
351-
throw new Error('should not complete');
352-
},
353-
});
354-
355-
MockXMLHttpRequest.mostRecent.respondWith({
356-
status: 207,
357-
responseText: 'Wee! I am text, but should be valid JSON!',
358-
});
359-
360-
expect(error instanceof SyntaxError).to.be.true;
361-
expect(error.message).to.equal('Unexpected token W in JSON at position 0');
362-
});
363-
364333
it('should fail on 404', () => {
365334
let error: any;
366335
const obj: AjaxConfig = {
@@ -1583,11 +1552,6 @@ class MockXHREventTarget {
15831552
class MockXMLHttpRequest extends MockXHREventTarget {
15841553
static readonly DONE = 4;
15851554

1586-
/**
1587-
* Set to `true` to test IE code paths.
1588-
*/
1589-
static noResponseProp = false;
1590-
15911555
private static requests: Array<MockXMLHttpRequest> = [];
15921556
private static recentRequest: MockXMLHttpRequest;
15931557

@@ -1600,7 +1564,6 @@ class MockXMLHttpRequest extends MockXHREventTarget {
16001564
}
16011565

16021566
static clearRequest(): void {
1603-
MockXMLHttpRequest.noResponseProp = false;
16041567
MockXMLHttpRequest.requests.length = 0;
16051568
MockXMLHttpRequest.recentRequest = null!;
16061569
}
@@ -1639,9 +1602,6 @@ class MockXMLHttpRequest extends MockXHREventTarget {
16391602
super();
16401603
MockXMLHttpRequest.recentRequest = this;
16411604
MockXMLHttpRequest.requests.push(this);
1642-
if (MockXMLHttpRequest.noResponseProp) {
1643-
delete this['response'];
1644-
}
16451605
}
16461606

16471607
// @ts-ignore: Property has no initializer and is not definitely assigned
@@ -1755,11 +1715,6 @@ class MockXMLHttpRequest extends MockXHREventTarget {
17551715
break;
17561716
}
17571717

1758-
// We're testing old IE, forget all of that response property stuff.
1759-
if (MockXMLHttpRequest.noResponseProp) {
1760-
delete this['response'];
1761-
}
1762-
17631718
this.triggerEvent('load', { type: 'load', total: response.total ?? 0, loaded: response.loaded ?? 0 });
17641719
this.triggerEvent('readystatechange', { type: 'readystatechange' });
17651720
}

src/internal/ajax/AjaxResponse.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AjaxRequest, AjaxResponseType } from './types';
2-
import { getXHRResponse } from './getXHRResponse';
32

43
/**
54
* A normalized response from an AJAX request. To get the data from the response,
@@ -116,7 +115,7 @@ export class AjaxResponse<T> {
116115
}, {})
117116
: {};
118117

119-
this.response = getXHRResponse(xhr);
118+
this.response = xhr.response;
120119
const { loaded, total } = originalEvent;
121120
this.loaded = loaded;
122121
this.total = total;

src/internal/ajax/ajax.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -481,18 +481,7 @@ export function fromAjax<T>(init: AjaxConfig): Observable<AjaxResponse<T>> {
481481
if (status < 400) {
482482
progressSubscriber?.complete?.();
483483

484-
let response: AjaxResponse<T>;
485-
try {
486-
// This can throw in IE, because we end up needing to do a JSON.parse
487-
// of the response in some cases to produce object we'd expect from
488-
// modern browsers.
489-
response = createResponse(DOWNLOAD, event);
490-
} catch (err) {
491-
destination.error(err);
492-
return;
493-
}
494-
495-
destination.next(response);
484+
destination.next(createResponse(DOWNLOAD, event));
496485
destination.complete();
497486
} else {
498487
progressSubscriber?.error?.(event);

src/internal/ajax/errors.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AjaxRequest } from './types';
2-
import { getXHRResponse } from './getXHRResponse';
32
import { createErrorClass } from '../util/createErrorClass';
43

54
/**
@@ -63,15 +62,7 @@ export const AjaxError: AjaxErrorCtor = createErrorClass(
6362
this.request = request;
6463
this.status = xhr.status;
6564
this.responseType = xhr.responseType;
66-
let response: any;
67-
try {
68-
// This can throw in IE, because we have to do a JSON.parse of
69-
// the response in some cases to get the expected response property.
70-
response = getXHRResponse(xhr);
71-
} catch (err) {
72-
response = xhr.responseText;
73-
}
74-
this.response = response;
65+
this.response = xhr.response;
7566
}
7667
);
7768

src/internal/ajax/getXHRResponse.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)