Skip to content

Commit

Permalink
Fix remaining test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Sep 16, 2024
1 parent d7cebc7 commit 5450189
Show file tree
Hide file tree
Showing 144 changed files with 1,177 additions and 727 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
/.eslintcache
/npm-debug.log
/.tap
/.vscode
**/node_modules
Expand Down
23 changes: 5 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"husky": "^9.1.5",
"knip": "^5.30.1",
"normalize-package-data": "^6.0.2",
"npm-package-arg": "^11.0.3",
"npm-run-all2": "^6.2.2",
"oxlint": "^0.9.3",
"packageurl-js": "^2.0.1",
Expand All @@ -66,7 +67,7 @@
"tap": "^21.0.1",
"tape": "^5.8.1",
"tinyglobby": "^0.2.6",
"typescript": "5.6.2",
"typescript": "5.5.3",
"typescript-eslint": "^8.5.0",
"validate-npm-package-name": "^5.0.1",
"which": "^4.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/npm/abab/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="node" />
declare interface Base64 {
atob: typeof atob
btoa: typeof btoa
Expand Down
4 changes: 3 additions & 1 deletion packages/npm/array-includes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const desc = value => ({

module.exports = Object.defineProperties(
function includes(thisArg, searchElement, fromIndex = 0) {
return Reflect.apply(impl, thisArg, [searchElement, fromIndex])
return new.target
? new impl()
: Reflect.apply(impl, thisArg, [searchElement, fromIndex])
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
4 changes: 3 additions & 1 deletion packages/npm/array.from/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const desc = value => ({

module.exports = Object.defineProperties(
function from(arrayLike, ...args) {
return Reflect.apply(impl, this || Array, [arrayLike, ...args])
return new.target
? new impl()
: Reflect.apply(impl, this ?? Array, [arrayLike, ...args])
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.of/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function of(...args) {
return Reflect.apply(impl, this ?? Array, args)
return new.target ? new impl() : Reflect.apply(impl, this ?? Array, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.at/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function at(thisArg, index = 0) {
return Reflect.apply(impl, thisArg, [index])
return new.target ? new impl() : Reflect.apply(impl, thisArg, [index])
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.every/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function every(thisArg, ...args) {
return Reflect.apply(impl, thisArg, args)
return new.target ? new impl() : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function filter(thisArg, ...args) {
return Reflect.apply(impl, thisArg, args)
return new.target ? new impl() : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.find/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function find(thisArg, ...args) {
return Reflect.apply(impl, thisArg, args)
return new.target ? new impl() : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.findlast/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function findLast(thisArg, ...args) {
return Reflect.apply(impl, thisArg, args)
return new.target ? new impl() : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.findlastindex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function findLastIndex(thisArg, ...args) {
return Reflect.apply(impl, thisArg, args)
return new.target ? new impl() : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.flat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function flat(thisArg, ...args) {
return Reflect.apply(impl, thisArg, args)
return new.target ? new impl() : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.flatmap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function flatMap(thisArg, ...args) {
return Reflect.apply(impl, thisArg, args)
return new.target ? new impl() : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.foreach/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function forEach(thisArg, ...args) {
Reflect.apply(impl, thisArg, args)
new.target ? new impl(...args) : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function map(thisArg, ...args) {
return Reflect.apply(impl, thisArg, args)
return new.target ? new impl() : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.reduce/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function reduce(thisArg, ...args) {
return Reflect.apply(impl, thisArg, args)
return new.target ? new impl() : Reflect.apply(impl, thisArg, args)
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/array.prototype.toreversed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function toReversed(thisArg) {
return Reflect.apply(impl, thisArg, [])
return new.target ? new impl() : Reflect.apply(impl, thisArg, [])
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
4 changes: 3 additions & 1 deletion packages/npm/array.prototype.tosorted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const desc = value => ({

module.exports = Object.defineProperties(
function toSorted(thisArg, compareFn) {
return Reflect.apply(impl, thisArg, [compareFn])
return new.target
? impl(compareFn)
: Reflect.apply(impl, thisArg, [compareFn])
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/arraybuffer.prototype.slice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const desc = value => ({

module.exports = Object.defineProperties(
function slice(thisArg, start, end) {
return Reflect.apply(impl, thisArg, [start, end])
return new.target ? new impl() : Reflect.apply(impl, thisArg, [start, end])
},
{
getPolyfill: desc(require('./polyfill')),
Expand Down
19 changes: 17 additions & 2 deletions packages/npm/asynciterator.prototype/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
'use strict'

module.exports = Reflect.getPrototypeOf(
Reflect.getPrototypeOf(Reflect.getPrototypeOf((async function* () {})()))
const asyncGeneratorProtoObj = Reflect.getPrototypeOf((async function* () {})())
const AsyncGeneratorPrototype = Reflect.getPrototypeOf(asyncGeneratorProtoObj)
const AsyncIteratorPrototype = Reflect.getPrototypeOf(AsyncGeneratorPrototype)

// Add Symbol.iterator property because the shim incorrectly adds it too.
// We at least make it non-enumerable.
module.exports = Object.defineProperty(
AsyncIteratorPrototype,
Symbol.iterator,
{
__proto__: null,
configurable: true,
value: function () {
return this
},
writable: true
}
)
6 changes: 5 additions & 1 deletion packages/npm/available-typed-arrays/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

module.exports = [
const allPossibleTypedArrays = [
'Float32Array',
'Float64Array',
'Int8Array',
Expand All @@ -13,3 +13,7 @@ module.exports = [
'BigInt64Array',
'BigUint64Array'
]

module.exports = function availableTypedArrays() {
return allPossibleTypedArrays.slice()
}
4 changes: 3 additions & 1 deletion packages/npm/date/Date.parse/auto.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/* empty */
'use strict'

require('./shim')()
73 changes: 72 additions & 1 deletion packages/npm/date/Date.parse/implementation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,74 @@
'use strict'

module.exports = Date.parse
const { parse: builtinParse } = Date
const { floor } = Math

// 15.9.1.15 Date Time String Format.
// https://tc39.es/ecma262/#sec-date-time-string-format
const yyyMmDdRegExp =
/^(?<yyyy>\d{4}|[+-]\d{6})(?:-(?<mm>\d{2})(?:-(?<dd>\d{2}))?)?/
// const yyyMmDdRegExp = new RegExp('^'
// + '(\\d{4}|[+-]\\d{6})' // four-digit year capture or sign + 6-digit expanded year
// + '(?:-(\\d{2})' // optional month capture
// + '(?:-(\\d{2})' // optional day capture
// + ')?)?'
// )

// The cumulative day numbers for each month in a non-leap year.
// For example:
// months[0] = 0: January starts at day 0.
// months[1] = 31: February starts on day 31 (i.e., after January’s 31 days).
// months[2] = 59: March starts on day 59 (31 days for January + 28 days for February).
// These are the day offsets for each month, assuming a non-leap year.
const months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365]

// Calculates how many days have passed in a given year up to the specified month,
// taking leap years into account.
function dayFromMonth(year, month) {
// t is set to 1 if the month is greater than 1 (i.e., March or later) and 0
// if it’s January or February. This is done because leap years affect only
// months after February. If you are calculating for March or later, you need
// to check for leap years and adjust accordingly.
const t = month > 1 ? 1 : 0
// The formula accounting for leap years essentially sums up the number of
// days contributed by:
// 1. The days from previous months in the same year (months[month]).
// 2. The number of days contributed by leap years and the correction for
// century years.
// 3. The total number of days from all complete years between 1970 and the
// specified year (365 * (year - 1970)).
return (
// Get the cumulative number of days for the given month.
months[month] +
// Count the number of leap years since 1970 (up to the specified year),
// because every 4th year is a leap year. The value of t ensures the leap
// year count is accurate if the month is March or later.
floor((year - 1969 + t) / 4) -
// Subtract the leap years that fall on century years (e.g. 1900, 2100),
// which are not leap years unless divisible by 400.
floor((year - 1901 + t) / 100) +
// Add back the leap years for centuries that are divisible by 400 (e.g. 1600, 2000),
// which are leap years.
floor((year - 1601 + t) / 400) +
// Account for the total number of days in all the non-leap years from 1970
// up to the given year. Each year adds 365 days (ignoring leap years initially).
365 * (year - 1970)
)
}

module.exports = function parse(dateString) {
// V8 (Chrome) and SpiderMonkey (Firefox) will parse dates like "2024-11-31"
// even though the month of November only has 30 days.
const match = yyyMmDdRegExp.exec(dateString)
if (match) {
const year = +match[1]
const month = +(match[2] ?? 1) - 1
const day = +(match[3] ?? 1) - 1
const daysInTheMonth =
dayFromMonth(year, month + 1) - dayFromMonth(year, month)
if (day >= daysInTheMonth) {
return NaN
}
}
return builtinParse(dateString)
}
11 changes: 10 additions & 1 deletion packages/npm/date/Date.parse/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
const impl = require('./implementation')

module.exports = function getPolyfill() {
return impl
// V8 (Chrome) and SpiderMonkey (Firefox) will parse dates like "2024-11-31"
// even though the month of November only has 30 days. This is technically
// allowed by https://tc39.es/ecma262/#sec-date.parse:
// > If the String does not conform to that format the function may fall back
// > to any implementation-specific heuristics or implementation-specific date
// > formats. Strings that are unrecognizable or contain out-of-bounds format
// > element values shall cause this function to return NaN.
//
// However, we've opted to normalize it for cross-platform consistency.
return isNaN(Date.parse('2024-11-31')) ? Date.parse : impl
}
14 changes: 12 additions & 2 deletions packages/npm/date/Date.parse/shim.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
'use strict'

const impl = require('./implementation')
const getPolyfill = require('./polyfill')

module.exports = function shimDateParse() {
return impl
const polyfill = getPolyfill()
if (polyfill && Date.parse !== polyfill) {
Object.defineProperty(Date, 'parse', {
__proto__: null,
configurable: true,
enumerable: false,
value: polyfill,
writable: true
})
}
return polyfill
}
Loading

0 comments on commit 5450189

Please sign in to comment.