-
Notifications
You must be signed in to change notification settings - Fork 22
TS + ES #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
TS + ES #112
Changes from all commits
cc9b258
28a1a49
a422675
2b3ac42
c0b6a93
f395830
31ba435
040dc02
86eb64b
e3a8bf6
3e24a50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"esmodules": false | ||
} | ||
} | ||
], | ||
[ | ||
"@babel/preset-typescript", | ||
{ | ||
"allowDeclareFields": true, | ||
"allowNamespaces": true | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties", | ||
"@babel/plugin-proposal-object-rest-spread", | ||
"@babel/plugin-proposal-optional-chaining", | ||
"@babel/plugin-proposal-nullish-coalescing-operator", | ||
[ | ||
"@babel/plugin-transform-runtime", | ||
{ | ||
"corejs": false, | ||
"helpers": true, | ||
"regenerator": true, | ||
"useESModules": false | ||
} | ||
] | ||
], | ||
"env": { | ||
"development": { | ||
"sourceMaps": "inline", | ||
"retainLines": true | ||
}, | ||
"production": { | ||
"plugins": [ | ||
"babel-plugin-minify-dead-code-elimination" | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,14 @@ | ||||||
mocha.setup({ ui: "bdd", reporter: "spec", retries: 5 }); | ||||||
import MochaDefault from "mocha"; | ||||||
const Mocha = MochaDefault as typeof import("mocha"); | ||||||
import { expect } from "chai"; | ||||||
|
||||||
Mocha.setup('bdd'); | ||||||
// @ts-ignore | ||||||
Mocha.reporter('spec'); | ||||||
|
||||||
declare const hostPlatform: string; | ||||||
declare const setExitCode: (code: number) => void; | ||||||
|
||||||
const expect = chai.expect; | ||||||
|
||||||
describe("AbortController", function () { | ||||||
it("should not throw while aborting with no callbacks", function () { | ||||||
|
@@ -60,7 +68,7 @@ describe("AbortController", function () { | |||||
}); | ||||||
|
||||||
describe("XMLHTTPRequest", function () { | ||||||
function createRequest(method, url, body, responseType) { | ||||||
function createRequest(method: string, url: string, body: any = undefined, responseType: any = undefined): Promise<XMLHttpRequest> { | ||||||
return new Promise((resolve) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use
Suggested change
|
||||||
const xhr = new XMLHttpRequest(); | ||||||
xhr.open(method, url); | ||||||
|
@@ -72,11 +80,11 @@ describe("XMLHTTPRequest", function () { | |||||
}); | ||||||
} | ||||||
|
||||||
function createRequestWithHeaders(method, url, headers, body) { | ||||||
function createRequestWithHeaders(method: string, url: string, headers: any, body?: string): Promise<XMLHttpRequest> { | ||||||
return new Promise((resolve) => { | ||||||
const xhr = new XMLHttpRequest(); | ||||||
xhr.open(method, url); | ||||||
headers.forEach((value, key) => xhr.setRequestHeader(key, value)); | ||||||
headers.forEach((value: string, key: string) => xhr.setRequestHeader(key, value)); | ||||||
xhr.addEventListener("loadend", () => resolve(xhr)); | ||||||
xhr.send(body); | ||||||
}); | ||||||
|
@@ -199,7 +207,7 @@ describe("setTimeout", function () { | |||||
}); | ||||||
|
||||||
it("should return an id greater than zero when given an undefined function", function () { | ||||||
const id = setTimeout(undefined, 0); | ||||||
const id = setTimeout(undefined as any, 0); | ||||||
expect(id).to.be.greaterThan(0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe pass in an empty lambda? |
||||||
}); | ||||||
|
||||||
|
@@ -241,13 +249,13 @@ describe("setTimeout", function () { | |||||
catch (e) { | ||||||
done(e); | ||||||
} | ||||||
}, "10"); | ||||||
}, "10" as any); | ||||||
}); | ||||||
|
||||||
it("should call the given function after zero milliseconds when the delay is a string representing an invalid number", function (done) { | ||||||
setTimeout(() => { | ||||||
done(); | ||||||
}, "a"); | ||||||
}, "a" as any); | ||||||
}); | ||||||
|
||||||
it("should call the given function after other tasks execute when the given delay is zero", function (done) { | ||||||
|
@@ -416,7 +424,7 @@ if (hostPlatform !== "Unix") { | |||||
}; | ||||||
|
||||||
ws.onerror = (ev) => { | ||||||
done(new Error(ev.message)); | ||||||
done(new Error(String(ev))); | ||||||
}; | ||||||
}); | ||||||
|
||||||
|
@@ -459,7 +467,7 @@ if (hostPlatform !== "Unix") { | |||||
}; | ||||||
|
||||||
ws2.onerror = (ev) => { | ||||||
done(new Error(ev.message)); | ||||||
done(new Error(String(ev))); | ||||||
}; | ||||||
} | ||||||
|
||||||
|
@@ -484,7 +492,7 @@ if (hostPlatform !== "Unix") { | |||||
} | ||||||
|
||||||
ws1.onerror = (ev) => { | ||||||
done(new Error(ev.message)); | ||||||
done(new Error(String(ev))); | ||||||
}; | ||||||
}); | ||||||
|
||||||
|
@@ -509,7 +517,15 @@ if (hostPlatform !== "Unix") { | |||||
describe("URL", function () { | ||||||
|
||||||
// Currently all of the properties that the polyfill has implemented | ||||||
function checkURL(url, { href, hostname, origin, pathname, search }) { | ||||||
interface URLCheckOptions { | ||||||
href: string; | ||||||
hostname: string; | ||||||
origin: string; | ||||||
pathname: string; | ||||||
search: string; | ||||||
} | ||||||
|
||||||
function checkURL(url: URL, { href, hostname, origin, pathname, search }: URLCheckOptions): void { | ||||||
expect(url).to.have.property("hostname", hostname); | ||||||
expect(url).to.have.property("href", href); | ||||||
expect(url).to.have.property("origin", origin); | ||||||
|
@@ -567,7 +583,7 @@ describe("URL", function () { | |||||
it("should update href after URLSearchParams are changed", function () { | ||||||
// Augment URL with pathname and search | ||||||
const url = new URL("https://httpbin.org/en-US/docs?foo=1&bar=2"); | ||||||
url.searchParams.set("foo", 999); | ||||||
url.searchParams.set("foo", 999 as any); | ||||||
// href should change to reflect searchParams change | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this cast? Should it just be
Suggested change
|
||||||
checkURL(url, { | ||||||
href: "https://httpbin.org/en-US/docs?foo=999&bar=2", | ||||||
|
@@ -581,7 +597,7 @@ describe("URL", function () { | |||||
it("should update href after URLSearchParams are changed (Starting with 0 params)", function () { | ||||||
// Augment URL with pathname and search | ||||||
const url = new URL("https://httpbin.org/en-US/docs"); | ||||||
url.searchParams.set("foo", 999); | ||||||
url.searchParams.set("foo", 999 as any); | ||||||
// href should change to reflect searchParams change | ||||||
checkURL(url, { | ||||||
href: "https://httpbin.org/en-US/docs?foo=999", | ||||||
|
@@ -617,12 +633,13 @@ describe("URLSearchParams", function () { | |||||
const paramsSet = new URLSearchParams(""); | ||||||
|
||||||
it("should throw exception when trying to set with less than 2 parameters", function () { | ||||||
// @ts-expect-error | ||||||
expect(() => paramsSet.set()).to.throw(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment on what the expected error is and why we need this? |
||||||
}); | ||||||
|
||||||
it("should add a number and retrieve it as a string from searchParams", function () { | ||||||
// Set Number | ||||||
paramsSet.set("foo", 400); | ||||||
paramsSet.set("foo", 400 as any); | ||||||
expect(paramsSet.get("foo")).to.equal("400"); | ||||||
}); | ||||||
|
||||||
|
@@ -634,13 +651,13 @@ describe("URLSearchParams", function () { | |||||
|
||||||
it("should add a boolean and retrieve it as a string from searchParams", function () { | ||||||
// Set Boolean | ||||||
paramsSet.set("baz", true); | ||||||
paramsSet.set("baz", true as any); | ||||||
expect(paramsSet.get("baz")).to.equal("true"); | ||||||
}); | ||||||
|
||||||
it("should set an existing number and retrieve it as a string from searchParams", function () { | ||||||
// Set Existing Value | ||||||
paramsSet.set("foo", 9999); | ||||||
paramsSet.set("foo", 9999 as any); | ||||||
expect(paramsSet.get("foo")).to.equal("9999"); | ||||||
}); | ||||||
|
||||||
|
@@ -728,10 +745,10 @@ describe("Console", function () { | |||||
}); | ||||||
|
||||||
describe("Blob", function () { | ||||||
let emptyBlobs, helloBlobs, stringBlob, typedArrayBlob, arrayBufferBlob, blobBlob; | ||||||
let emptyBlobs: Blob[], helloBlobs: Blob[], stringBlob: Blob, typedArrayBlob: Blob, arrayBufferBlob: Blob, blobBlob: Blob; | ||||||
|
||||||
before(function () { | ||||||
emptyBlobs = [new Blob(), new Blob([])]; | ||||||
emptyBlobs = [new Blob([]), new Blob([])]; | ||||||
stringBlob = new Blob(["Hello"]); | ||||||
typedArrayBlob = new Blob([new Uint8Array([72, 101, 108, 108, 111])]), | ||||||
arrayBufferBlob = new Blob([new Uint8Array([72, 101, 108, 108, 111]).buffer]), | ||||||
|
@@ -842,7 +859,7 @@ describe("Blob", function () { | |||||
}); | ||||||
|
||||||
function runTests() { | ||||||
mocha.run(failures => { | ||||||
mocha.run((failures: number) => { | ||||||
// Test program will wait for code to be set before exiting | ||||||
if (failures > 0) { | ||||||
// Failure | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe some comments about why this is needed. |
||
return { | ||
visitor: { | ||
BigIntLiteral(path) { | ||
const value = path.node.value; // Get the BigInt literal value | ||
path.replaceWith({ | ||
type: 'NumericLiteral', | ||
value: Number(value), // Convert BigInt to Number | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this file relate to the .babelrc at the root? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compact": false, | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"targets": { | ||
"ie": "11" | ||
} | ||
}] | ||
], | ||
"plugins": ["./babel-plugin-replace-bigint"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this equivalent to: